| java.lang.Object org.drools.util.UUID
UUID | public class UUID implements Serializable,Cloneable,Comparable(Code) | | UUID represents Universally Unique Identifiers (aka Global UID in
Windows world). UUIDs are usually generated via UUIDGenerator (or in
case of 'Null UUID', 16 zero bytes, via static method getNullUUID()),
or received from external systems.
By default class caches the string presentations of UUIDs so that
description is only created the first time it's needed. For memory
stingy applications this caching can be turned off (note though
that if uuid.toString() is never called, desc is never calculated
so only loss is the space allocated for the desc pointer... which
can of course be commented out to save memory).
Similarly, hash code is calculated when it's needed for the first
time, and from thereon that value is just returned. This means
that using UUIDs as keys should be reasonably efficient.
UUIDs can be compared for equality, serialized, cloned and even sorted.
Equality is a simple bit-wise comparison. Ordering (for sorting) is done by
first ordering based on type (in the order of numeric values of
types), secondarily by time stamp (only for time-based time stamps),
and finally by straight numeric byte-by-byte comparison (from
most to least significant bytes).
|
Constructor Summary | |
public | UUID() Default constructor creates a NIL UUID, one that contains all
zeroes
Note that the clearing of array is actually unnecessary as
JVMs are required to clear up the allocated arrays by default. | public | UUID(byte[] data) Constructor for cases where you already have the 16-byte binary
representation of the UUID (for example if you save UUIDs binary
takes less than half of space string representation takes). | public | UUID(byte[] data, int start) | | UUID(int type, byte[] data) | public | UUID(String id) Constructor for creating UUIDs from the canonical string
representation
Note that implementation is optimized for speed, not necessarily
code clarity... |
Method Summary | |
public byte[] | asByteArray() | public Object | clone() Default cloning behaviour (bitwise copy) is just fine... | public int | compareTo(Object o) Let's also make UUIDs sortable. | public boolean | equals(Object o) Checking equality of UUIDs is easy; just compare the 128-bit
number. | public static UUID | getNullUUID() | public int | getType() | public int | hashCode() | public boolean | isNullUUID() | public static void | setDescCaching(boolean state) | public void | toByteArray(byte[] dst, int pos) Fills in the 16 bytes (from index pos) of the specified byte array
with the UUID contents. | public void | toByteArray(byte[] dst) | public byte[] | toByteArray() | public String | toString() | public static UUID | valueOf(String id) Constructs a new UUID instance given the canonical string
representation of an UUID. | public static UUID | valueOf(byte[] src, int start) Constructs a new UUID instance given a byte array that contains
the (16 byte) binary representation. | public static UUID | valueOf(byte[] src) Constructs a new UUID instance given a byte array that contains
the (16 byte) binary representation. |
INDEX_CLOCK_HI | final public static byte INDEX_CLOCK_HI(Code) | | |
INDEX_CLOCK_LO | final public static byte INDEX_CLOCK_LO(Code) | | |
INDEX_CLOCK_MID | final public static byte INDEX_CLOCK_MID(Code) | | |
INDEX_CLOCK_SEQUENCE | final public static byte INDEX_CLOCK_SEQUENCE(Code) | | |
INDEX_TYPE | final public static byte INDEX_TYPE(Code) | | |
INDEX_VARIATION | final public static byte INDEX_VARIATION(Code) | | |
NAMESPACE_X500 | final public static String NAMESPACE_X500(Code) | | |
TYPE_DCE | final public static byte TYPE_DCE(Code) | | |
TYPE_NAME_BASED | final public static byte TYPE_NAME_BASED(Code) | | |
TYPE_NULL | final public static byte TYPE_NULL(Code) | | |
TYPE_RANDOM_BASED | final public static byte TYPE_RANDOM_BASED(Code) | | |
TYPE_TIME_BASED | final public static byte TYPE_TIME_BASED(Code) | | |
UUID | public UUID()(Code) | | Default constructor creates a NIL UUID, one that contains all
zeroes
Note that the clearing of array is actually unnecessary as
JVMs are required to clear up the allocated arrays by default.
|
UUID | public UUID(byte[] data)(Code) | | Constructor for cases where you already have the 16-byte binary
representation of the UUID (for example if you save UUIDs binary
takes less than half of space string representation takes).
Parameters: data - array that contains the binary representation of UUID |
UUID | public UUID(byte[] data, int start)(Code) | | Constructor for cases where you already have the binary
representation of the UUID (for example if you save UUIDs binary
takes less than half of space string representation takes) in
a byte array
Parameters: data - array that contains the binary representation of UUID Parameters: start - byte offset where UUID starts |
UUID | UUID(int type, byte[] data)(Code) | | Protected constructor used by UUIDGenerator
Parameters: type - UUID type Parameters: data - 16 byte UUID contents |
UUID | public UUID(String id) throws NumberFormatException(Code) | | Constructor for creating UUIDs from the canonical string
representation
Note that implementation is optimized for speed, not necessarily
code clarity... Also, since what we get might not be 100% canonical
(see below), let's not yet populate mDesc here.
Parameters: id - String that contains the canonical representation ofthe UUID to build; 36-char string (see UUID specs for details).Hex-chars may be in upper-case too; UUID class will always outputthem in lowercase. |
asByteArray | public byte[] asByteArray()(Code) | | Returns the UUID as a 16-byte byte array
16-byte byte array that contains UUID bytes in the networkbyte order |
clone | public Object clone()(Code) | | Default cloning behaviour (bitwise copy) is just fine...
Could clear out cached string presentation, but there's
probably no point in doing that.
|
compareTo | public int compareTo(Object o)(Code) | | Let's also make UUIDs sortable. This will mostly/only be useful with
time-based UUIDs; they will sorted by time of creation. The order
will be strictly correct with UUIDs produced over one JVM's lifetime;
that is, if more than one JVMs create UUIDs and/or system is rebooted
the order may not be 100% accurate between UUIDs created under
different JVMs.
For all UUIDs, type is first compared, and UUIDs of different types
are sorted together (ie. null UUID is before all other UUIDs, then
time-based UUIDs etc). If types are the same, time-based UUIDs'
time stamps (including additional clock counter) are compared, so
UUIDs created first are ordered first. For all other types (and for
time-based UUIDs with same time stamp, which should only occur
when comparing a UUID with itself, or with UUIDs created on
different JVMs or external systems) binary comparison is done
over all 16 bytes.
Parameters: o - Object to compare this UUID to; should be a UUID -1 if this UUID should be ordered before the one passed,1 if after, and 0 if they are the same throws: ClassCastException - if o is not a UUID. |
equals | public boolean equals(Object o)(Code) | | Checking equality of UUIDs is easy; just compare the 128-bit
number.
|
getNullUUID | public static UUID getNullUUID()(Code) | | Accessor for getting the shared null UUID
the shared null UUID |
getType | public int getType()(Code) | | Returns the UUID type code
UUID type |
hashCode | public int hashCode()(Code) | | |
isNullUUID | public boolean isNullUUID()(Code) | | |
setDescCaching | public static void setDescCaching(boolean state)(Code) | | |
toByteArray | public void toByteArray(byte[] dst, int pos)(Code) | | Fills in the 16 bytes (from index pos) of the specified byte array
with the UUID contents.
Parameters: dst - Byte array to fill Parameters: pos - Offset in the array |
toByteArray | public void toByteArray(byte[] dst)(Code) | | |
toByteArray | public byte[] toByteArray()(Code) | | 'Synonym' for 'asByteArray'
|
valueOf | public static UUID valueOf(String id) throws NumberFormatException(Code) | | Constructs a new UUID instance given the canonical string
representation of an UUID.
Note that calling this method returns the same result as would
using the matching (1 string arg) constructor.
Parameters: id - Canonical string representation used for constructingan UUID instance throws: NumberFormatException - if 'id' is invalid UUID |
valueOf | public static UUID valueOf(byte[] src, int start)(Code) | | Constructs a new UUID instance given a byte array that contains
the (16 byte) binary representation.
Note that calling this method returns the same result as would
using the matching constructor
Parameters: src - Byte array that contains the UUID definition Parameters: start - Offset in the array where the UUID starts |
valueOf | public static UUID valueOf(byte[] src)(Code) | | Constructs a new UUID instance given a byte array that contains
the (16 byte) binary representation.
Note that calling this method returns the same result as would
using the matching constructor
Parameters: src - Byte array that contains the UUID definition |
|
|