public class BasicDBObjectBuilder extends Object
Utility for building complex objects. For example:
BasicDBObjectBuilder.start().add( "name" , "eliot").add("number" , 17).get()
Constructor | Description |
---|---|
BasicDBObjectBuilder() |
Creates a builder intialized with an empty document.
|
Modifier and Type | Method | Description |
---|---|---|
BasicDBObjectBuilder |
add(String key,
Object val) |
Same as append
|
BasicDBObjectBuilder |
append(String key,
Object val) |
Appends the key/value to the active object
|
DBObject |
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 active
|
BasicDBObjectBuilder |
push(String 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 |
start(String key,
Object val) |
Creates a builder initialized with the given key/value.
|
static BasicDBObjectBuilder |
start(Map documentAsMap) |
Creates an object builder from an existing map of key value pairs.
|
public BasicDBObjectBuilder()
public static BasicDBObjectBuilder start()
public static BasicDBObjectBuilder start(String key, Object val)
key
- The field nameval
- The valuepublic static BasicDBObjectBuilder start(Map documentAsMap)
documentAsMap
- a document in Map form.public BasicDBObjectBuilder append(String key, Object val)
key
- the field nameval
- the value of the fieldthis
so calls can be chainedpublic BasicDBObjectBuilder add(String key, Object val)
key
- the field nameval
- the value of the fieldthis
so calls can be chainedappend(String, Object)
public BasicDBObjectBuilder push(String key)
key
- the field namethis
so calls can be chainedpublic BasicDBObjectBuilder pop()
this
so calls can be chainedpublic DBObject get()
public boolean isEmpty()