com.eaio.uuid
Class UUID

java.lang.Object
  extended by com.eaio.uuid.UUID
All Implemented Interfaces:
Serializable, Cloneable, Comparable<UUID>, IDLEntity

public class UUID
extends Object
implements Comparable<UUID>, Serializable, Cloneable, IDLEntity

Creates UUIDs according to the DCE Universal Token Identifier specification.

All you need to know:

 UUID u = new UUID();
 

Version:
$Id: UUID.java 1888 2009-03-15 12:43:24Z johann $
Author:
Johann Burkard
See Also:
http://www.opengroup.org/onlinepubs/9629399/apdxa.htm , http://www.uddi.org/pubs/draft-leach-uuids-guids-01.txt , UUID, Serialized Form

Field Summary
 long clockSeqAndNode
          The clock sequence and node field of the UUID.
 long time
          The time field of the UUID.
 
Constructor Summary
UUID()
          Constructor for UUID.
UUID(CharSequence s)
          Parses a textual representation of a UUID.
UUID(long time, long clockSeqAndNode)
          Constructor for UUID.
UUID(UUID u)
          Copy constructor for UUID.
 
Method Summary
 Object clone()
          Clones this UUID.
 int compareTo(UUID t)
          Compares this UUID to another Object.
 boolean equals(Object obj)
          Compares two Objects for equality.
 long getClockSeqAndNode()
          Returns the clock and node field of the UUID (lower 64 bits).
 long getTime()
          Returns the time field of the UUID (upper 64 bits).
 int hashCode()
          Returns a hash code of this UUID.
static UUID nilUUID()
          Returns the nil UUID (a UUID whose values are both set to zero).
 Appendable toAppendable(Appendable a)
          Appends a String representation of this object to the given Appendable object.
 String toString()
          Returns this UUID as a String.
 StringBuffer toStringBuffer(StringBuffer in)
          Appends a String representation of this to the given StringBuffer or creates a new one if none is given.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

time

public long time
The time field of the UUID.


clockSeqAndNode

public long clockSeqAndNode
The clock sequence and node field of the UUID.

Constructor Detail

UUID

public UUID()
Constructor for UUID. Constructs a new, unique UUID.

See Also:
UUIDGen.newTime(), UUIDGen.getClockSeqAndNode()

UUID

public UUID(long time,
            long clockSeqAndNode)
Constructor for UUID. Constructs a UUID from two long values.

Parameters:
time - the upper 64 bits
clockSeqAndNode - the lower 64 bits

UUID

public UUID(UUID u)
Copy constructor for UUID. Values of the given UUID are copied.

Parameters:
u - the UUID, may not be null

UUID

public UUID(CharSequence s)
Parses a textual representation of a UUID.

No validation is performed. If the CharSequence is shorter than 36 characters, ArrayIndexOutOfBoundsExceptions will be thrown.

Parameters:
s - the CharSequence, may not be null
Method Detail

compareTo

public int compareTo(UUID t)
Compares this UUID to another Object. Throws a ClassCastException if the other Object is not an instance of the UUID class. Returns a value smaller than zero if the other UUID is "larger" than this UUID and a value larger than zero if the other UUID is "smaller" than this UUID.

Specified by:
compareTo in interface Comparable<UUID>
Parameters:
t - the other UUID, may not be null
Returns:
a value < 0, 0 or a value > 0
Throws:
ClassCastException
See Also:
Comparable.compareTo(java.lang.Object)

toString

public final String toString()
Returns this UUID as a String.

Overrides:
toString in class Object
Returns:
a String, never null
See Also:
Object.toString(), toAppendable(Appendable)

toStringBuffer

public StringBuffer toStringBuffer(StringBuffer in)
Appends a String representation of this to the given StringBuffer or creates a new one if none is given.

Parameters:
in - the StringBuffer to append to, may be null
Returns:
a StringBuffer, never null
See Also:
toAppendable(Appendable)

toAppendable

public Appendable toAppendable(Appendable a)
Appends a String representation of this object to the given Appendable object.

For reasons I'll probably never understand, Sun has decided to have a number of I/O classes implement Appendable which forced them to destroy an otherwise nice and simple interface with IOExceptions.

I decided to ignore any possible IOExceptions in this method.

Parameters:
a - the Appendable object, may be null
Returns:
an Appendable object, defaults to a StringBuilder if a is null

hashCode

public int hashCode()
Returns a hash code of this UUID. The hash code is calculated by XOR'ing the upper 32 bits of the time and clockSeqAndNode fields and the lower 32 bits of the time and clockSeqAndNode fields.

Overrides:
hashCode in class Object
Returns:
an int representing the hash code
See Also:
Object.hashCode()

clone

public Object clone()
Clones this UUID.

Overrides:
clone in class Object
Returns:
a new UUID with identical values, never null

getTime

public final long getTime()
Returns the time field of the UUID (upper 64 bits).

Returns:
the time field

getClockSeqAndNode

public final long getClockSeqAndNode()
Returns the clock and node field of the UUID (lower 64 bits).

Returns:
the clockSeqAndNode field

equals

public boolean equals(Object obj)
Compares two Objects for equality.

Overrides:
equals in class Object
Parameters:
obj - the Object to compare this UUID with, may be null
Returns:
true if the other Object is equal to this UUID, false if not
See Also:
Object.equals(Object)

nilUUID

public static UUID nilUUID()
Returns the nil UUID (a UUID whose values are both set to zero).

Starting with version 2.0, this method does return a new UUID instance every time it is called. Earlier versions returned one instance. This has now been changed because this UUID has public, non-final instance fields. Returning a new instance is therefore more safe.

Returns:
a nil UUID, never null


Copyright © 2003-2011. All Rights Reserved.