org.apache.jackrabbit.uuid
Class UUID

java.lang.Object
  extended byorg.apache.jackrabbit.uuid.UUID
All Implemented Interfaces:
Comparable, Constants, Serializable

public class UUID
extends Object
implements Constants, Serializable, Comparable

UUID represents a Universally Unique Identifier per IETF Draft specification. For more information regarding the IETF Draft UUID specification

See: http://www.ietf.org/internet-drafts/draft-mealling-uuid-urn-01.txt

Copied from the Jakarta Commons-Id project

todo remove and use official commons-id release as soon as it is available

See Also:
Serialized Form

Field Summary
 
Fields inherited from interface org.apache.jackrabbit.uuid.Constants
CLOCK_SEQ_HI_AND_RESERVED_BYTE_8, FORMAT_POSITION1, FORMAT_POSITION2, FORMAT_POSITION3, FORMAT_POSITION4, hexDigits, TIME_HI_AND_VERSION_BYTE_6, TIME_HI_BYTE_LEN, TIME_HI_START_POS, TIME_HI_TS_POS, TIME_LOW_BYTE_LEN, TIME_LOW_START_POS, TIME_LOW_TS_POS, TIME_MID_BYTE_LEN, TIME_MID_START_POS, TIME_MID_TS_POS, TOKEN_LENGTHS, TOKENS_IN_UUID, URN_PREFIX, UUID_BIT_LENGTH, UUID_BYTE_LENGTH, UUID_FORMATTED_LENGTH, UUID_UNFORMATTED_LENGTH, VARIANT_FUTURE, VARIANT_IETF_DRAFT, VARIANT_MS, VARIANT_NCS_COMPAT, VERSION_FOUR, VERSION_ONE, VERSION_THREE, VERSION_TWO, WRONG_VAR_VER_MSG
 
Constructor Summary
UUID()
          Constructs a nil UUID
UUID(byte[] byteArray)
          Constructs a UUID from a 16 byte array.
UUID(DataInput input)
          Constructs a UUID from a DataInput.
UUID(long mostSignificant, long leastSignificant)
          Constructs a UUID from two long values in most significant byte, and least significant bytes order.
UUID(String uuidString)
          Constructs a UUID from a UUID formatted String.
UUID(UUID copyFrom)
          Copy constructor.
 
Method Summary
 int clockSequence()
          Returns the clock sequence value in the UUID.
 int compareTo(Object compareTo)
          Compares two UUID's for equality
 boolean equals(Object obj)
          Compares two UUID for equality.
static UUID fromString(String uuidString)
          Parses a string for a UUID.
 byte[] getRawBytes()
          Returns a copy of the byte values contained in this UUID.
 int hashCode()
          Returns a hash code value for the object.
 long node()
          Returns the node identifier found in this UUID.
static UUID randomUUID()
          XXX begin modification by stefan@apache.org
 long timestamp()
          Returns the timestamp value of the UUID as 100-nano second intervals since the Gregorian change offset (00:00:00.00, 15 October 1582 ).
 String toString()
          Returns a string representation of the UUID.
 String toUrn()
          Returns a urn representation of the UUID.
 int variant()
          Returns the variant field of the UUID.
 int version()
          Returns the version of the UUID.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UUID

public UUID()
Constructs a nil UUID


UUID

public UUID(UUID copyFrom)

Copy constructor.

Parameters:
copyFrom - the UUID to copy to create this UUID.

UUID

public UUID(byte[] byteArray)
     throws IllegalArgumentException

Constructs a UUID from a 16 byte array.

Parameters:
byteArray - the 16 byte array to construct this UUID from.
Throws:
IllegalArgumentException - argument must be 16 bytes

UUID

public UUID(DataInput input)
     throws IOException

Constructs a UUID from a DataInput. Note if 16 bytes are not available this method will block.

Parameters:
input - the datainput with 16 bytes to read in from.
Throws:
IOException - exception if there is an IO problem also argument must contain 16 bytes.

UUID

public UUID(long mostSignificant,
            long leastSignificant)

Constructs a UUID from two long values in most significant byte, and least significant bytes order.

Parameters:
mostSignificant - - the most significant 8 bytes of the uuid to be constructed.
leastSignificant - - the least significant 8 bytes of the uuid to be constructed.

UUID

public UUID(String uuidString)

Constructs a UUID from a UUID formatted String.

Parameters:
uuidString - the String representing a UUID to construct this UUID
Throws:
UUIDFormatException - String must be a properly formatted UUID string
Method Detail

fromString

public static UUID fromString(String uuidString)
                       throws IllegalArgumentException

Parses a string for a UUID.

Parameters:
uuidString - the UUID formatted String to parse. XXX begin modification by stefan@apache.org
Returns:
Returns a UUID or null if the formatted string could not be parsed.
Throws:
IllegalArgumentException - the String must be a properly formatted UUID String. XXX end modification by stefan@apache.org

toString

public String toString()

Returns a string representation of the UUID.

Returns:
a string representation of the UUID formatted according to the specification.

toUrn

public String toUrn()

Returns a urn representation of the UUID. This is same as the toString() value prefixed with urn:uuid:

Returns:
Returns the urn string representation of the UUID

equals

public boolean equals(Object obj)

Compares two UUID for equality.

See Also:
Object.equals(Object)

hashCode

public int hashCode()

Returns a hash code value for the object.

See Also:
Object.hashCode()

compareTo

public int compareTo(Object compareTo)
              throws ClassCastException

Compares two UUID's for equality

Specified by:
compareTo in interface Comparable
Throws:
ClassCastException
See Also:
Comparable.compareTo(Object)

clockSequence

public int clockSequence()
                  throws UnsupportedOperationException

Returns the clock sequence value in the UUID. The clock sequence is a random assigned to a particular clock instance that generated the time in the timestamp of a time based UUID.

Returns:
the clock sequence value in the UUID.
Throws:
UnsupportedOperationException - thrown if this is not a IETF variant or not a time-based UUID.

version

public int version()

Returns the version of the UUID.

Returns:
the version of the UUID.

variant

public int variant()

Returns the variant field of the UUID.

Returns:
Returns the variant field of the UUID.
See Also:
Constants.VARIANT_NCS_COMPAT, Constants.VARIANT_IETF_DRAFT, Constants.VARIANT_MS, Constants.VARIANT_FUTURE

node

public long node()
          throws UnsupportedOperationException

Returns the node identifier found in this UUID. The specification was written such that this value holds the IEEE 802 MAC address. The specification permits this value to be calculated from other sources other than the MAC.

Returns:
the node identifier found in this UUID.
Throws:
UnsupportedOperationException - thrown if this is not a IETF variant or not a time-based UUID.

timestamp

public long timestamp()
               throws UnsupportedOperationException

Returns the timestamp value of the UUID as 100-nano second intervals since the Gregorian change offset (00:00:00.00, 15 October 1582 ).

Returns:
the timestamp value of the UUID as 100-nano second intervals since the Gregorian change offset.
Throws:
UnsupportedOperationException - thrown if this is not a IETF variant or not a time-based UUID.

getRawBytes

public byte[] getRawBytes()

Returns a copy of the byte values contained in this UUID.

Returns:
a copy of the byte values contained in this UUID.

randomUUID

public static UUID randomUUID()
XXX begin modification by stefan@apache.org



Copyright © 2004-2005 The Apache Software Foundation. All Rights Reserved.