public class IntegerElement extends AbstractElement implements NumericElement
| Modifier and Type | Field and Description |
|---|---|
static ElementType |
TYPE
The BSON type for a integer.
|
ELEMENT_TYPE| Constructor and Description |
|---|
IntegerElement(String name,
int value)
Constructs a new
IntegerElement. |
IntegerElement(String name,
int value,
long size)
Constructs a new
IntegerElement. |
| Modifier and Type | Method and Description |
|---|---|
void |
accept(Visitor visitor)
Accepts the visitor and calls the
Visitor.visitInteger(java.lang.String, int) method. |
int |
compareTo(Element otherElement) |
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.
|
double |
getDoubleValue()
Returns the value cast to a double.
|
int |
getIntValue()
Returns the value cast to an integer.
|
long |
getLongValue()
Returns the value cast to a long.
|
ElementType |
getType()
Returns the type for the BSON type.
|
int |
getValue()
Returns the BSON integer value.
|
Integer |
getValueAsObject()
Returns the value for BSON element as a Java
Object type. |
String |
getValueAsString()
Returns the value for BSON element as a Java
String. |
int |
hashCode()
Computes a reasonable hash code.
|
IntegerElement |
withName(String name)
Creates a new element with the same type and value as this element but
with the specified name.
|
asElement, find, find, findFirst, findFirst, getName, nullSafeEquals, size, toStringclone, finalize, getClass, notify, notifyAll, wait, wait, waitfind, find, findFirst, findFirst, getName, sizeasElementpublic static final ElementType TYPE
public IntegerElement(String name, int value)
IntegerElement.name - The name for the BSON integer.value - The BSON integer value.IllegalArgumentException - If the name is null.public IntegerElement(String name, int value, long size)
IntegerElement.name - The name for the BSON integer.value - The BSON integer value.size - The size of the element when encoded in bytes. If not known
then use the
IntegerElement(String, int) constructor
instead.IllegalArgumentException - If the name is null.public void accept(Visitor visitor)
Visitor.visitInteger(java.lang.String, int) method.accept in interface Elementvisitor - The visitor for the element.Element.accept(Visitor)public int compareTo(Element otherElement)
Overridden to compare the elements based on the tuple (name, type, value).
Overridden to compare the elements based on the tuple (name, type). Derived classes are responsible for the value portion of the full comparison.
Overridden to compare the values if the base class comparison is equals.
Note that for MongoDB integers, longs, and doubles will return equal based on the type. Care is taken here to make sure that double, integer, and long values return the same value regardless of comparison order by using the lowest resolution representation of the value.
compareTo in interface ElementcompareTo in interface Comparable<Element>compareTo in class AbstractElementpublic boolean equals(Object object)
equals in class AbstractElementobject - The object to compare to.Object.equals(java.lang.Object)public double getDoubleValue()
Note: There may be a loss of precision using this method if the
NumericElement is not a
DoubleElement.
Overridden to return the integer value as a double.
getDoubleValue in interface NumericElementpublic int getIntValue()
Note: There may be a loss of precision using this method if the
NumericElement is not a
IntegerElement.
Overridden to return the integer value.
getIntValue in interface NumericElementpublic long getLongValue()
Note: There may be a loss of precision using this method if the
NumericElement is not a
LongElement.
Overridden to return the integer value as a long.
getLongValue in interface NumericElementpublic ElementType getType()
public int getValue()
public Integer 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 Integer with the value.
getValueAsObject in interface ElementObject 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 Integer.toString(int).
getValueAsString in interface ElementgetValueAsString in class AbstractElementString.public int hashCode()
hashCode in class AbstractElementpublic IntegerElement withName(String name)
Returns a new IntegerElement.
Copyright © 2011–2014 Allanbank Consulting, Inc.. All rights reserved.