public abstract class AbstractElement extends Object implements Element
Modifier and Type | Field and Description |
---|---|
protected static Class<Element> |
ELEMENT_TYPE
The base type (interface) for all elements.
|
Constructor and Description |
---|
AbstractElement(String name,
long size)
Constructs a new
AbstractElement . |
Modifier and Type | Method and Description |
---|---|
Element |
asElement()
Converts the object into an
Element . |
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.
|
<E extends Element> |
find(Class<E> clazz,
String... nameRegexs)
Returns the elements matching the path of regular expressions.
|
List<Element> |
find(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.
|
Element |
findFirst(String... nameRegexs)
Returns the first element matching the path of regular expressions.
|
String |
getName()
Returns the name for the BSON type.
|
String |
getValueAsString()
Returns the value for BSON element as a Java
String . |
int |
hashCode()
Computes a reasonable hash code.
|
protected boolean |
nullSafeEquals(Object rhs,
Object lhs)
Does a null safe equals comparison.
|
long |
size()
Returns the number of bytes that are used to encode the element.
|
String |
toString()
String form of the object.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
accept, getType, getValueAsObject, withName
public AbstractElement(String name, long size) throws IllegalArgumentException
AbstractElement
.name
- The name for the BSON type.size
- The size of the element when encoded in bytes.IllegalArgumentException
- If the name
is null
.public Element asElement()
Element
.
Returns this element.
asElement
in interface ElementAssignable
Element
.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.
compareTo
in interface Element
compareTo
in interface Comparable<Element>
public boolean equals(Object object)
equals
in class Object
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.
find
in interface Element
E
- The type of element to match.clazz
- The class of elements to match.nameRegexs
- The path of regular expressions.Element.find(java.lang.Class<E>, java.lang.String...)
public List<Element> find(String... nameRegexs)
Returns a singleton list if the nameRegexs is empty. An empty list otherwise.
find
in interface Element
nameRegexs
- The path of regular expressions.Element.find(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.
findFirst
in interface Element
E
- The type of element to match.clazz
- The class of element to match.nameRegexs
- The path of regular expressions.Element.findFirst(java.lang.Class<E>, java.lang.String...)
public Element findFirst(String... nameRegexs)
Searches this sub-elements for matching elements on the path and are of the right type.
findFirst
in interface Element
nameRegexs
- The path of regular expressions.Element.findFirst(java.lang.Class<E>, java.lang.String...)
public String getName()
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.
getValueAsString
in interface Element
String
.public int hashCode()
public long size()
public String toString()
toString
in class Object
Object.toString()
Copyright © 2011–2014 Allanbank Consulting, Inc.. All rights reserved.