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