Package com.mongodb
Class BasicDBObjectBuilder
-
- com.mongodb.BasicDBObjectBuilder
-
public class BasicDBObjectBuilder extends
Utility for building complex objects. For example:
BasicDBObjectBuilder.start().add( "name" , "eliot").add("number" , 17).get()
-
-
Constructor Summary
Constructors Constructor Description BasicDBObjectBuilder()
Creates a builder intialized with an empty document.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description BasicDBObjectBuilder
key, val)
Same as appendBasicDBObjectBuilder
key, val)
Appends the key/value to the active objectDBObject
get()
Gets the top level document.boolean
isEmpty()
Returns true if no key/value was inserted into the top level document.BasicDBObjectBuilder
pop()
Pops the active object, which means that the parent object becomes activeBasicDBObjectBuilder
key)
Creates an new empty object and inserts it into the current object with the given key.static BasicDBObjectBuilder
start()
Creates a builder intialized with an empty document.static BasicDBObjectBuilder
key, val)
Creates a builder initialized with the given key/value.static BasicDBObjectBuilder
documentAsMap)
Creates an object builder from an existing map of key value pairs.
-
-
-
Method Detail
-
start
public static BasicDBObjectBuilder start()
Creates a builder intialized with an empty document.- Returns:
- The new empty builder
-
start
public static key, val)
Creates a builder initialized with the given key/value.- Parameters:
key
- The field nameval
- The value- Returns:
- the new builder
-
start
public static documentAsMap)
Creates an object builder from an existing map of key value pairs.- Parameters:
documentAsMap
- a document in Map form.- Returns:
- the new builder
-
append
public key, val)
Appends the key/value to the active object- Parameters:
key
- the field nameval
- the value of the field- Returns:
this
so calls can be chained
-
add
public key, val)
Same as append- Parameters:
key
- the field nameval
- the value of the field- Returns:
this
so calls can be chained- See Also:
append(String, Object)
-
push
public key)
Creates an new empty object and inserts it into the current object with the given key. The new child object becomes the active one.- Parameters:
key
- the field name- Returns:
this
so calls can be chained
-
pop
public BasicDBObjectBuilder pop()
Pops the active object, which means that the parent object becomes active- Returns:
this
so calls can be chained
-
get
public DBObject get()
Gets the top level document.- Returns:
- The base object
-
isEmpty
public boolean isEmpty()
Returns true if no key/value was inserted into the top level document.- Returns:
- true if empty
-
-