public class BasicBSONList extends ArrayList<Object> implements BSONObject
Utility class to allow array DBObject
s to be created.
Note: MongoDB will also create arrays from java.util
.List
s.
BSONObject obj = new BasicBSONList(); obj.put( "0", value1 ); obj.put( "4", value2 ); obj.put( 2, value3 );
This simulates the array [ value1, null, value3, null, value2 ] by creating the DBObject
{ "0" : value1, "1" : null,
"2" : value3, "3" : null, "4" : value2 }
.
BasicBSONList only supports numeric keys. Passing strings that cannot be converted to ints will cause an IllegalArgumentException.
BasicBSONList list = new BasicBSONList(); list.put("1", "bar"); // ok list.put("1E1", "bar"); // throws exception
modCount
Constructor and Description |
---|
BasicBSONList() |
Modifier and Type | Method and Description |
---|---|
boolean |
containsField(String key)
Checks if this object contains a field with the given name.
|
boolean |
containsKey(String key)
Deprecated.
|
Object |
get(String key)
Gets a value at an index.
|
Set<String> |
keySet()
Returns this object's fields' names
|
Object |
put(int key,
Object value)
Puts a value at an index.
|
Object |
put(String key,
Object v)
Puts a value at an index.
|
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 |
removeField(String key)
Removes a field with a given name from this object.
|
Map |
toMap()
Returns a map representing this BSONObject.
|
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, forEach, get, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeIf, removeRange, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSize
equals, hashCode
containsAll, toString
finalize, getClass, notify, notifyAll, wait, wait, wait
containsAll, equals, hashCode
parallelStream, stream
public Object put(String key, Object v)
put
in interface BSONObject
key
- the index at which to insert the valuev
- the value to insertIllegalArgumentException
- if key
cannot be parsed into an int
public Object put(int key, Object value)
index
with null
.key
- the index at which to insert the valuevalue
- the value to insertpublic void putAll(Map m)
BSONObject
putAll
in interface BSONObject
m
- the mappublic void putAll(BSONObject o)
BSONObject
putAll
in interface BSONObject
o
- the objectpublic Object get(String key)
get
in interface BSONObject
key
- the indexIllegalArgumentException
- if key
cannot be parsed into an int
public Object removeField(String key)
BSONObject
removeField
in interface BSONObject
key
- The name of the field to remove@Deprecated public boolean containsKey(String key)
BSONObject
containsKey
in interface BSONObject
key
- the key to checkpublic boolean containsField(String key)
BSONObject
containsField
in interface BSONObject
key
- Field name for which to checkpublic Set<String> keySet()
BSONObject
keySet
in interface BSONObject
public Map toMap()
BSONObject
toMap
in interface BSONObject