public class DocumentElement extends AbstractElement implements Document
Modifier and Type | Field and Description |
---|---|
static List<Element> |
EMPTY_ELEMENTS
The empty list of elements.
|
static ElementType |
TYPE
The BSON type for a document.
|
ELEMENT_TYPE
Constructor and Description |
---|
DocumentElement(String name,
Collection<Element> elements)
Constructs a new
DocumentElement . |
DocumentElement(String name,
Document value)
Constructs a new
DocumentElement . |
DocumentElement(String name,
DocumentElement value)
Constructs a new
DocumentElement with a single sub-document
element. |
DocumentElement(String name,
Element... elements)
Constructs a new
DocumentElement . |
DocumentElement(String name,
List<Element> elements)
Constructs a new
DocumentElement . |
DocumentElement(String name,
List<Element> elements,
boolean takeOwnership)
Constructs a new
DocumentElement . |
Modifier and Type | Method and Description |
---|---|
void |
accept(Visitor visitor)
Accepts the visitor and calls the
Visitor.visitDocument(java.lang.String, java.util.List<com.allanbank.mongodb.bson.Element>) method. |
Document |
asDocument()
Converts the object into a document.
|
DocumentReference |
asDocumentReference()
Returns this sub-document as a
DocumentReference if it conforms
to the MongoDB DBRef convention. |
boolean |
contains(String name)
Returns true if the document contains an element with the specified name.
|
boolean |
equals(Object object)
Determines if the passed object is of this same type as this object and
if so that its fields are equal.
|
<E extends Element> |
find(Class<E> clazz,
String... nameRegexs)
Returns the elements matching the path of regular expressions.
|
<E extends Element> |
findFirst(Class<E> clazz,
String... nameRegexs)
Returns the first element matching the path of regular expressions.
|
<E extends Element> |
get(Class<E> clazz,
String name)
Returns the element with the specified name and type or null if no
element with that name and type exists.
|
Element |
get(String name)
Returns the element with the specified name or null if no element with
that name exists.
|
Document |
getDocument()
Returns the element's document.
|
List<Element> |
getElements()
Returns the elements in the document.
|
ElementType |
getType()
Returns the type for the BSON type.
|
Document |
getValueAsObject()
Returns the value for BSON element as a Java
Object type. |
int |
hashCode()
Computes a reasonable hash code.
|
boolean |
isDocumentReference()
Returns true if this sub-document conforms to the MongoDB DBRef
convention, false otherwise.
|
Iterator<Element> |
iterator()
Returns an iterator over the documents elements.
|
DocumentElement |
withName(String name)
Creates a new element with the same type and value as this element but
with the specified name.
|
asElement, find, findFirst, getName, getValueAsString, nullSafeEquals, queryPath, queryPath, toString
public static final ElementType TYPE
public DocumentElement(String name, Collection<Element> elements)
DocumentElement
.name
- The name for the BSON document.elements
- The sub-elements for the document.IllegalArgumentException
- If the name
is null
.public DocumentElement(String name, Document value)
DocumentElement
.name
- The name for the BSON document.value
- The document to copy elements from.IllegalArgumentException
- If the name
or value
is null
.public DocumentElement(String name, DocumentElement value)
DocumentElement
with a single sub-document
element.name
- The name for the BSON document.value
- The document to copy elements from.IllegalArgumentException
- If the name
or value
is null
.public DocumentElement(String name, Element... elements)
DocumentElement
.name
- The name for the BSON document.elements
- The sub-elements for the document.IllegalArgumentException
- If the name
is null
.public DocumentElement(String name, List<Element> elements)
DocumentElement
.name
- The name for the BSON document.elements
- The sub-elements for the document.IllegalArgumentException
- If the name
is null
.public DocumentElement(String name, List<Element> elements, boolean takeOwnership)
DocumentElement
.name
- The name for the BSON document.elements
- The sub-elements for the document.takeOwnership
- If true this element takes ownership of the list to avoid a
copy of the list.public void accept(Visitor visitor)
Visitor.visitDocument(java.lang.String, java.util.List<com.allanbank.mongodb.bson.Element>)
method.accept
in interface Document
accept
in interface Element
visitor
- THe visitor for the document.Element.accept(Visitor)
public Document asDocument()
Returns this element.
asDocument
in interface DocumentAssignable
public DocumentReference asDocumentReference()
DocumentReference
if it conforms
to the MongoDB DBRef convention. Returns null
otherwise.
A DocumentReference contains (order matters):
$ref
.$id
.$db
(Optional).DocumentReference
if it conforms
to the MongoDB DBRef convention. Returns null
otherwise.isDocumentReference()
,
MongoDB
DBRef Informationpublic boolean contains(String name)
contains
in interface Document
name
- The name of the element to locate.Document.contains(String)
public boolean equals(Object object)
equals
in class AbstractElement
object
- The object to compare to.Object.equals(java.lang.Object)
public <E extends Element> List<E> find(Class<E> clazz, String... nameRegexs)
Returns a singleton list if the nameRegexs is empty and this element's type is assignable to E. An empty list otherwise.
Searches this sub-elements for matching elements on the path and are of the right type.
find
in interface Document
find
in interface Element
find
in class AbstractElement
E
- The type of element to match.clazz
- The class of elements to match.nameRegexs
- The path of regular expressions.Element.queryPath(java.lang.Class<E>, java.lang.String...)
public <E extends Element> E findFirst(Class<E> clazz, String... nameRegexs)
Returns a this
if the nameRegexs is empty and this element's type
is assignable to E. An empty list otherwise.
Searches this sub-elements for matching elements on the path and are of the right type.
findFirst
in interface Document
findFirst
in interface Element
findFirst
in class AbstractElement
E
- The type of element to match.clazz
- The class of element to match.nameRegexs
- The path of regular expressions.Document.queryPath(java.lang.Class<E>, java.lang.String...)
public <E extends Element> E get(Class<E> clazz, String name)
get
in interface Document
E
- The type of element to get.clazz
- The class of element to get.name
- The name of the element to locate.Document.get(String)
public Element get(String name)
get
in interface Document
name
- The name of the element to locate.Document.get(String)
public Document getDocument()
public List<Element> getElements()
getElements
in interface Document
public ElementType getType()
public Document getValueAsObject()
Object
type.
Automatic conversion from the Object-ified value to an element is
provided via the DocumentBuilder.add(String, Object)
method. Not
all element types will be successfully converted to the same element
duing a Element-->Object value-->Element conversion. This cases are noted
in the appropriate sub-type's JavaDoc.
Sub-types will also overload this method with the appropriate type
returned. e.g., The
StringElement.getValueAsObject()
method signature returns a String
.
Returns a stand-alone Document
.
getValueAsObject
in interface Element
Object
type.public int hashCode()
hashCode
in class AbstractElement
public boolean isDocumentReference()
A DocumentReference contains (order matters):
$ref
.$id
.$db
(Optional).asDocumentReference()
,
DocumentReference
,
MongoDB
DBRef Informationpublic Iterator<Element> iterator()
iterator
in interface Iterable<Element>
Iterable.iterator()
public DocumentElement withName(String name)
Returns a new DocumentElement
.
Copyright © 2011-2013 Allanbank Consulting, Inc.. All Rights Reserved.