CoherenceTM v3.3
Copyright© 2000-2007 by Oracle Corporation

com.tangosol.util
Class UID

java.lang.Object
  extended by com.tangosol.util.Base
      extended by com.tangosol.util.UID
All Implemented Interfaces:
Serializable, Comparable

public class UID
extends Base
implements Comparable, Serializable

A UID is a 128-bit identifier that is almost guaranteed to be unique.

Author:
cp 2000.09.12

Constructor Summary
UID()
          Construct a UID (default constructor).
UID(byte[] ab)
          Construct a UID from a byte array.
UID(DataInput stream)
          Construct a UID from a stream.
UID(int nAddr, long lDatetime, int nCount)
          Construct a UID from its constituent members (advanced constructor).
UID(String s)
          Construct a UID from a String.
 
Method Summary
 int compareTo(Object o)
          Compares this object with the specified object for order.
 boolean equals(Object o)
          Determine if two UIDs are equal.
 int getAddress()
          Determine the internet address of the host that generated the UID instance (or a random number if no internet address was available)
 int getCount()
          Determine the "counter" portion of the UID that ensures that two UIDs generated at the same exact time by the same process are unique.
 long getTimestamp()
          Determine the date/time value that the UID instance was generated.
 int hashCode()
          Determine a hash code for the UID object.
static void main(String[] asArgs)
          Allow UID identifiers to be generated or parsed at the command line.
 void save(DataOutput stream)
          Store this UID in a stream.
 byte[] toByteArray()
          Convert the UID to a byte array of 16 bytes.
 char[] toCharArray()
          Convert the UID to a character array of 32 hex digits.
static long toLong(InetAddress addr)
          Converts and IP address to a long value.
 String toString()
          Convert the UID to a printable String.
static String toString(long l)
          Converts a long value to an address string in the form returned by InetAddress#getHostAddress.
 

Constructor Detail

UID

public UID()
Construct a UID (default constructor).


UID

public UID(int nAddr,
           long lDatetime,
           int nCount)
Construct a UID from its constituent members (advanced constructor).

Parameters:
nAddr - the InetAddress-related portion of the UID
lDatetime - the creation date/time millis portion of the UID
nCount - the counter portion of the UID

UID

public UID(byte[] ab)
Construct a UID from a byte array.

Parameters:
ab - a byte array as would be returned from UID.toByteArray()

UID

public UID(String s)
Construct a UID from a String.

Parameters:
s - a String as would be returned from UID.toString()

UID

public UID(DataInput stream)
    throws IOException
Construct a UID from a stream. This is a custom serialization implementation that is unrelated to the Serializable interface and the Java implementation of persistence.

Parameters:
stream - an object implementing java.io.DataInput that contains the internal information that a previous UID wrote
Throws:
IOException - if an error occurs reading from the stream
Method Detail

main

public static void main(String[] asArgs)
Allow UID identifiers to be generated or parsed at the command line. For example, to generate 10 identifiers: java com.tangosol.util.UID 10


getAddress

public int getAddress()
Determine the internet address of the host that generated the UID instance (or a random number if no internet address was available)

Returns:
a 4-byte integer value holding an internet address in the byte order that is used by InetAddress and LicensedObject

getTimestamp

public long getTimestamp()
Determine the date/time value that the UID instance was generated.

Returns:
date/time value in millis that the UID instance was generated

getCount

public int getCount()
Determine the "counter" portion of the UID that ensures that two UIDs generated at the same exact time by the same process are unique.

Returns:
a number that helps to make the UID unique

toString

public String toString()
Convert the UID to a printable String.

Returns:
the UID data as a 0x-prefixed hex string.

toByteArray

public byte[] toByteArray()
Convert the UID to a byte array of 16 bytes.

Returns:
the UID data as a byte array of 16 bytes

toCharArray

public char[] toCharArray()
Convert the UID to a character array of 32 hex digits.

Returns:
the UID data as a character array of 32 hex digits

equals

public boolean equals(Object o)
Determine if two UIDs are equal.

Parameters:
o - the other UID
Returns:
true if the passed object is equal to this

compareTo

public int compareTo(Object o)
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Specified by:
compareTo in interface Comparable
Parameters:
o - the Object to be compared.
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object
Throws:
ClassCastException - if the specified object's type prevents it from being compared to this Object

hashCode

public int hashCode()
Determine a hash code for the UID object.

Returns:
a hash code reflecting the UID's data

save

public void save(DataOutput stream)
          throws IOException
Store this UID in a stream. This is a custom serialization implementation that is unrelated to the Serializable interface and the Java implementation of persistence.

Parameters:
stream - an object implementing java.io.DataOutput that this UID should write its internal information to.
Throws:
IOException - if an error occurs writing to the stream

toLong

public static long toLong(InetAddress addr)
Converts and IP address to a long value.

Parameters:
addr - an instance of InetAddress to convert to a long
Returns:
a long value holding the IP address

toString

public static String toString(long l)
Converts a long value to an address string in the form returned by InetAddress#getHostAddress.

Parameters:
l - the long value holding the IP address
Returns:
the IP address string "%d.%d.%d.%d"

CoherenceTM v3.3
Copyright© 2000-2007 by Oracle Corporation