Class UUID

java.lang.Object
org.apache.activemq.artemis.utils.UUID

public final class UUID extends 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).

  • Field Details

  • Constructor Details

    • UUID

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

      public UUID(UUID uuid)
      This is for conversions between two types of UUID
  • Method Details

    • asBytes

      public byte[] asBytes()
    • hashCode

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

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

      public static byte[] stringToBytes(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(Object o)
      Checking equality of UUIDs is easy; just compare the 128-bit number.
      Overrides:
      equals in class Object