public class Identifier extends Object implements Comparable<Identifier>, Serializable
Instances of this class are immutable, so those can be shared without problem between threads.
The value is internally this is stored as a byte array.
| Modifier | Constructor and Description |
|---|---|
protected |
Identifier(byte[] value)
Creates a new instance of Identifier
|
|
Identifier(Identifier identifier)
Deprecated.
objects of this class are immutable and therefore don't have to be cloned when
used from multiple threads
|
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(Identifier that)
Compares two identifiers.
|
boolean |
equals(Object that)
Returns whether both Identifiers contain equal value.
|
static Identifier |
fromBytes(byte[] bytes,
int start,
int end,
boolean littleEndian)
Creates an Identifier from the specified byte array.
|
static Identifier |
fromInt(int intValue)
Creates an Identifier backed by a two byte Array (big endian).
|
static Identifier |
fromLong(long longValue,
int desiredByteLength)
Creates an Identifer backed by an array of length desiredByteLength
|
static Identifier |
fromUuid(UUID uuid)
Transforms a
UUID into an Identifier. |
int |
getByteCount()
Returns the byte length of this identifier.
|
int |
hashCode() |
static Identifier |
parse(String stringValue)
Takes the passed string and tries to figure out what format it is in.
|
static Identifier |
parse(String stringValue,
int desiredByteLength)
Variant of the parse method that allows specifying the byte length of the identifier.
|
byte[] |
toByteArray()
Gives you the byte array backing this Identifier.
|
byte[] |
toByteArrayOfSpecifiedEndianness(boolean bigEndian)
Converts identifier to a byte array
|
String |
toHexString()
Represents the value as a hexadecimal String.
|
int |
toInt()
Represents the value as an
int. |
String |
toString()
Represents the value as a String.
|
UUID |
toUuid()
Gives you the Identifier as a UUID if possible.
|
String |
toUuidString()
Deprecated.
Replaced by stronger typed variant.
This mathod returns a string, therefore does not offer type safety on
the UUID per se. It was replaced by
toUuid(). |
@Deprecated public Identifier(Identifier identifier)
identifier - identifier to copyprotected Identifier(byte[] value)
value - value to use. This value isn't copied, so don't change the value after using it to create an instance!public static Identifier parse(String stringValue)
fromUuid(java.util.UUID) directly, which is safe.
Allowed formats:
stringValue - string to parseIllegalArgumentException - if the passed string cannot be parsedNullPointerException - if the passed string is nullpublic static Identifier parse(String stringValue, int desiredByteLength)
stringValue - desiredByteLength - parse(String)public static Identifier fromLong(long longValue, int desiredByteLength)
longValue - a long to put into the identifierdesiredByteLength - how many bytes to make the identifierpublic static Identifier fromInt(int intValue)
intValue - an integer between 0 and 65535 (inclusive)public static Identifier fromBytes(byte[] bytes, int start, int end, boolean littleEndian)
bytes - array to copy fromstart - the start index, inclusiveend - the end index, exclusivelittleEndian - whether the bytes are ordered in little endianNullPointerException - bytes must not be nullArrayIndexOutOfBoundsException - start or end are outside the bounds of the arrayIllegalArgumentException - start is larger than endpublic static Identifier fromUuid(UUID uuid)
UUID into an Identifier.
No mangling with strings, only the underlying bytes of the
UUID are used so this is fast and stable.public String toString()
0x, for example 0x0012abpublic int toInt()
int.UnsupportedOperationException - when value length is longer than 2public byte[] toByteArrayOfSpecifiedEndianness(boolean bigEndian)
bigEndian - true if bytes are MSB firstpublic int getByteCount()
public boolean equals(Object that)
public String toHexString()
0x. For example 0x0034ab@Deprecated public String toUuidString()
toUuid().UnsupportedOperationException - when value length is not 16 bytespublic UUID toUuid()
UnsupportedOperationException - if the byte array backing this Identifier is not exactly
16 bytes long.public byte[] toByteArray()
public int compareTo(Identifier that)
compareTo in interface Comparable<Identifier>that - the other identifierComparable.compareTo(T)