Package org.bson
Class BasicBSONObject
- java.lang.Object
 - 
- java.util.AbstractMap<K,V>
 - 
- java.util.HashMap<K,V>
 - 
- java.util.LinkedHashMap<java.lang.String,java.lang.Object>
 - 
- org.bson.BasicBSONObject
 
 
 
 
 
- 
- All Implemented Interfaces:
 java.io.Serializable,java.lang.Cloneable,java.util.Map<java.lang.String,java.lang.Object>,BSONObject
- Direct Known Subclasses:
 BasicDBObject
public class BasicBSONObject extends java.util.LinkedHashMap<java.lang.String,java.lang.Object> implements BSONObject
A simple implementation ofDBObject. ADBObjectcan be created as follows, using this class:DBObject obj = new BasicBSONObject(); obj.put( "foo", "bar" );- See Also:
 - Serialized Form
 
 
- 
- 
Constructor Summary
Constructors Constructor Description BasicBSONObject()Creates an empty object.BasicBSONObject(int size)Creates an empty object.BasicBSONObject(java.lang.String key, java.lang.Object value)Creates a BSONObject initialised with a single key/value pair.BasicBSONObject(java.util.Map map)Creates a DBObject from a map. 
- 
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description BasicBSONObjectappend(java.lang.String key, java.lang.Object val)Add a key/value pair to this objectbooleancontainsField(java.lang.String field)Checks if this object contains a given fieldbooleancontainsKey(java.lang.String key)Deprecated.booleanequals(java.lang.Object o)Compares two documents according to their serialized form, ignoring the order of keys.java.lang.Objectget(java.lang.String key)Gets a value from this objectbooleangetBoolean(java.lang.String key)Returns the value of a field as a boolean.booleangetBoolean(java.lang.String key, boolean def)Returns the value of a field as a booleanjava.util.DategetDate(java.lang.String field)Returns the date or null if not set.java.util.DategetDate(java.lang.String field, java.util.Date def)Returns the date or def if not set.doublegetDouble(java.lang.String key)Returns the value of a field as adouble.doublegetDouble(java.lang.String key, double def)Returns the value of a field as andouble.intgetInt(java.lang.String key)Returns the value of a field as anint.intgetInt(java.lang.String key, int def)Returns the value of a field as anint.longgetLong(java.lang.String key)Returns the value of a field as along.longgetLong(java.lang.String key, long def)Returns the value of a field as anlong.ObjectIdgetObjectId(java.lang.String field)Returns the object id or null if not set.ObjectIdgetObjectId(java.lang.String field, ObjectId def)Returns the object id or def if not set.java.lang.StringgetString(java.lang.String key)Returns the value of a field as a stringjava.lang.StringgetString(java.lang.String key, java.lang.String def)Returns the value of a field as a stringinthashCode()voidputAll(java.util.Map m)Sets all key/value pairs from a map into this objectvoidputAll(BSONObject o)Sets all key/value pairs from an object into this objectjava.lang.ObjectremoveField(java.lang.String key)Deletes a field from this object.java.util.MaptoMap()Converts a DBObject to a map.- 
Methods inherited from class java.util.LinkedHashMap
clear, containsValue, entrySet, forEach, get, getOrDefault, keySet, replaceAll, values 
- 
Methods inherited from class java.util.HashMap
clone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, put, putIfAbsent, remove, remove, replace, replace, size 
- 
Methods inherited from interface org.bson.BSONObject
keySet, put 
 - 
 
 - 
 
- 
- 
Constructor Detail
- 
BasicBSONObject
public BasicBSONObject()
Creates an empty object. 
- 
BasicBSONObject
public BasicBSONObject(int size)
Creates an empty object.- Parameters:
 size- the initial capacity for the Map storing this document.
 
- 
BasicBSONObject
public BasicBSONObject(java.lang.String key, java.lang.Object value)Creates a BSONObject initialised with a single key/value pair.- Parameters:
 key- key under which to storevalue- value to store
 
- 
BasicBSONObject
public BasicBSONObject(java.util.Map map)
Creates a DBObject from a map.- Parameters:
 map- map to convert
 
 - 
 
- 
Method Detail
- 
toMap
public java.util.Map toMap()
Converts a DBObject to a map.- Specified by:
 toMapin interfaceBSONObject- Returns:
 - the DBObject
 
 
- 
removeField
public java.lang.Object removeField(java.lang.String key)
Deletes a field from this object.- Specified by:
 removeFieldin interfaceBSONObject- Parameters:
 key- the field name to remove- Returns:
 - the object removed
 
 
- 
containsField
public boolean containsField(java.lang.String field)
Checks if this object contains a given field- Specified by:
 containsFieldin interfaceBSONObject- Parameters:
 field- field name- Returns:
 - if the field exists
 
 
