Package org.bson.types
Class BasicBSONList
- All Implemented Interfaces:
Serializable,Cloneable,Iterable<Object>,Collection<Object>,List<Object>,RandomAccess,BSONObject
Utility class to allow array DBObjects to be created.
Note: MongoDB will also create arrays from java.util
.Lists.
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
- See Also:
-
Field Summary
Fields inherited from class java.util.AbstractList
modCount -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancontainsField(String key) Checks if this object contains a field with the given name.Gets a value at an index.keySet()Returns this object's fields' namesPuts a value at an index.Puts a value at an index.voidSets all key/value pairs from a map into this objectvoidputAll(BSONObject o) Sets all key/value pairs from an object into this objectremoveField(String key) Removes a field with a given name from this object.toMap()Returns a map representing this BSONObject.Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, equals, forEach, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeIf, removeRange, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSizeMethods inherited from class java.util.AbstractCollection
containsAll, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, stream, toArrayMethods inherited from interface java.util.List
containsAll
-
Constructor Details
-
BasicBSONList
public BasicBSONList()
-
-
Method Details
-
put
Puts a value at an index. For interface compatibility. Must be passed a String that is parsable to an int.- Specified by:
putin interfaceBSONObject- Parameters:
key- the index at which to insert the valuev- the value to insert- Returns:
- the value
- Throws:
IllegalArgumentException- ifkeycannot be parsed into anint
-
put
Puts a value at an index. This will fill any unset indexes less thanindexwithnull.- Parameters:
key- the index at which to insert the valuevalue- the value to insert- Returns:
- the value
-
putAll
Description copied from interface:BSONObjectSets all key/value pairs from a map into this object- Specified by:
putAllin interfaceBSONObject- Parameters:
m- the map
-
putAll
Description copied from interface:BSONObjectSets all key/value pairs from an object into this object- Specified by:
putAllin interfaceBSONObject- Parameters:
o- the object
-
get
Gets a value at an index. For interface compatibility. Must be passed a String that is parsable to an int.- Specified by:
getin interfaceBSONObject- Parameters:
key- the index- Returns:
- the value, if found, or null
- Throws:
IllegalArgumentException- ifkeycannot be parsed into anint
-
removeField
Description copied from interface:BSONObjectRemoves a field with a given name from this object.- Specified by:
removeFieldin interfaceBSONObject- Parameters:
key- The name of the field to remove- Returns:
- The value removed from this object
-
containsField
Description copied from interface:BSONObjectChecks if this object contains a field with the given name.- Specified by:
containsFieldin interfaceBSONObject- Parameters:
key- Field name for which to check- Returns:
- True if the field is present
-
keySet
Description copied from interface:BSONObjectReturns this object's fields' names- Specified by:
keySetin interfaceBSONObject- Returns:
- The names of the fields in this object
-
toMap
Description copied from interface:BSONObjectReturns a map representing this BSONObject.- Specified by:
toMapin interfaceBSONObject- Returns:
- the map
-