messif.objects.keys
Class IntegerKey

java.lang.Object
  extended by messif.objects.keys.AbstractObjectKey
      extended by messif.objects.keys.IntegerKey
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<AbstractObjectKey>, BinarySerializable

public class IntegerKey
extends AbstractObjectKey

The object key that contains an integer value and a locator URI.

See Also:
Serialized Form

Field Summary
 int key
          The integer key
 
Constructor Summary
protected IntegerKey(BinaryInput input, BinarySerializator serializator)
          Creates a new instance of IntegerKey loaded from binary input.
  IntegerKey(java.lang.String keyString)
          Creates a new instance of AbstractObjectKey given a buffered reader with the first line of the following format: "integerKey locatorUri"
  IntegerKey(java.lang.String locatorURI, int key)
          Creates a new instance of IntegerKey
 
Method Summary
 int binarySerialize(BinaryOutput output, BinarySerializator serializator)
          Binary-serialize this object into the output.
 int compareTo(AbstractObjectKey o)
          Compare the keys according to the integer key
 boolean equals(java.lang.Object obj)
          Equals according to the integer key.
 int getBinarySize(BinarySerializator serializator)
          Returns the exact size of the binary-serialized version of this object in bytes.
 int hashCode()
          Return the integer key itself.
 java.lang.String toString()
          Returns the URI string.
protected  void writeData(java.io.OutputStream stream)
          Store this key's data to a text stream.
 
Methods inherited from class messif.objects.keys.AbstractObjectKey
create, getLocatorURI, write
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

key

public final int key
The integer key

Constructor Detail

IntegerKey

public IntegerKey(java.lang.String locatorURI,
                  int key)
Creates a new instance of IntegerKey

Parameters:
locatorURI - the URI locator
key - the integer key of the object - it musn't be null

IntegerKey

public IntegerKey(java.lang.String keyString)
           throws java.lang.IllegalArgumentException
Creates a new instance of AbstractObjectKey given a buffered reader with the first line of the following format: "integerKey locatorUri"

Parameters:
keyString - the text stream to read an object from
Throws:
java.lang.IllegalArgumentException - if the string is not of format "integerKey locatorUri"

IntegerKey

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

Parameters:
input - the input to read the IntegerKey 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

writeData

protected void writeData(java.io.OutputStream stream)
                  throws java.io.IOException
Description copied from class: AbstractObjectKey
Store this key's data to a text stream. This method should have the opposite deserialization in constructor. Note that this method should not write a line separator (\n).

Overrides:
writeData in class AbstractObjectKey
Parameters:
stream - the stream to store this object to
Throws:
java.io.IOException - if there was an error while writing to stream

compareTo

public int compareTo(AbstractObjectKey o)
Compare the keys according to the integer key

Specified by:
compareTo in interface java.lang.Comparable<AbstractObjectKey>
Overrides:
compareTo in class AbstractObjectKey
Parameters:
o - the key to compare this key with
Returns:
a negative integer, zero, or a positive integer if this object is less than, equal to, or greater than the specified object

hashCode

public int hashCode()
Return the integer key itself.

Overrides:
hashCode in class AbstractObjectKey
Returns:
the integer key itself

equals

public boolean equals(java.lang.Object obj)
Equals according to the integer key. If the parameter is not of the IntegerKey class then return false.

Overrides:
equals in class AbstractObjectKey
Parameters:
obj - object to compare this object to
Returns:
true if this object is the same as the obj argument; false otherwise

toString

public java.lang.String toString()
Description copied from class: AbstractObjectKey
Returns the URI string.

Overrides:
toString in class AbstractObjectKey
Returns:
the URI string

binarySerialize

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

Specified by:
binarySerialize in interface BinarySerializable
Overrides:
binarySerialize in class AbstractObjectKey
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

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

Specified by:
getBinarySize in interface BinarySerializable
Overrides:
getBinarySize in class AbstractObjectKey
Parameters:
serializator - the serializator used to write objects
Returns:
size of the binary-serialized version of this object