Package org.bson.types
Class BasicBSONList
-
- <E>
-
- <E>
-
- <>
-
- org.bson.types.BasicBSONList
-
- All Implemented Interfaces:
,
,
<>
,<>
,<>
,,
BSONObject
- Direct Known Subclasses:
BasicDBList
public class BasicBSONList extends <> 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
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description BasicBSONList()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
key)
Checks if this object contains a field with the given name.boolean
key)
Deprecated.key)
Gets a value at an index.<>
keySet()
Returns this object's fields' namesput(int key, value)
Puts a value at an index.key, v)
Puts a value at an index.void
m)
Sets all key/value pairs from a map into this objectvoid
putAll(BSONObject o)
Sets all key/value pairs from an object into this objectkey)
Removes a field with a given name from this object.toMap()
Returns a map representing this BSONObject.
-
-
-
Method Detail
-
put
public put( key, v)
Puts a value at an index. For interface compatibility. Must be passed a String that is parsable to an int.- Specified by:
put
in interfaceBSONObject
- Parameters:
key
- the index at which to insert the valuev
- the value to insert- Returns:
- the value
- Throws:
- if
key
cannot be parsed into anint
-
put
public put(int key, value)
Puts a value at an index. This will fill any unset indexes less thanindex
withnull
.- Parameters:
key
- the index at which to insert the valuevalue
- the value to insert- Returns:
- the value
-
putAll
public void putAll( m)
Description copied from interface:BSONObject
Sets all key/value pairs from a map into this object- Specified by:
putAll
in interfaceBSONObject
- Parameters:
m
- the map
-
putAll
public void putAll(BSONObject o)
Description copied from interface:BSONObject
Sets all key/value pairs from an object into this object- Specified by:
putAll
in interfaceBSONObject
- Parameters:
o
- the object
-
get
public get( key)
Gets a value at an index. For interface compatibility. Must be passed a String that is parsable to an int.- Specified by:
get
in interfaceBSONObject
- Parameters:
key
- the index- Returns:
- the value, if found, or null
- Throws:
- if
key
cannot be parsed into anint
-
removeField
public removeField( key)
Description copied from interface:BSONObject
Removes a field with a given name from this object.- Specified by:
removeField
in interfaceBSONObject
- Parameters:
key
- The name of the field to remove- Returns:
- The value removed from this object
-
containsKey
public boolean containsKey( key)
Deprecated.Description copied from interface:BSONObject
Deprecated- Specified by:
containsKey
in interfaceBSONObject
- Parameters:
key
- the key to check- Returns:
- True if the key is present
-
containsField
public boolean containsField( key)
Description copied from interface:BSONObject
Checks if this object contains a field with the given name.- Specified by:
containsField
in interfaceBSONObject
- Parameters:
key
- Field name for which to check- Returns:
- True if the field is present
-
keySet
public <> keySet()
Description copied from interface:BSONObject
Returns this object's fields' names- Specified by:
keySet
in interfaceBSONObject
- Returns:
- The names of the fields in this object
-
toMap
public toMap()
Description copied from interface:BSONObject
Returns a map representing this BSONObject.- Specified by:
toMap
in interfaceBSONObject
- Returns:
- the map
-
-