org.planx.xmlstore.routing
Class Identifier

java.lang.Object
  extended by org.planx.xmlstore.routing.Identifier
All Implemented Interfaces:
Serializable, Streamable

public class Identifier
extends Object
implements Streamable, Serializable

An identifier consists of at most IDSIZE bit and it is always positive. Trying to construct an Identifer outside these boundaries will throw an IndexOutOfBoundsException.

TODO: Consider converting Identifier to interface.

See Also:
Serialized Form

Field Summary
static int IDSIZE
          Number of bits in an ID.
 
Constructor Summary
Identifier()
          Constructs an Identifier with value 0.
Identifier(BigInteger val)
          Constructs an Identifier from the specified BigInteger.
Identifier(byte[] val)
          Constructs an Identifier from the specified byte array which is interpreted as a positive integer in big-endian order (most significant byte is in the zeroth element)
Identifier(DataInput in)
          Constructs an Identifier by reading IDSIZE/8 bytes from the specified DataInput.
 
Method Summary
 boolean equals(Object o)
           
 void fromStream(DataInput in)
          Reads the internal state of the Streamable object from the input stream.
 int hashCode()
           
static Identifier randomIdentifier()
          Returns a random Identifer.
 String toBinary()
          Returns a binary string representation of this identifier with IDSIZE bits.
static String toBinary(BigInteger val)
          Returns a binary string representation of the specified BigInteger with IDSIZE bits.
 byte[] toByteArray()
          Returns the value of the identifier in a byte array of size IDSIZE/8 in big-endian order (most significant byte is in the zeroth element).
 void toStream(DataOutput out)
          Writes the internal state of the Streamable object to the output stream in a format that can later be read by the same Streamble class using the Streamable.fromStream(java.io.DataInput) method.
 String toString()
           
 BigInteger value()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

IDSIZE

public static int IDSIZE
Number of bits in an ID. Must be a multiplum of 8. Should be final but test program changes this value to simplify the tests.

Constructor Detail

Identifier

public Identifier()
Constructs an Identifier with value 0.


Identifier

public Identifier(byte[] val)
Constructs an Identifier from the specified byte array which is interpreted as a positive integer in big-endian order (most significant byte is in the zeroth element)


Identifier

public Identifier(BigInteger val)
Constructs an Identifier from the specified BigInteger.


Identifier

public Identifier(DataInput in)
           throws IOException
Constructs an Identifier by reading IDSIZE/8 bytes from the specified DataInput.

Throws:
IOException
Method Detail

randomIdentifier

public static Identifier randomIdentifier()
Returns a random Identifer.


fromStream

public void fromStream(DataInput in)
                throws IOException
Description copied from interface: Streamable
Reads the internal state of the Streamable object from the input stream. Immutable objects should throw an UnsupportedOperationException, and instead implement a constructor as described above.

Specified by:
fromStream in interface Streamable
Throws:
IOException

toStream

public void toStream(DataOutput out)
              throws IOException
Description copied from interface: Streamable
Writes the internal state of the Streamable object to the output stream in a format that can later be read by the same Streamble class using the Streamable.fromStream(java.io.DataInput) method.

Specified by:
toStream in interface Streamable
Throws:
IOException

toByteArray

public byte[] toByteArray()
Returns the value of the identifier in a byte array of size IDSIZE/8 in big-endian order (most significant byte is in the zeroth element).

Throws:
IndexOutOfBoundsException - if the identifier is to large to fit in the array

value

public BigInteger value()

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

toBinary

public String toBinary()
Returns a binary string representation of this identifier with IDSIZE bits.


toBinary

public static String toBinary(BigInteger val)
Returns a binary string representation of the specified BigInteger with IDSIZE bits.



Copyright © 2010. All Rights Reserved.