public interface DocumentBuilder extends Builder, DocumentAssignable
Modifier and Type | Method and Description |
---|---|
DocumentBuilder |
add(ElementAssignable element)
Adds a pre-built element to the document.
|
DocumentBuilder |
add(String name,
boolean value)
Adds a boolean element.
|
DocumentBuilder |
add(String name,
byte[] data)
Adds a binary element using sub-type zero (the default).
|
DocumentBuilder |
add(String name,
byte subType,
byte[] data)
Adds a binary element.
|
DocumentBuilder |
add(String name,
Date timestamp)
Adds a timestamp element.
|
DocumentBuilder |
add(String name,
DocumentAssignable document)
Adds a pre-constructed document to the array.
|
DocumentBuilder |
add(String name,
double value)
Adds a double element.
|
DocumentBuilder |
add(String name,
int value)
Adds a integer (32-bit signed) element.
|
DocumentBuilder |
add(String name,
long value)
Adds a long (64-bit signed) element.
|
DocumentBuilder |
add(String name,
Object value)
Adds the value to the document after trying to coerce the value into the
best possible element type.
|
DocumentBuilder |
add(String name,
ObjectId id)
Adds an ObjectId element.
|
DocumentBuilder |
add(String name,
Pattern pattern)
Adds an ObjectId element.
|
DocumentBuilder |
add(String name,
String value)
Adds a string element.
|
DocumentBuilder |
add(String name,
String databaseName,
String collectionName,
ObjectId id)
Deprecated.
See BSON specification.
|
DocumentBuilder |
add(String name,
UUID uuid)
Adds a (sub-type 4)
UUID binary element. |
DocumentBuilder |
addBinary(String name,
byte[] data)
Adds a binary element using sub-type zero (the default).
|
DocumentBuilder |
addBinary(String name,
byte subType,
byte[] data)
Adds a binary element using sub-type zero (the default).
|
DocumentBuilder |
addBoolean(String name,
boolean value)
Adds a boolean element.
|
DocumentBuilder |
addDBPointer(String name,
String databaseName,
String collectionName,
ObjectId id)
Deprecated.
See BSON specification.
|
DocumentBuilder |
addDocument(String name,
DocumentAssignable value)
Adds a pre-built document element.
|
DocumentBuilder |
addDouble(String name,
double value)
Adds a double element.
|
DocumentBuilder |
addInteger(String name,
int value)
Adds a integer (32-bit signed) element.
|
DocumentBuilder |
addJavaScript(String name,
String code)
Adds a JavaScript element.
|
DocumentBuilder |
addJavaScript(String name,
String code,
DocumentAssignable scope)
Adds a JavaScript with Scope element.
|
DocumentBuilder |
addLegacyUuid(String name,
UUID uuid)
Adds a legacy (sub-type 3)
UUID binary element. |
DocumentBuilder |
addLong(String name,
long value)
Adds a long (64-bit signed) element.
|
DocumentBuilder |
addMaxKey(String name)
Adds a minimum key value element.
|
DocumentBuilder |
addMinKey(String name)
Adds a minimum key value element.
|
DocumentBuilder |
addMongoTimestamp(String name,
long value)
Adds a MongoDB Timestamp element.
|
DocumentBuilder |
addNull(String name)
Adds a
null valued element. |
DocumentBuilder |
addObjectId(String name,
ObjectId id)
Adds an ObjectId element.
|
DocumentBuilder |
addRegularExpression(String name,
Pattern pattern)
Adds a regular expression element.
|
DocumentBuilder |
addRegularExpression(String name,
String pattern,
String options)
Adds a regular expression element.
|
DocumentBuilder |
addString(String name,
String value)
Adds a string element.
|
DocumentBuilder |
addSymbol(String name,
String symbol)
Adds a symbol element.
|
DocumentBuilder |
addTimestamp(String name,
long timestamp)
Adds a timestamp element.
|
DocumentBuilder |
addUuid(String name,
UUID uuid)
Adds a (sub-type 4)
UUID binary element. |
Document |
build()
Returns the
Document being constructed. |
DocumentBuilder |
push(String name)
Pushes a context for constructing a sub-document.
|
ArrayBuilder |
pushArray(String name)
Pushes a context for constructing a sub-array.
|
DocumentBuilder |
remove(String name)
Removes all
Element s that have the provided name from the
document being built. |
DocumentBuilder |
reset()
Resets the builder back to an empty state.
|
asDocument
DocumentBuilder add(ElementAssignable element) throws IllegalArgumentException
element
- The element to add.DocumentBuilder
for method chaining.IllegalArgumentException
- If the element
is null
.DocumentBuilder add(String name, boolean value) throws IllegalArgumentException
This is a equivalent to addBoolean(String,boolean)
but less
verbose.
name
- The name of the element.value
- The boolean value.DocumentBuilder
for method chaining.IllegalArgumentException
- If the name
is null
.DocumentBuilder add(String name, byte subType, byte[] data) throws IllegalArgumentException
This is a equivalent to addBinary(String,byte, byte[])
but less
verbose.
name
- The name of the element.subType
- The sub-type for the binary data.data
- The binary value.DocumentBuilder
for method chaining.IllegalArgumentException
- If the name
or data
is null
.DocumentBuilder add(String name, byte[] data) throws IllegalArgumentException
This is a equivalent to addBinary(String,byte[])
but will insert
a NullElement
if the data
is null
instead of
throwing an IllegalArgumentException
.
name
- The name of the element.data
- The binary value.DocumentBuilder
for method chaining.IllegalArgumentException
- If the name
is null
.DocumentBuilder add(String name, Date timestamp) throws IllegalArgumentException
This is a equivalent to addTimeStamp(timestamp.getTime())
but will insert a NullElement
if the timestamp
is null
instead of throwing an
IllegalArgumentException
.
name
- The name of the element.timestamp
- The number of milliseconds since the Unix epoch.DocumentBuilder
for method chaining.IllegalArgumentException
- If the name
is null
.DocumentBuilder add(String name, DocumentAssignable document) throws IllegalArgumentException
This is a equivalent to addDocument(String,DocumentAssignable)
but will insert a NullElement
if the document
is
null
instead of throwing an IllegalArgumentException
.
name
- The name of the element.document
- The document to add to the array.DocumentBuilder
for method chaining.IllegalArgumentException
- If the name
is null
.DocumentBuilder add(String name, double value) throws IllegalArgumentException
This is a equivalent to addDouble(String,double)
but less
verbose.
name
- The name of the element.value
- The double value.DocumentBuilder
for method chaining.IllegalArgumentException
- If the name
is null
.DocumentBuilder add(String name, int value) throws IllegalArgumentException
This is a equivalent to addInteger(String,int)
but less verbose.
name
- The name of the element.value
- The integer value.DocumentBuilder
for method chaining.IllegalArgumentException
- If the name
is null
.DocumentBuilder add(String name, long value) throws IllegalArgumentException
This is a equivalent to addLong(String,long)
but less verbose.
name
- The name of the element.value
- The long value.DocumentBuilder
for method chaining.IllegalArgumentException
- If the name
is null
.DocumentBuilder add(String name, Object value) throws IllegalArgumentException
IllegalArgumentException
is thrown.
This method does type inspection which can be slow. It is generally much faster to use the type specific methods of this interface.
name
- The name of the element.value
- The Object value to coerce into an element.DocumentBuilder
for method chaining.IllegalArgumentException
- If the name
is null
or the value
cannot be coerced into an element type.DocumentBuilder add(String name, ObjectId id) throws IllegalArgumentException
This is a equivalent to addObjectId(String,ObjectId)
but will
insert a NullElement
if the id
is null
instead of throwing an IllegalArgumentException
.
name
- The name of the element.id
- The ObjectId to add.DocumentBuilder
for method chaining.IllegalArgumentException
- If the name
or id
is null
.DocumentBuilder add(String name, Pattern pattern) throws IllegalArgumentException
This is a equivalent to addRegularExpression(String,Pattern)
but
will insert a NullElement
if the pattern
is
null
instead of throwing an IllegalArgumentException
.
name
- The name of the element.pattern
- The pattern for the regular expression.DocumentBuilder
for method chaining.IllegalArgumentException
- If the name
is null
.DocumentBuilder add(String name, String value) throws IllegalArgumentException
This is a equivalent to addString(String,String)
but will insert
a NullElement
if the value
is null
instead
of throwing an IllegalArgumentException
.
name
- The name of the element.value
- The string value.DocumentBuilder
for method chaining.IllegalArgumentException
- If the name
is null
.@Deprecated DocumentBuilder add(String name, String databaseName, String collectionName, ObjectId id) throws IllegalArgumentException
This is a equivalent to
addDBPointer(String,String, String, ObjectId)
but less verbose.
name
- The name of the element.databaseName
- The name of the database containing the document.collectionName
- The name of the collection containing the document.id
- The id for the document.DocumentBuilder
for method chaining.IllegalArgumentException
- If the name
, databaseName
,
collectionName
, or id
is null
.DocumentBuilder add(String name, UUID uuid) throws IllegalArgumentException
UUID
binary element.
This is a equivalent to addUuid(String,UUID)
but will insert a
NullElement
if the uuid
is null
instead of
throwing an IllegalArgumentException
.
name
- The name of the element.uuid
- The UUID
to add.DocumentBuilder
for method chaining.IllegalArgumentException
- If the name
is null
.DocumentBuilder addBinary(String name, byte subType, byte[] data) throws IllegalArgumentException
name
- The name of the element.subType
- The sub-type for the binary data.data
- The binary value.DocumentBuilder
for method chaining.IllegalArgumentException
- If the name
or data
is null
.DocumentBuilder addBinary(String name, byte[] data) throws IllegalArgumentException
This method throws an IllegalArgumentException
if the
data
is null
. If you would prefer a
NullElement
be inserted in the document use the
add(String, byte[])
method instead.
name
- The name of the element.data
- The binary value.DocumentBuilder
for method chaining.IllegalArgumentException
- If the name
or value
is null
.DocumentBuilder addBoolean(String name, boolean value) throws IllegalArgumentException
name
- The name of the element.value
- The boolean value.DocumentBuilder
for method chaining.IllegalArgumentException
- If the name
is null
.@Deprecated DocumentBuilder addDBPointer(String name, String databaseName, String collectionName, ObjectId id) throws IllegalArgumentException
name
- The name of the element.databaseName
- The name of the database containing the document.collectionName
- The name of the collection containing the document.id
- The id for the document.DocumentBuilder
for method chaining.IllegalArgumentException
- If the name
, databaseName
,
collectionName
, or id
is null
.DocumentBuilder addDocument(String name, DocumentAssignable value) throws IllegalArgumentException
push(String)
a sub
document.
This method throws an IllegalArgumentException
if the
value
is null
. If you would prefer a
NullElement
be inserted in the document use the
add(String, DocumentAssignable)
method instead.
name
- The name of the element.value
- The document value.DocumentBuilder
for method chaining.IllegalArgumentException
- If the name
or value
is null
.DocumentBuilder addDouble(String name, double value) throws IllegalArgumentException
name
- The name of the element.value
- The double value.DocumentBuilder
for method chaining.IllegalArgumentException
- If the name
is null
.DocumentBuilder addInteger(String name, int value) throws IllegalArgumentException
name
- The name of the element.value
- The integer value.DocumentBuilder
for method chaining.IllegalArgumentException
- If the name
is null
.DocumentBuilder addJavaScript(String name, String code) throws IllegalArgumentException
name
- The name of the element.code
- The java script code.DocumentBuilder
for method chaining.IllegalArgumentException
- If the name
or code
is null
.DocumentBuilder addJavaScript(String name, String code, DocumentAssignable scope) throws IllegalArgumentException
name
- The name of the element.code
- The java script code.scope
- The scope for the JacaScript code.DocumentBuilder
for method chaining.IllegalArgumentException
- If the name
, value
, or scope
is
null
.DocumentBuilder addLegacyUuid(String name, UUID uuid) throws IllegalArgumentException
UUID
binary element.
This method throws an IllegalArgumentException
if the
uuid
is null
.
name
- The name of the element.uuid
- The UUID
to add.DocumentBuilder
for method chaining.IllegalArgumentException
- If the name
or uuid
is null
.DocumentBuilder addLong(String name, long value) throws IllegalArgumentException
name
- The name of the element.value
- The long value.DocumentBuilder
for method chaining.IllegalArgumentException
- If the name
is null
.DocumentBuilder addMaxKey(String name) throws IllegalArgumentException
name
- The name of the element.DocumentBuilder
for method chaining.IllegalArgumentException
- If the name
is null
.DocumentBuilder addMinKey(String name) throws IllegalArgumentException
name
- The name of the element.DocumentBuilder
for method chaining.IllegalArgumentException
- If the name
is null
.DocumentBuilder addMongoTimestamp(String name, long value) throws IllegalArgumentException
name
- The name of the element.value
- The mongoDB timstamp value.DocumentBuilder
for method chaining.IllegalArgumentException
- If the name
is null
.DocumentBuilder addNull(String name) throws IllegalArgumentException
null
valued element.name
- The name of the element.DocumentBuilder
for method chaining.IllegalArgumentException
- If the name
is null
.DocumentBuilder addObjectId(String name, ObjectId id) throws IllegalArgumentException
This method throws an IllegalArgumentException
if the id
is null
. If you would prefer a NullElement
be
inserted in the document use the add(String, ObjectId)
method
instead.
name
- The name of the element.id
- The ObjectId to add.DocumentBuilder
for method chaining.IllegalArgumentException
- If the name
or id
is null
.DocumentBuilder addRegularExpression(String name, Pattern pattern) throws IllegalArgumentException
This method throws an IllegalArgumentException
if the
pattern
is null
. If you would prefer a
NullElement
be inserted in the document use the
add(String, Pattern)
method instead.
name
- The name of the element.pattern
- The pattern for the regular expression.DocumentBuilder
for method chaining.IllegalArgumentException
- If the name
or pattern
is null
.DocumentBuilder addRegularExpression(String name, String pattern, String options) throws IllegalArgumentException
name
- The name of the element.pattern
- The pattern for the regular expression.options
- The regular expression options. See the BSON specification for
details. The options may be null
.DocumentBuilder
for method chaining.IllegalArgumentException
- If the name
or pattern
is null
.
Note the options
may be null
.DocumentBuilder addString(String name, String value) throws IllegalArgumentException
This method throws an IllegalArgumentException
if the
value
is null
. If you would prefer a
NullElement
be inserted in the document use the
add(String, String)
method instead.
name
- The name of the element.value
- The string value.DocumentBuilder
for method chaining.IllegalArgumentException
- If the name
or value
is null
.DocumentBuilder addSymbol(String name, String symbol) throws IllegalArgumentException
name
- The name of the element.symbol
- The symbol value.DocumentBuilder
for method chaining.IllegalArgumentException
- If the name
or symbol
is null
.DocumentBuilder addTimestamp(String name, long timestamp) throws IllegalArgumentException
name
- The name of the element.timestamp
- The number of milliseconds since the Unix epoch.DocumentBuilder
for method chaining.IllegalArgumentException
- If the name
is null
.DocumentBuilder addUuid(String name, UUID uuid) throws IllegalArgumentException
UUID
binary element.
This method throws an IllegalArgumentException
if the
uuid
is null
. If you would prefer a
NullElement
be inserted in the document use the
add(String, UUID)
method instead.
name
- The name of the element.uuid
- The UUID
to add.DocumentBuilder
for method chaining.IllegalArgumentException
- If the name
or uuid
is null
.DocumentBuilder push(String name) throws IllegalArgumentException
name
- The name of the sub-document.DocumentBuilder
for constructing the sub-document.IllegalArgumentException
- If the name
is null
.ArrayBuilder pushArray(String name) throws IllegalArgumentException
name
- The name of the sub-array.ArrayBuilder
for constructing the sub-array.IllegalArgumentException
- If the name
is null
.DocumentBuilder remove(String name)
Element
s that have the provided name from the
document being built.
Note that adding a new element with the same name add that element to the end of document's element list.
name
- The name of the element to remove.DocumentBuilder
for method chaining.DocumentBuilder reset()
Overridden to return an DocumentBuilder
instance.
Copyright © 2011-2013 Allanbank Consulting, Inc.. All Rights Reserved.