org.xlattice
Class NodeID

java.lang.Object
  extended by org.xlattice.NodeID
All Implemented Interfaces:
java.lang.Comparable

public class NodeID
extends java.lang.Object
implements java.lang.Comparable

Quasi-unique 160-bit value serving as a global identifier. This will most often be an SHA-1 digest, but there is no guarantee that it will be. Any value assigned must have the same or similar levels of randomness.

Author:
Jim Dixon

Field Summary
static int LENGTH
          length of the node ID in bytes
 
Constructor Summary
NodeID(byte[] b)
          Create the node ID from a byte array.
NodeID(java.lang.String val)
          Create the node ID from a base-64 encoded value.
 
Method Summary
 java.lang.Object clone()
           
 int compareTo(java.lang.Object o)
           
 boolean equals(java.lang.Object o)
           
 int hashCode()
           
static boolean isValid(byte[] b)
          Whether the array reference is non-null and the array of the right length.
 java.lang.String toString()
           
 byte[] value()
          Return a reference to the byte array.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

LENGTH

public static final int LENGTH
length of the node ID in bytes

See Also:
Constant Field Values
Constructor Detail

NodeID

public NodeID(byte[] b)
Create the node ID from a byte array. The constructor makes a copy of the array.

Parameters:
b - the value to be assigned to the NodeID
Throws:
java.lang.IllegalArgumentException - if the array is not a valid ID

NodeID

public NodeID(java.lang.String val)
Create the node ID from a base-64 encoded value. XXX May need to chomp(val).

Method Detail

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

isValid

public static final boolean isValid(byte[] b)
Whether the array reference is non-null and the array of the right length.

Returns:
true if the reference is not null and the length correct.

value

public final byte[] value()
Return a reference to the byte array. XXX Not comfortable with this; the elements of the array could then be modified.


compareTo

public int compareTo(java.lang.Object o)
Specified by:
compareTo in interface java.lang.Comparable

equals

public final boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object
Returns:
whether the Object o is a NodeID with the same value

hashCode

public final int hashCode()
Overrides:
hashCode in class java.lang.Object
Returns:
a hash useful in NodeID comparisons

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object