Skip to content

Commit c0e8cfe

Browse files
committed
splitting out BSONObject JAVA-113
1 parent d47631d commit c0e8cfe

7 files changed

Lines changed: 88 additions & 50 deletions

File tree

src/main/com/mongodb/BasicDBList.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
import com.mongodb.util.OrderedSet;
2222

23+
import org.bson.*;
24+
2325
import java.util.*;
2426

2527
/**
@@ -84,7 +86,7 @@ public void putAll( Map m ){
8486
}
8587
}
8688

87-
public void putAll( DBObject o ){
89+
public void putAll( BSONObject o ){
8890
for ( String k : o.keySet() ){
8991
put( k , o.get( k ) );
9092
}

src/main/com/mongodb/BasicDBObject.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
import com.mongodb.util.*;
2424

25+
import org.bson.*;
26+
2527
/**
2628
* A simple implementation of <code>DBObject</code>.
2729
* A <code>DBObject</code> can be created as follows, using this class:
@@ -159,7 +161,7 @@ public void putAll( Map m ){
159161
}
160162
}
161163

162-
public void putAll( DBObject o ){
164+
public void putAll( BSONObject o ){
163165
for ( String k : o.keySet() ){
164166
put( k , o.get( k ) );
165167
}

src/main/com/mongodb/DBObject.java

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -20,52 +20,10 @@
2020

2121
import java.util.*;
2222

23-
/** A key-value map that can be saved to the database. */
24-
public interface DBObject {
25-
26-
/** Sets a name/value pair in this object.
27-
* @param key Name to set
28-
* @param v Corresponding value
29-
* @return <tt>v</tt>
30-
*/
31-
public Object put( String key , Object v );
32-
33-
public void putAll( DBObject o );
34-
public void putAll( Map m );
35-
36-
/** Gets a field from this object by a given name.
37-
* @param key The name of the field fetch
38-
* @return The field, if found
39-
*/
40-
public Object get( String key );
41-
42-
/**
43-
* Returns a map representing this DBObject.
44-
* @return the map
45-
*/
46-
public Map toMap();
23+
import org.bson.*;
4724

48-
/** Remove a field with a given name from this object.
49-
* @param key The name of the field to remove
50-
* @return The value removed from this object
51-
*/
52-
public Object removeField( String key );
53-
54-
/**
55-
* @deprecated
56-
*/
57-
public boolean containsKey( String s );
58-
59-
/** Checks if this object contains a field with the given name.
60-
* @param s Field name for which to check
61-
* @return if this object contains a field with the given name
62-
*/
63-
public boolean containsField(String s);
64-
65-
/** Returns this object's fields' names
66-
* @return The names of the fields in this object
67-
*/
68-
public Set<String> keySet();
25+
/** A key-value map that can be saved to the database. */
26+
public interface DBObject extends BSONObject {
6927

7028
/**
7129
* if this object was loaded with only some fields (using a field filter)

src/main/com/mongodb/RawDBObject.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import java.nio.*;
2222
import java.util.*;
2323

24+
import org.bson.*;
25+
2426
import static com.mongodb.Bytes.*;
2527
import static com.mongodb.util.MyAsserts.*;
2628

@@ -66,7 +68,7 @@ public Object put( String key , Object v ){
6668
throw new RuntimeException( "read only" );
6769
}
6870

69-
public void putAll( DBObject o ){
71+
public void putAll( BSONObject o ){
7072
throw new RuntimeException( "read only" );
7173
}
7274

src/main/com/mongodb/ReflectionDBObject.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import java.util.*;
2222
import java.lang.reflect.*;
2323

24+
import org.bson.*;
25+
2426
import com.mongodb.util.*;
2527

2628
public abstract class ReflectionDBObject implements DBObject {
@@ -54,7 +56,7 @@ public void putAll( Map m ){
5456
}
5557
}
5658

57-
public void putAll( DBObject o ){
59+
public void putAll( BSONObject o ){
5860
for ( String k : o.keySet() ){
5961
put( k , o.get( k ) );
6062
}

src/main/com/mongodb/gridfs/GridFSFile.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import com.mongodb.*;
2222
import com.mongodb.util.*;
2323

24+
import org.bson.*;
25+
2426
import java.io.*;
2527
import java.util.*;
2628

@@ -156,7 +158,7 @@ else if ( key.equals( "md5" ) )
156158
}
157159

158160

159-
public void putAll( DBObject o ){
161+
public void putAll( BSONObject o ){
160162
throw new UnsupportedOperationException();
161163
}
162164
public void putAll( Map m ){

src/main/org/bson/BSONObject.java

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// BSONObject.java
2+
3+
/**
4+
* Copyright (C) 2008 10gen Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.bson;
20+
21+
import java.util.*;
22+
23+
/** A key-value map that can be saved to the database. */
24+
public interface BSONObject {
25+
26+
/** Sets a name/value pair in this object.
27+
* @param key Name to set
28+
* @param v Corresponding value
29+
* @return <tt>v</tt>
30+
*/
31+
public Object put( String key , Object v );
32+
33+
public void putAll( BSONObject o );
34+
public void putAll( Map m );
35+
36+
/** Gets a field from this object by a given name.
37+
* @param key The name of the field fetch
38+
* @return The field, if found
39+
*/
40+
public Object get( String key );
41+
42+
/**
43+
* Returns a map representing this BSONObject.
44+
* @return the map
45+
*/
46+
public Map toMap();
47+
48+
/** Remove a field with a given name from this object.
49+
* @param key The name of the field to remove
50+
* @return The value removed from this object
51+
*/
52+
public Object removeField( String key );
53+
54+
/**
55+
* @deprecated
56+
*/
57+
public boolean containsKey( String s );
58+
59+
/** Checks if this object contains a field with the given name.
60+
* @param s Field name for which to check
61+
* @return if this object contains a field with the given name
62+
*/
63+
public boolean containsField(String s);
64+
65+
/** Returns this object's fields' names
66+
* @return The names of the fields in this object
67+
*/
68+
public Set<String> keySet();
69+
70+
}

0 commit comments

Comments
 (0)