Class UID

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, ID

    public class UID
    extends java.lang.Object
    implements ID
    A unique identifier (uniqueness only guarantied inside of the virtual machine in which it was created).

    The identifier is composed of:

    1. A long generated from the current system time (in milliseconds).
    2. A long generated from a counter (which is the number of UID objects that have been created durring the life of the executing virtual machine).
        [ time ] - [ counter ]
     

    Numbers are converted to radix(Character.MAX_RADIX) when converting to strings.

    This should provide adequate uniqueness for most purposes.

    Version:
    $Revision$
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static java.util.concurrent.atomic.AtomicLong COUNTER
      A counter for generating identity values
      protected long id
      The identity portion of the UID
      private static long serialVersionUID  
      protected long time
      The time portion of the UID
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
        UID()
      Construct a new UID.
      protected UID​(UID uid)
      Copy a UID.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String asString()
      Returns a UID as a string.
      java.lang.Object clone()
      Returns a copy of this UID.
      boolean equals​(java.lang.Object obj)
      Checks if the given object is equal to this UID.
      long getID()
      Get the identity portion of this UID.
      long getTime()
      Get the time portion of this UID.
      int hashCode()
      Return the hash code of this UID.
      java.lang.String toString()
      Return a string representation of this UID.
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • COUNTER

        protected static final java.util.concurrent.atomic.AtomicLong COUNTER
        A counter for generating identity values
      • time

        protected final long time
        The time portion of the UID
      • id

        protected final long id
        The identity portion of the UID
    • Constructor Detail

      • UID

        public UID()
        Construct a new UID.
      • UID

        protected UID​(UID uid)
        Copy a UID.
        Parameters:
        uid -
    • Method Detail

      • getTime

        public final long getTime()
        Get the time portion of this UID.
        Returns:
        The time portion of this UID.
      • getID

        public final long getID()
        Get the identity portion of this UID.
        Returns:
        The identity portion of this UID.
      • toString

        public java.lang.String toString()
        Return a string representation of this UID.
        Overrides:
        toString in class java.lang.Object
        Returns:
        A string representation of this UID.
      • hashCode

        public int hashCode()
        Return the hash code of this UID.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        The hash code of this UID.
      • equals

        public boolean equals​(java.lang.Object obj)
        Checks if the given object is equal to this UID.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        obj - Object to test equality with.
        Returns:
        True if object is equal to this UID.
      • clone

        public java.lang.Object clone()
        Returns a copy of this UID.
        Overrides:
        clone in class java.lang.Object
        Returns:
        A copy of this UID.
      • asString

        public static java.lang.String asString()
        Returns a UID as a string.
        Returns:
        UID as a string.