one.util
Class Guid

java.lang.Object
  |
  +--one.util.Guid
All Implemented Interfaces:
Serializable

public class Guid
extends Object
implements Serializable

Implementation of a globally unique identifier (GUID). Globally unique identifiers are 128-bit values as defined by the Open Group's DCE standard and as used in Microsoft's COM and DCOM.

GUIDs are created by a native, platform-dependent library. Currently, Windows and Linux are supported. The Windows library works on Windows 95 (DCOM release), Windows 98, Windows Me, Windows NT 4.0, and Windows 2000.

Version:
$Revision: 1.13 $
See Also:
DCE Specification for GUIDs, Internet draft specification for GUIDs and UUIDs, Serialized Form

Field Summary
protected static String STRING_TEMPLATE
          The template for a string representation of a GUID.
 
Constructor Summary
Guid()
          Create a new GUID.
Guid(byte[] bytes)
          Create a new GUID from the specified byte array.
Guid(DataInput in)
          Create a new GUID from the specified data input.
Guid(long high, long low)
          Create a new GUID from the specified high and low value.
Guid(String s)
          Create a new GUID from the specified string.
Guid(String s, char sep)
          Create a new GUID from the specified string using the specified separator.
 
Method Summary
 boolean equals(Object o)
          Determine wheter this GUID equals the specified object.
protected  String fill(StringBuffer buf)
          Fill the specified string buffer with a string representation of this GUID.
 long getHigh()
          Get the high double word for this GUID.
 long getLow()
          Get the low double word for this GUID.
 int hashCode()
          Get a hash code for this GUID.
 byte[] toBytes()
          Get the bytes for this GUID.
 String toString()
          Get a string representation of this GUID.
 String toString(char sep)
          Get a string representation of this GUID.
 String toUnderscoredString()
          Get a string representation of this GUID.
 void writeBytes(DataOutput out)
          Write this GUID to the specified data output.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

STRING_TEMPLATE

protected static final String STRING_TEMPLATE
The template for a string representation of a GUID.
Constructor Detail

Guid

public Guid()
Create a new GUID. Due to limitations of the Java standard APIs, it is impossible to correctly create a new GUID in Java. This constructor thus requires a native library to perform the actual GUID creation.

Guid

public Guid(String s)
     throws NumberFormatException
Create a new GUID from the specified string. This constructor parses the string representation of a GUID, for example, as returned by the toString() method of this class.
Parameters:
s - The string representation of the GUID.
Throws:
NumberFormatException - Signals that the specified string does not have the expected format.

Guid

public Guid(String s,
            char sep)
     throws NumberFormatException
Create a new GUID from the specified string using the specified separator. This constructor parses the string representation of a GUID, for example, as returned by the toString(char) method of this class.
Parameters:
s - The string representation of the GUID.
sep - The separator.
Throws:
NumberFormatException - Signals that the specified string does not have the expected format.

Guid

public Guid(byte[] bytes)
Create a new GUID from the specified byte array. This constructor creates a new GUID by reading the binary representation of the GUID from the specified byte array. The byte array must be 16 bytes long and the bytes must be in standard network byte order.
Parameters:
bytes - The binary representation of new GUID.
Throws:
IllegalArgumentException - Signals that bytes is not 16 bytes long.
See Also:
toBytes()

Guid

public Guid(long high,
            long low)
Create a new GUID from the specified high and low value.
Parameters:
high - The most significant 64 bits for the new GUID as a long.
low - The least significant 64 bits for the new GUID as a long.
See Also:
getHigh(), getLow()

Guid

public Guid(DataInput in)
     throws IOException
Create a new GUID from the specified data input. This constructor creates a new GUID by reading 16 bytes in standard network byte order from the specified data input.
Parameters:
in - The data input to read the new GUID from.
Throws:
IOException - Signals an exceptional condition when reading from the specified data input.
Method Detail

equals

public boolean equals(Object o)
Determine wheter this GUID equals the specified object. This GUID equals the specified object, iff the specified object is a GUID with the same 128-bit value.
Overrides:
equals in class Object
Returns:
true if o is a GUID with the same 128-bit value.

hashCode

public int hashCode()
Get a hash code for this GUID.
Overrides:
hashCode in class Object
Returns:
A hash code for this GUID.

writeBytes

public void writeBytes(DataOutput out)
                throws IOException
Write this GUID to the specified data output. This method writes this GUID to the specified data output by writing 16 bytes in standard network byte order.
Parameters:
out - The data output to write the GUID to.
Throws:
IOException - Signals an exceptional condition when writing to the specified data output.

getHigh

public long getHigh()
Get the high double word for this GUID. This method returns the most significant 64 bits of this GUID as a long.
Returns:
The high double word for this GUID.

getLow

public long getLow()
Get the low double word for this GUID. This method returns the least significant 64 bits of this GUID as a long.
Returns:
The low double word for this GUID.

toBytes

public byte[] toBytes()
Get the bytes for this GUID. This method returns a byte array of length 16 containing the binary representation for this GUID. The bytes are in standard network byte order.
Returns:
The binary representation of this GUID.

toString

public String toString()
Get a string representation of this GUID.
Overrides:
toString in class Object
Returns:
A string representation of this GUID.

toUnderscoredString

public String toUnderscoredString()
Get a string representation of this GUID. The returned string uses the underscore character instead of the dash character specified for the standard string format.
Returns:
A string representation of this GUID.

toString

public String toString(char sep)
Get a string representation of this GUID. The returned string uses the specified separator instead of the dash character specified for the standard string format.
Parameters:
sep - The separator.
Returns:
A string representation of this GUID.

fill

protected String fill(StringBuffer buf)
Fill the specified string buffer with a string representation of this GUID. The specified string buffer must have a length of 35 and must contain "00000000-0000-0000-0000-000000000000", where '-' may be replaced with any other character used as a separator.
Parameters:
buf - The string buffer to fill.
Returns:
The corresponding string.


(C) Copyright 2001 UW CSE