Oracle® Coherence Java API Reference
v3.5

E14977-01

com.tangosol.util
Class UUID

java.lang.Object
  extended by com.tangosol.util.Base
      extended by com.tangosol.util.UUID
All Implemented Interfaces:
ExternalizableLite, PortableObject, java.io.Externalizable, java.io.Serializable, java.lang.Comparable

public final class UUID
extends Base
implements java.lang.Comparable, java.io.Externalizable, ExternalizableLite, PortableObject

A UUID is a 256-bit identifier that, if it is generated, is statistically guaranteed to be unique.

Author:
cp 2004.06.24

Constructor Summary
UUID()
          Generate a UUID.
UUID(byte[] ab)
          Construct a UUID from a byte array.
UUID(java.io.DataInput stream)
          Construct a UUID from a stream.
UUID(long lDatetime, byte[] abIP, int nPort, int nCount)
          Build a UUID from its constituent members (advanced constructor).
UUID(long lDatetime, java.net.InetAddress addr, int nPort, int nCount)
          Build a UUID from its constituent members (advanced constructor).
UUID(java.lang.String s)
          Construct a UUID from a String.
 
Method Summary
 int compareTo(java.lang.Object o)
          Compares this object with the specified object for order.
 boolean equals(java.lang.Object o)
          Determine if two UUIDs are equal.
 byte[] getAddress()
          Determine the internet address of the host that generated the UUID instance.
 int getCount()
          Determine the "counter" portion of the UUID that ensures that two UUIDs generated at the same exact time by the same process are unique.
 int getPort()
          Determine the port portion of the UUID.
 long getTimestamp()
          Determine the date/time value that the UUID instance was generated.
 int hashCode()
          Determine a hash code for the UUID object.
 boolean isAddressIncluded()
          This is true if the IP address is a real IP address.
 boolean isGenerated()
          This is true if the UUID was generated, and false if it was built.
static void main(java.lang.String[] asArgs)
          Allow UUID identifiers to be generated or parsed at the command line.
 void readExternal(java.io.DataInput in)
          Restore the contents of this object by loading the object's state from the passed DataInput object.
 void readExternal(java.io.ObjectInput in)
          Read this object from an ObjectInputStream.
 void readExternal(PofReader in)
          Restore the contents of a user type instance by reading its state using the specified PofReader object.
 byte[] toByteArray()
          Convert the UUID to a byte array of 32 bytes.
 java.lang.String toString()
          Convert the UUID to a printable String.
 void writeExternal(java.io.DataOutput out)
          Save the contents of this object by storing the object's state into the passed DataOutput object.
 void writeExternal(java.io.ObjectOutput out)
          Write this object to an ObjectOutputStream.
 void writeExternal(PofWriter out)
          Save the contents of a POF user type instance by writing its state using the specified PofWriter object.
 

Constructor Detail

UUID

public UUID()
Generate a UUID.


UUID

public UUID(long lDatetime,
            java.net.InetAddress addr,
            int nPort,
            int nCount)
Build a UUID from its constituent members (advanced constructor).

It is guaranteed that a generated UUID will never equal a built UUID.

Parameters:
lDatetime - the creation date/time millis portion of the UUID
addr - the InetAddress portion of the UUID
nPort - the port number portion of the UUID; a port number is 16 bits, but up to 28 bits of data from this value will be maintained by the UUID
nCount - the counter portion of the UUID

UUID

public UUID(long lDatetime,
            byte[] abIP,
            int nPort,
            int nCount)
Build a UUID from its constituent members (advanced constructor).

It is guaranteed that a generated UUID will never equal a built UUID.

Parameters:
lDatetime - the creation date/time millis portion of the UUID
abIP - the InetAddress portion of the UUID
nPort - the port number portion of the UUID; a port number is 16 bits, but up to 28 bits of data from this value will be maintained by the UUID
nCount - the counter portion of the UUID

UUID

public UUID(java.lang.String s)
Construct a UUID from a String.

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

UUID

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

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

UUID

public UUID(java.io.DataInput stream)
     throws java.io.IOException
Construct a UUID from a stream.

This is a helper constructor that is just a shorthand for a sequence:

   UUID uid = new UUID();
   uid.readExternal(stream);
 

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

main

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


isGenerated

public boolean isGenerated()
This is true if the UUID was generated, and false if it was built. A generated UUID is universally unique. Note that the port number is random if the UUID is generated.

Returns:
true if the UUID was generated

getTimestamp

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

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

isAddressIncluded

public boolean isAddressIncluded()
This is true if the IP address is a real IP address. This is only false if two conditions are met: The UUID is generated, and it could not get an IP address (or one that is not a loopback/localhost address) from the VM.

Returns:
true if the UUID has IP address information

getAddress

public byte[] getAddress()
Determine the internet address of the host that generated the UUID instance.

Returns:
an array of bytes containing the IP address information; the array can be zero bytes (no address,) four bytes (IPv4) or 16 bytes (IPv6)

getPort

public int getPort()
Determine the port portion of the UUID. Note that the port is a 28-bit value; the first nibble is always 0x0.

Returns:
the port portion of the UID

getCount

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

Returns:
a number that helps to make the UUID unique

toByteArray

public byte[] toByteArray()
Convert the UUID to a byte array of 32 bytes.

Returns:
the UUID data as a byte array of 32 bytes

toString

public java.lang.String toString()
Convert the UUID to a printable String.

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

equals

public boolean equals(java.lang.Object o)
Determine if two UUIDs are equal.

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

compareTo

public int compareTo(java.lang.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 java.lang.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:
java.lang.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 UUID object.

Returns:
a hash code reflecting the UUID's data

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException
Read this object from an ObjectInputStream.

Specified by:
readExternal in interface java.io.Externalizable
Parameters:
in - the ObjectInputStream to read this object from
Throws:
java.io.IOException - if an exception occurs reading this object

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Write this object to an ObjectOutputStream.

Specified by:
writeExternal in interface java.io.Externalizable
Parameters:
out - the ObjectOutputStream to write this object to
Throws:
java.io.IOException - thrown if an exception occurs writing this object

readExternal

public void readExternal(java.io.DataInput in)
                  throws java.io.IOException
Restore the contents of this object by loading the object's state from the passed DataInput object.

Specified by:
readExternal in interface ExternalizableLite
Parameters:
in - the DataInput stream to read data from in order to restore the state of this object
Throws:
java.io.IOException - if an I/O exception occurs
java.io.NotActiveException - if the object is not in its initial state, and therefore cannot be deserialized into

writeExternal

public void writeExternal(java.io.DataOutput out)
                   throws java.io.IOException
Save the contents of this object by storing the object's state into the passed DataOutput object.

Specified by:
writeExternal in interface ExternalizableLite
Parameters:
out - the DataOutput stream to write the state of this object to
Throws:
java.io.IOException - if an I/O exception occurs

readExternal

public void readExternal(PofReader in)
                  throws java.io.IOException
Restore the contents of a user type instance by reading its state using the specified PofReader object.

Specified by:
readExternal in interface PortableObject
Parameters:
in - the PofReader from which to read the object's state
Throws:
java.io.IOException - if an I/O error occurs

writeExternal

public void writeExternal(PofWriter out)
                   throws java.io.IOException
Save the contents of a POF user type instance by writing its state using the specified PofWriter object.

Specified by:
writeExternal in interface PortableObject
Parameters:
out - the PofWriter to which to write the object's state
Throws:
java.io.IOException - if an I/O error occurs

Oracle® Coherence Java API Reference
v3.5

E14977-01

Copyright © 2000, 2009, Oracle. All rights reserved.