Class UUID


  • public final class UUID
    extends java.lang.Object
    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 Detail

      • UUID

        public UUID​(int type,
                    byte[] data)
        Parameters:
        type - UUID type
        data - 16 byte UUID contents
      • UUID

        public UUID​(java.util.UUID uuid)
        This is for conversions between two types of UUID
    • Method Detail

      • asBytes

        public byte[] asBytes()
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • stringToBytes

        public static byte[] stringToBytes​(java.lang.String uuid)
        Creates a 128bit number from the String representation of UUID.
        Parameters:
        uuid - The UUID
        Returns:
        byte array that can be used to recreate a UUID instance from the given String representation
      • equals

        public boolean equals​(java.lang.Object o)
        Checking equality of UUIDs is easy; just compare the 128-bit number.
        Overrides:
        equals in class java.lang.Object