Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.opencms.flex.util
Class CmsUUID  view CmsUUID download CmsUUID.java

java.lang.Object
  extended bycom.opencms.flex.util.CmsUUID
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable, java.io.Serializable

public final class CmsUUID
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable, java.lang.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) 55 method.

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

Since:
5.0.0
Version:
$Revision: 1.2 $

Field Summary
private static EthernetAddress m_ethernetAddress
          Ethernet addess of the server machine
private static boolean m_isNotInitialized
          Flag to indicate if the ethernet addess has been initilized
private  UUID m_uuid
          Internal UUID implementation
 
Constructor Summary
CmsUUID()
          Creates a new UUID.
CmsUUID(byte[] data)
          Create a UUID based on a binary data array.
CmsUUID(java.lang.String uuid)
          Create a UUID based on a String.
 
Method Summary
 java.lang.Object clone()
          Clones this object.
 int compareTo(java.lang.Object o)
          Compares this object with another, and returns a numerical result based on the comparison.
 boolean equals(java.lang.Object o)
          Determine whether this Object is semantically equal to another Object.
static java.lang.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(java.lang.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.
 java.lang.String toString()
          Convert this Object to a human-readable String.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

m_ethernetAddress

private static EthernetAddress m_ethernetAddress
Ethernet addess of the server machine


m_isNotInitialized

private static boolean m_isNotInitialized
Flag to indicate if the ethernet addess has been initilized


m_uuid

private UUID m_uuid
Internal UUID implementation

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(java.lang.String uuid)
        throws java.lang.NumberFormatException
Create a UUID based on a String.


CmsUUID

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

Method Detail

init

public static void init(java.lang.String ethernetAddress)
                 throws com.opencms.core.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').


getDummyEthernetAddress

public static java.lang.String getDummyEthernetAddress()
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.


isNullUUID

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


toByteArray

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


hashCode

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


equals

public boolean equals(java.lang.Object o)
Description copied from class: java.lang.Object
Determine whether this Object is semantically equal to another Object.

There are some fairly strict requirements on this method which subclasses must follow:

  • It must be transitive. If a.equals(b) and b.equals(c), then a.equals(c) must be true as well.
  • It must be symmetric. a.equals(b) and b.equals(a) must have the same value.
  • It must be reflexive. a.equals(a) must always be true.
  • It must be consistent. Whichever value a.equals(b) returns on the first invocation must be the value returned on all later invocations.
  • a.equals(null) must be false.
  • It must be consistent with hashCode(). That is, a.equals(b) must imply a.hashCode() == b.hashCode(). The reverse is not true; two objects that are not equal may have the same hashcode, but that has the potential to harm hashing performance.

This is typically overridden to throw a java.lang.ClassCastException if the argument is not comparable to the class performing the comparison, but that is not a requirement. It is legal for a.equals(b) to be true even though a.getClass() != b.getClass(). Also, it is typical to never cause a java.lang.NullPointerException.

In general, the Collections API (java.util) use the equals method rather than the == operator to compare objects. However, java.util.IdentityHashMap is an exception to this rule, for its own good reasons.

The default implementation returns this == o.


clone

public java.lang.Object clone()
Clones this object.


toString

public java.lang.String toString()
Description copied from class: java.lang.Object
Convert this Object to a human-readable String. There are no limits placed on how long this String should be or what it should contain. We suggest you make it as intuitive as possible to be able to place it into System.out.println() 55 and such.

It is typical, but not required, to ensure that this method never completes abruptly with a java.lang.RuntimeException.

This method will be called when performing string concatenation with this object. If the result is null, string concatenation will instead use "null".

The default implementation returns getClass().getName() + "@" + Integer.toHexString(hashCode()).


compareTo

public int compareTo(java.lang.Object o)
Description copied from interface: java.lang.Comparable
Compares this object with another, and returns a numerical result based on the comparison. If the result is negative, this object sorts less than the other; if 0, the two are equal, and if positive, this object sorts greater than the other. To translate this into boolean, simply perform o1.compareTo(o2) <op> 0, where op is one of <, <=, =, !=, >, or >=.

You must make sure that the comparison is mutual, ie. sgn(x.compareTo(y)) == -sgn(y.compareTo(x)) (where sgn() is defined as -1, 0, or 1 based on the sign). This includes throwing an exception in either direction if the two are not comparable; hence, compareTo(null) should always throw an Exception.

You should also ensure transitivity, in two forms: x.compareTo(y) > 0 && y.compareTo(z) > 0 implies x.compareTo(z) > 0; and x.compareTo(y) == 0 implies x.compareTo(z) == y.compareTo(z).

Specified by:
compareTo in interface java.lang.Comparable