Serializable
, Cloneable
, Map<String,Object>
, BSONObject
BasicDBObject
public class BasicBSONObject extends LinkedHashMap<String,Object> implements BSONObject
DBObject
. A DBObject
can be created as follows, using this class: DBObject obj = new
BasicBSONObject(); obj.put( "foo", "bar" );
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
Constructor | Description |
---|---|
BasicBSONObject() |
Creates an empty object.
|
BasicBSONObject(int size) |
Creates an empty object.
|
BasicBSONObject(String key,
Object value) |
Creates a BSONObject initialised with a single key/value pair.
|
BasicBSONObject(Map map) |
Creates a DBObject from a map.
|
Modifier and Type | Method | Description |
---|---|---|
BasicBSONObject |
append(String key,
Object val) |
Add a key/value pair to this object
|
boolean |
containsField(String field) |
Checks if this object contains a given field
|
boolean |
containsKey(String key) |
Deprecated.
|
boolean |
equals(Object o) |
Compares two documents according to their serialized form, ignoring the order of keys.
|
Object |
get(String key) |
Gets a value from this object
|
boolean |
getBoolean(String key) |
Returns the value of a field as a boolean.
|
boolean |
getBoolean(String key,
boolean def) |
Returns the value of a field as a boolean
|
Date |
getDate(String field) |
Returns the date or null if not set.
|
Date |
getDate(String field,
Date def) |
Returns the date or def if not set.
|
double |
getDouble(String key) |
Returns the value of a field as a
double . |
double |
getDouble(String key,
double def) |
Returns the value of a field as an
double . |
int |
getInt(String key) |
Returns the value of a field as an
int . |
int |
getInt(String key,
int def) |
Returns the value of a field as an
int . |
long |
getLong(String key) |
Returns the value of a field as a
long . |
long |
getLong(String key,
long def) |
Returns the value of a field as an
long . |
ObjectId |
getObjectId(String field) |
Returns the object id or null if not set.
|
ObjectId |
getObjectId(String field,
ObjectId def) |
Returns the object id or def if not set.
|
String |
getString(String key) |
Returns the value of a field as a string
|
String |
getString(String key,
String def) |
Returns the value of a field as a string
|
int |
hashCode() |
|
void |
putAll(Map m) |
Sets all key/value pairs from a map into this object
|
void |
putAll(BSONObject o) |
Sets all key/value pairs from an object into this object
|
Object |
removeField(String key) |
Deletes a field from this object.
|
Map |
toMap() |
Converts a DBObject to a map.
|
toString
keySet, put
clone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, put, putIfAbsent, remove, remove, replace, replace, size
clear, containsValue, entrySet, forEach, get, getOrDefault, keySet, removeEldestEntry, replaceAll, values
public BasicBSONObject()
public BasicBSONObject(int size)
size
- the initial capacity for the Map storing this document.public BasicBSONObject(String key, Object value)
key
- key under which to storevalue
- value to storepublic BasicBSONObject(Map map)
map
- map to convertpublic Map toMap()
toMap
in interface BSONObject
public Object removeField(String key)
removeField
in interface BSONObject
key
- the field name to removepublic boolean containsField(String field)
containsField
in interface BSONObject
field
- field name@Deprecated public boolean containsKey(String key)
BSONObject
containsKey
in interface BSONObject
key
- the key to checkpublic Object get(String key)
get
in interface BSONObject
key
- field namepublic int getInt(String key)
int
.key
- the field to look forpublic int getInt(String key, int def)
int
.key
- the field to look fordef
- the default to returnpublic long getLong(String key)
long
.key
- the field to returnpublic long getLong(String key, long def)
long
.key
- the field to look fordef
- the default to returnpublic double getDouble(String key)
double
.key
- the field to returnpublic double getDouble(String key, double def)
double
.key
- the field to look fordef
- the default to returnpublic String getString(String key)
key
- the field to look uppublic String getString(String key, String def)
key
- the field to look updef
- the default to returnpublic boolean getBoolean(String key)
key
- the field to look uppublic boolean getBoolean(String key, boolean def)
key
- the field to look updef
- the default value in case the field is not foundpublic ObjectId getObjectId(String field)
field
- The field to returnpublic ObjectId getObjectId(String field, ObjectId def)
field
- The field to returndef
- the default value in case the field is not foundpublic Date getDate(String field)
field
- The field to returnpublic Date getDate(String field, Date def)
field
- The field to returndef
- the default value in case the field is not foundpublic void putAll(Map m)
BSONObject
public void putAll(BSONObject o)
BSONObject
putAll
in interface BSONObject
o
- the objectpublic BasicBSONObject append(String key, Object val)
key
- the field nameval
- the field valuethis
public boolean equals(Object o)
equals
in interface Map<String,Object>
equals
in class AbstractMap<String,Object>
o
- the document to compare to, which must be an instance of BSONObject
.