- 
containsKey
@Deprecated public boolean containsKey(java.lang.String key)
Deprecated.Description copied from interface:BSONObjectDeprecated- Specified by:
 containsKeyin interfaceBSONObject- Parameters:
 key- the key to check- Returns:
 - True if the key is present
 
 
- 
get
public java.lang.Object get(java.lang.String key)
Gets a value from this object- Specified by:
 getin interfaceBSONObject- Parameters:
 key- field name- Returns:
 - the value
 
 
- 
getInt
public int getInt(java.lang.String key)
Returns the value of a field as anint.- Parameters:
 key- the field to look for- Returns:
 - the field value (or default)
 
 
- 
getInt
public int getInt(java.lang.String key, int def)Returns the value of a field as anint.- Parameters:
 key- the field to look fordef- the default to return- Returns:
 - the field value (or default)
 
 
- 
getLong
public long getLong(java.lang.String key)
Returns the value of a field as along.- Parameters:
 key- the field to return- Returns:
 - the field value
 
 
- 
getLong
public long getLong(java.lang.String key, long def)Returns the value of a field as anlong.- Parameters:
 key- the field to look fordef- the default to return- Returns:
 - the field value (or default)
 
 
- 
getDouble
public double getDouble(java.lang.String key)
Returns the value of a field as adouble.- Parameters:
 key- the field to return- Returns:
 - the field value
 
 
- 
getDouble
public double getDouble(java.lang.String key, double def)Returns the value of a field as andouble.- Parameters:
 key- the field to look fordef- the default to return- Returns:
 - the field value (or default)
 
 
- 
getString
public java.lang.String getString(java.lang.String key)
Returns the value of a field as a string- Parameters:
 key- the field to look up- Returns:
 - the value of the field, converted to a string
 
 
- 
getString
public java.lang.String getString(java.lang.String key, java.lang.String def)Returns the value of a field as a string- Parameters:
 key- the field to look updef- the default to return- Returns:
 - the value of the field, converted to a string
 
 
- 
getBoolean
public boolean getBoolean(java.lang.String key)
Returns the value of a field as a boolean.- Parameters:
 key- the field to look up- Returns:
 - the value of the field, or false if field does not exist
 
 
- 
getBoolean
public boolean getBoolean(java.lang.String key, boolean def)Returns the value of a field as a boolean- Parameters:
 key- the field to look updef- the default value in case the field is not found- Returns:
 - the value of the field, converted to a string
 
 
- 
getObjectId
public ObjectId getObjectId(java.lang.String field)
Returns the object id or null if not set.- Parameters:
 field- The field to return- Returns:
 - The field object value or null if not found (or if null :-^).
 
 
- 
getObjectId
public ObjectId getObjectId(java.lang.String field, ObjectId def)
Returns the object id or def if not set.- Parameters:
 field- The field to returndef- the default value in case the field is not found- Returns:
 - The field object value or def if not set.
 
 
- 
getDate
public java.util.Date getDate(java.lang.String field)
Returns the date or null if not set.- Parameters:
 field- The field to return- Returns:
 - The field object value or null if not found.
 
 
- 
getDate
public java.util.Date getDate(java.lang.String field, java.util.Date def)Returns the date or def if not set.- Parameters:
 field- The field to returndef- the default value in case the field is not found- Returns:
 - The field object value or def if not set.
 
 
- 
putAll
public void putAll(java.util.Map m)
Description copied from interface:BSONObjectSets all key/value pairs from a map into this object- Specified by:
 putAllin interfaceBSONObject- Specified by:
 putAllin interfacejava.util.Map<java.lang.String,java.lang.Object>- Overrides:
 putAllin classjava.util.HashMap<java.lang.String,java.lang.Object>- Parameters:
 m- the map
 
- 
putAll
public void putAll(BSONObject o)
Description copied from interface:BSONObjectSets all key/value pairs from an object into this object- Specified by:
 putAllin interfaceBSONObject- Parameters:
 o- the object
 
- 
append
public BasicBSONObject append(java.lang.String key, java.lang.Object val)
Add a key/value pair to this object- Parameters:
 key- the field nameval- the field value- Returns:
 this
 
- 
equals
public boolean equals(java.lang.Object o)
Compares two documents according to their serialized form, ignoring the order of keys.- Specified by:
 equalsin interfacejava.util.Map<java.lang.String,java.lang.Object>- Overrides:
 equalsin classjava.util.AbstractMap<java.lang.String,java.lang.Object>- Parameters:
 o- the document to compare to, which must be an instance ofBSONObject.- Returns:
 - true if the documents have the same serialized form, ignoring key order.
 
 
- 
hashCode
public int hashCode()
- Specified by:
 hashCodein interfacejava.util.Map<java.lang.String,java.lang.Object>- Overrides:
 hashCodein classjava.util.AbstractMap<java.lang.String,java.lang.Object>
 
 - 
 
 -