public class BasicBSONObject extends Object implements Map<String,Object>, BSONObject
BSONObject
. A BSONObject
can be created as follows, using this class: BSONObject obj = new BasicBSONObject(); obj.put("foo", "bar");
构造器和说明 |
---|
BasicBSONObject()
Creates an empty object. by default, key won't be sorted
|
BasicBSONObject(boolean sort)
Creates an empty object.
|
BasicBSONObject(int size)
Creates an empty object. by default, key won't be sorted
|
BasicBSONObject(Map m)
Creates a BSONObject from a map.
|
BasicBSONObject(String key,
Object value)
Convenience CTOR
|
限定符和类型 | 方法和说明 |
---|---|
BasicBSONObject |
append(String key,
Object val)
Add a key/value pair to this object
|
<T> T |
as(Class<T> cls)
Return an instance of the class "cls", only for BasicBSONObject
|
<T> T |
as(Class<T> cls,
Type eleType)
Return an instance of the class "cls", only for BasicBSONObject.
|
Object |
asMap() |
boolean |
BasicTypeWrite(Object object,
Object value,
Method method) |
void |
clear()
Removes all of the mappings from this map (optional operation).
|
boolean |
containsField(String field)
Checks if this object contains a given field
|
boolean |
containsKey(Object key)
Returns true if this map contains a mapping for the specified key.
|
boolean |
containsValue(Object value)
Returns true if this map maps one or more keys to the specified value.
|
Set<Map.Entry<String,Object>> |
entrySet()
Returns a Set view of the mappings contained in this map
|
boolean |
equals(Object o)
Current bson object is equal with the other or not
|
Object |
get(Object key)
Returns the value to which the specified key is mapped, or null if the
map contains no mapping for the key.
|
Object |
get(String key)
Gets a value from this object
|
BigDecimal |
getBigDecimal(String field)
Returns the BigDecimal object or null if not set.
|
BigDecimal |
getBigDecimal(String field,
BigDecimal def)
Returns the BigDecimal object or def if not set.
|
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() |
boolean |
isEmpty()
The current bson object keeps any elements or not
|
Set<String> |
keySet()
Returns this object's fields' names
|
Object |
put(String key,
Object val)
Add a key/value pair to this object
|
void |
putAll(BSONObject o)
Sets all key/value pairs from an object into this object
|
void |
putAll(Map m)
Sets all key/value pairs from a map into this object
|
Object |
remove(Object key)
Removes the mapping for a key from this map if it is present (optional
operation).
|
Object |
removeField(String key)
Deletes a field from this object.
|
int |
size()
Returns the number of key-value mappings in this map.
|
Map |
toMap()
Converts a BSONObject to a map.
|
String |
toString()
Returns a JSON serialization of this object
|
static BSONObject |
typeToBson(Object object) |
static BSONObject |
typeToBson(Object object,
Boolean ignoreNullValue) |
Collection<Object> |
values()
Returns a Collection view of the values contained in this map.
|
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
public BasicBSONObject()
public BasicBSONObject(boolean sort)
sort
- true: key will be sorted false: key won't be sorted.public BasicBSONObject(int size)
size
- this parament does not work.public BasicBSONObject(Map m)
m
- map to convertpublic BasicBSONObject append(String key, Object val)
key
- the field nameval
- the field valuethis
public <T> T as(Class<T> cls) throws Exception
as
在接口中 BSONObject
cls
- target class objectException
- If error happens.public <T> T as(Class<T> cls, Type eleType) throws Exception
BSONObject
as
在接口中 BSONObject
cls
- target class objectException
- If error happens.public Object asMap()
public boolean BasicTypeWrite(Object object, Object value, Method method) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
public void clear()
public boolean containsField(String field)
containsField
在接口中 BSONObject
field
- field namepublic boolean containsKey(Object key)
containsKey
在接口中 Map<String,Object>
key
- whose presence in this map is to be testedpublic boolean containsValue(Object value)
containsValue
在接口中 Map<String,Object>
value
- whose presence in this map is to be testedpublic Set<Map.Entry<String,Object>> entrySet()
public boolean equals(Object o)
public Object get(Object key)
public Object get(String key)
get
在接口中 BSONObject
key
- field namepublic BigDecimal getBigDecimal(String field)
field
- The field to returnpublic BigDecimal getBigDecimal(String field, BigDecimal def)
field
- The field to returndef
- the default value in case the field is not foundpublic 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 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 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 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 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 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 isEmpty()
public void putAll(BSONObject o)
putAll
在接口中 BSONObject
o
- the objectpublic void putAll(Map m)
public Object remove(Object key)
public Object removeField(String key)
removeField
在接口中 BSONObject
key
- the field name to removepublic int size()
public Map toMap()
toMap
在接口中 BSONObject
public String toString()
public static BSONObject typeToBson(Object object) throws IntrospectionException, IllegalArgumentException, IllegalAccessException, InvocationTargetException
public static BSONObject typeToBson(Object object, Boolean ignoreNullValue) throws IntrospectionException, IllegalArgumentException, IllegalAccessException, InvocationTargetException
public Collection<Object> values()
Copyright © 2018. All rights reserved.