public class NullElement extends AbstractElement
Modifier and Type | Field and Description |
---|---|
static ElementType |
TYPE
The BSON type for a binary.
|
ELEMENT_TYPE
Constructor and Description |
---|
NullElement(String name)
Constructs a new
NullElement . |
NullElement(String name,
long size)
Constructs a new
NullElement . |
Modifier and Type | Method and Description |
---|---|
void |
accept(Visitor visitor)
Accepts the visitor and calls the
Visitor.visitNull(java.lang.String) method. |
ElementType |
getType()
Returns the type for the BSON type.
|
Object |
getValueAsObject()
Returns the value for BSON element as a Java
Object type. |
String |
getValueAsString()
Returns the value for BSON element as a Java
String . |
NullElement |
withName(String name)
Creates a new element with the same type and value as this element but
with the specified name.
|
public static final ElementType TYPE
public NullElement(String name)
NullElement
.name
- The name for the BSON null.IllegalArgumentException
- If the name
is null
.public NullElement(String name, long size)
NullElement
.name
- The name for the BSON null.size
- The size of the element when encoded in bytes. If not known
then use the NullElement(String)
constructor instead.IllegalArgumentException
- If the name
is null
.public void accept(Visitor visitor)
Visitor.visitNull(java.lang.String)
method.visitor
- The visitor for the element.Element.accept(Visitor)
public ElementType getType()
public Object 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 null
.
Object
type.public String getValueAsString()
String
. Automatic
conversion from the string value back to an Element is not provided.
Generally the string returned will be the expected value. As an example
for a LongElement with the value 101 the returned string will be "101".
In those cases where there is not canonical form for the value (e.g., a
TimestampElement
the returned
string will match the value when converted to JSON by the
JsonSerializationVisitor
. For a TimestampElement
that is
a string of the form "ISODate('1970-01-01T00:00:00.000+0000')".
Uses the JsonSerializationVisitor
to encode the value. In some
cases it will be more efficient to override this method with a more
straight forward conversion.
Returns the result of String.valueOf(null)
.
getValueAsString
in interface Element
getValueAsString
in class AbstractElement
String
.public NullElement withName(String name)
Returns a new NullElement
.
name
- The new name for the element.Copyright © 2011–2014 Allanbank Consulting, Inc.. All rights reserved.