public class UuidElement extends BinaryElement
BinaryElement
sub-types.
If no sub-type is provided this class defaults to the standardized sub-type 4 binary element which encodes the UUID from most significant byte to least significant byte. If the deprecated sub-type 3 is specified this class assumes the legacy Java encoding of the UUID which encodes the most significant long in least-significant-byte order and then the least significant long in least-significant-byte order.
Modifier and Type | Field and Description |
---|---|
static byte |
LEGACY_UUID_SUBTTYPE
The legacy (reverse byte order for high and low long values) subtype for
the UUID.
|
static int |
UUID_BINARY_LENGTH
The length for the UUID binary value.
|
static byte |
UUID_SUBTTYPE
The default subtype for the UUID.
|
DEFAULT_SUB_TYPE, TYPE
ELEMENT_TYPE
Constructor and Description |
---|
UuidElement(String name,
byte subType,
byte[] value)
Creates a new UuidElement.
|
UuidElement(String name,
byte subType,
UUID value)
Creates a new UuidElement.
|
UuidElement(String name,
UUID value)
Creates a new UuidElement.
|
Modifier and Type | Method and Description |
---|---|
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.
|
UUID |
getUuid()
Returns the
UUID value. |
UUID |
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.
|
UuidElement |
withName(String name)
Creates a new element with the same type and value as this element but
with the specified name.
|
accept, getSubType, getType, getValue
public static final byte LEGACY_UUID_SUBTTYPE
public static final int UUID_BINARY_LENGTH
public static final byte UUID_SUBTTYPE
public UuidElement(String name, byte subType, byte[] value)
name
- The name for the element.subType
- The subtype for the UUID element.value
- The UUID bytes for the element.IllegalArgumentException
- If the name
or value
is null
. If
the subType is not UUID_SUBTTYPE
or
LEGACY_UUID_SUBTTYPE
. If the value is not a 16 bytes
long.public UuidElement(String name, byte subType, UUID value)
name
- The name for the element.subType
- The subtype for the UUID element.value
- The UUID value for the element.IllegalArgumentException
- If the name
or value
is null
.public UuidElement(String name, UUID value)
name
- The name for the element.value
- The UUID value for the element.IllegalArgumentException
- If the name
or value
is null
.public boolean equals(Object object)
equals
in class BinaryElement
object
- The object to compare to.Object.equals(java.lang.Object)
public UUID 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 byte[].
Note: This value will not be recreated is a Object-->Element
conversion. The sub type is lost in this conversion to an Object
.
Implementation Note: The return type cannot be a byte[] here as
UuidElement
returns a UUID
.
Returns the UUID value.
Note: This value will not be recreated is a Object-->Element
conversion. The sub type is lost in this conversion to an Object
.
getValueAsObject
in interface Element
getValueAsObject
in class BinaryElement
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 the UUID.toString()
.
getValueAsString
in interface Element
getValueAsString
in class AbstractElement
String
.public int hashCode()
hashCode
in class BinaryElement
public UuidElement withName(String name)
Returns a new BinaryElement
.
Returns a new BinaryElement
.
withName
in interface Element
withName
in class BinaryElement
name
- The new name for the element.Copyright © 2011-2013 Allanbank Consulting, Inc.. All Rights Reserved.