public class Document extends Object implements Map<String,Object>, Serializable
Map
. All iterators will traverse the elements in insertion order, as with LinkedHashMap
.Constructor and Description |
---|
Document()
Creates an empty Document instance.
|
Document(Map<String,Object> map)
Creates a Document instance initialized with the given map.
|
Document(String key,
Object value)
Create a Document instance initialized with the given key/value pair.
|
Modifier and Type | Method and Description |
---|---|
Document |
append(String key,
Object value)
Put the given key/value pair into this Document and return this.
|
void |
clear() |
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
Set<Map.Entry<String,Object>> |
entrySet() |
boolean |
equals(Object o) |
Object |
get(Object key) |
<T> T |
get(Object key,
Class<T> clazz)
Gets the value of the given key, casting it to the given
Class<T> . |
Boolean |
getBoolean(Object key)
Gets the value of the given key as a Boolean.
|
boolean |
getBoolean(Object key,
boolean defaultValue)
Gets the value of the given key as a primitive boolean.
|
Date |
getDate(Object key)
Gets the value of the given key as a Date.
|
Double |
getDouble(Object key)
Gets the value of the given key as a Double.
|
Integer |
getInteger(Object key)
Gets the value of the given key as an Integer.
|
int |
getInteger(Object key,
int defaultValue)
Gets the value of the given key as a primitive int.
|
Long |
getLong(Object key)
Gets the value of the given key as a Long.
|
ObjectId |
getObjectId(Object key)
Gets the value of the given key as an ObjectId.
|
String |
getString(Object key)
Gets the value of the given key as a String.
|
int |
hashCode() |
boolean |
isEmpty() |
Set<String> |
keySet() |
Object |
put(String key,
Object value) |
void |
putAll(Map<? extends String,?> map) |
Object |
remove(Object key) |
int |
size() |
String |
toString() |
static Document |
valueOf(String s)
Converts a string in JSON format to a
Document |
Collection<Object> |
values() |
public Document()
public Document(String key, Object value)
key
- keyvalue
- valuepublic static Document valueOf(String s)
Document
s
- document representation in JSON format that conforms JSON RFC specifications.Document
objectpublic Document append(String key, Object value)
doc.append("a", 1).append("b", 2)}
key
- keyvalue
- valuepublic <T> T get(Object key, Class<T> clazz)
Class<T>
. This is useful to avoid having casts in client code,
though the effect is the same. So to get the value of a key that is of type String, you would write String name =
doc.get("name", String.class)
instead of String name = (String) doc.get("x")
.T
- the type of the classkey
- the keyclazz
- the class to cast the value toClassCastException
- if the value of the given key is not of type Tpublic Integer getInteger(Object key)
key
- the keyClassCastException
- if the value is not an integerpublic int getInteger(Object key, int defaultValue)
key
- the keydefaultValue
- what to return if the value is nullClassCastException
- if the value is not an integerpublic Long getLong(Object key)
key
- the keyClassCastException
- if the value is not an longpublic Double getDouble(Object key)
key
- the keyClassCastException
- if the value is not an doublepublic String getString(Object key)
key
- the keyClassCastException
- if the value is not a Stringpublic Boolean getBoolean(Object key)
key
- the keyClassCastException
- if the value is not an doublepublic boolean getBoolean(Object key, boolean defaultValue)
key
- the keydefaultValue
- what to return if the value is nullClassCastException
- if the value is not an doublepublic ObjectId getObjectId(Object key)
key
- the keyClassCastException
- if the value is not an ObjectIdpublic Date getDate(Object key)
key
- the keyClassCastException
- if the value is not a Datepublic boolean containsValue(Object value)
containsValue
in interface Map<String,Object>
public boolean containsKey(Object key)
containsKey
in interface Map<String,Object>
public boolean equals(Object o)
public int hashCode()