com.opencms.flex.util
Class CmsUUID

java.lang.Object
  |
  +--com.opencms.flex.util.CmsUUID
All Implemented Interfaces:
Cloneable, Comparable, Serializable

public final class CmsUUID
extends Object
implements Serializable, Cloneable, Comparable

Generates a UUID using spatial and temporal uniqueness.

Spatial uniqueness is derived from ethernet address (MAC, 802.1); temporal from system clock.

For more information about the algorith used, please see draft-leach-uuids-guids-01.txt.

Because Java is unable to read the MAC address of the machine (without using JNI), the MAC address has to be provided first by using the static init(String) method.

This class is just a facade wrapper for the "real" UUID implementation.

Since:
5.0.0
Version:
$Revision: 1.2 $
Author:
Alexander Kandzior (a.kandzior@alkacon.com)
See Also:
Serialized Form

Constructor Summary
CmsUUID()
          Creates a new UUID.
CmsUUID(byte[] data)
          Create a UUID based on a binary data array.
CmsUUID(String uuid)
          Create a UUID based on a String.
 
Method Summary
 Object clone()
          Clones this object.
 int compareTo(Object o)
           
 boolean equals(Object o)
           
static String getDummyEthernetAddress()
          Returns a String representing a dummy (random based) ethernet address.
static CmsUUID getNullUUID()
          Returns a null UUID, use this null UUID to check if a UUID has been initilized or not.
 int hashCode()
          Optimized hashCode implementation for UUID's.
static void init(String ethernetAddress)
          Initialize the UUID generator with the ethernet address of the server machine.
 boolean isNullUUID()
          Returns true if this UUID is equal to the null UUID.
 byte[] toByteArray()
          Returns the UUID as a 16-byte byte array.
 String toString()
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CmsUUID

public CmsUUID()
Creates a new UUID.

Please note that the static init() method has to be called first to initialize the enternet address of the machine.


CmsUUID

public CmsUUID(String uuid)
        throws NumberFormatException
Create a UUID based on a String.

Parameters:
uuid - a String representing a UUID
Throws:
NumberFormatException - in case uuid is not a valid UUID

CmsUUID

public CmsUUID(byte[] data)
Create a UUID based on a binary data array.

Parameters:
data - a binary data array representing a UUID
Method Detail

init

public static void init(String ethernetAddress)
                 throws CmsException
Initialize the UUID generator with the ethernet address of the server machine.

The ethernetAddress parameter must represent a 'standard' ethernet MAC address string (e.g. '00:C0:F0:3D:5B:7C').

Parameters:
ethernetAddress - the ethernet address of the server machine
Throws:
CmsException - in case the ethernetAddress String is not a valid ethernet address

getDummyEthernetAddress

public static String getDummyEthernetAddress()
Returns a String representing a dummy (random based) ethernet address.

Returns:
a String representing a dummy (random based) ethernet address

getNullUUID

public static CmsUUID getNullUUID()
Returns a null UUID, use this null UUID to check if a UUID has been initilized or not.

Returns:
a null UUID

isNullUUID

public boolean isNullUUID()
Returns true if this UUID is equal to the null UUID.

Returns:
true if this UUID is equal to the null UUID

toByteArray

public byte[] toByteArray()
Returns the UUID as a 16-byte byte array.

Returns:
16-byte byte array that contains the UUID's bytes in the network byte order

hashCode

public int hashCode()
Optimized hashCode implementation for UUID's.

Overrides:
hashCode in class Object
See Also:
Object.hashCode()

equals

public boolean equals(Object o)
Overrides:
equals in class Object
See Also:
Object.equals(java.lang.Object)

clone

public Object clone()
Clones this object.

Overrides:
clone in class Object

toString

public String toString()
Overrides:
toString in class Object
See Also:
Object.toString()

compareTo

public int compareTo(Object o)
Specified by:
compareTo in interface Comparable
See Also:
Comparable.compareTo(java.lang.Object)