messif.objects
Class UniqueID

java.lang.Object
  extended by messif.objects.UniqueID
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<UniqueID>
Direct Known Subclasses:
AbstractObject

public class UniqueID
extends java.lang.Object
implements java.io.Serializable, java.lang.Comparable<UniqueID>

A class that represents an immutable universally unique identifier (UUID). It represents a 128-bit value. It is generated using UUID class's static constructor. Note: we decided not to use the UUID class directly, because it is memory intensive.

See Also:
UUID, Serialized Form

Constructor Summary
protected UniqueID()
          Creates a new instance of UniqueID with newly generated ID.
protected UniqueID(BinaryInput input, BinarySerializator serializator)
          Creates a new instance of UniqueID loaded from binary input.
protected UniqueID(UniqueID source)
          Creates a new instance of UniqueID from an existing UniqueID object.
 
Method Summary
protected  int binarySerialize(BinaryOutput output, BinarySerializator serializator)
          Binary-serialize this object into the output.
protected  java.lang.Object clone()
          Creates and returns a copy of this object.
 int compareTo(UniqueID val)
          Compares this unique ID with the specified unique ID.
 boolean equals(java.lang.Object obj)
          Indicates whether some other object is "equal to" this one.
protected  int getBinarySize(BinarySerializator serializator)
          Returns the exact size of the binary-serialized version of this object in bytes.
 int hashCode()
          Returns a hash code value for this unique ID.
 java.lang.String toString()
          Returns a string representation of this unique ID.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UniqueID

protected UniqueID()
Creates a new instance of UniqueID with newly generated ID.


UniqueID

protected UniqueID(UniqueID source)
Creates a new instance of UniqueID from an existing UniqueID object.

Parameters:
source - the unique ID to copy from

UniqueID

protected UniqueID(BinaryInput input,
                   BinarySerializator serializator)
            throws java.io.IOException
Creates a new instance of UniqueID loaded from binary input.

Parameters:
input - the input to read the ID from
serializator - the serializator used to write objects
Throws:
java.io.IOException - if there was an I/O error reading from the input
Method Detail

equals

public final boolean equals(java.lang.Object obj)
Indicates whether some other object is "equal to" this one. Returns true if and only if the obj is descendant of UniqueID and its internal 128-bit IDs are equal. Otherwise false is returned.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the object to compare with.
Returns:
true if the objects are the same; false otherwise

hashCode

public final int hashCode()
Returns a hash code value for this unique ID.

Overrides:
hashCode in class java.lang.Object
Returns:
a hash code value for this unique ID

toString

public java.lang.String toString()
Returns a string representation of this unique ID.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of this unique ID

clone

protected java.lang.Object clone()
                          throws java.lang.CloneNotSupportedException
Creates and returns a copy of this object. The unique ID of the copy will be different from this object's ID. Note: This method should be called only from clone method of this class's descendants. Thus it is protected and the class doesn't implement Cloneable interface.

Overrides:
clone in class java.lang.Object
Returns:
a copy of this object
Throws:
java.lang.CloneNotSupportedException

compareTo

public final int compareTo(UniqueID val)
Compares this unique ID with the specified unique ID.

The first of two unique IDs follows the second if the most significant field in which the unique IDs differ is greater for the first unique ID.

Specified by:
compareTo in interface java.lang.Comparable<UniqueID>
Parameters:
val - the unique ID to which this unique ID is to be compared.
Returns:
-1, 0 or 1 as this unique ID is less than, equal to, or greater than val.

binarySerialize

protected int binarySerialize(BinaryOutput output,
                              BinarySerializator serializator)
                       throws java.io.IOException
Binary-serialize this object into the output.

Parameters:
output - the output that this object is binary-serialized into
serializator - the serializator used to write objects
Returns:
the number of bytes actually written
Throws:
java.io.IOException - if there was an I/O error during serialization

getBinarySize

protected int getBinarySize(BinarySerializator serializator)
Returns the exact size of the binary-serialized version of this object in bytes.

Parameters:
serializator - the serializator used to write objects
Returns:
size of the binary-serialized version of this object