messif.objects.keys
Class LongKey

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

public class LongKey
extends AbstractObjectKey

The object key that contains a long value and a locator URI.

See Also:
Serialized Form

Field Summary
 long key
          The long key
 
Constructor Summary
protected LongKey(BinaryInput input, BinarySerializator serializator)
          Creates a new instance of LongKey loaded from binary input.
  LongKey(java.lang.String keyString)
          Creates a new instance of AbstractObjectKey given a buffered reader with the first line of the following format: "longKey locatorUri"
  LongKey(java.lang.String locatorURI, boolean hashURI, long maxValue)
          Creates a new instance of LongKey given only the locatorURI - implicitly create the key as the (locatorURI.hashCode() + Integer.MAX_VALUE) modulo maxKey.
  LongKey(java.lang.String locatorURI, long key)
          Creates a new instance of LongKey
 
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 long key
 boolean equals(java.lang.Object obj)
          Equals according to the long key.
 int getBinarySize(BinarySerializator serializator)
          Returns the exact size of the binary-serialized version of this object in bytes.
 int hashCode()
          Return the long key converted to int.
 java.lang.String toString()
          Return 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 long key
The long key

Constructor Detail

LongKey

public LongKey(java.lang.String locatorURI,
               long key)
Creates a new instance of LongKey

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

LongKey

public LongKey(java.lang.String locatorURI,
               boolean hashURI,
               long maxValue)
        throws java.lang.IllegalArgumentException
Creates a new instance of LongKey given only the locatorURI - implicitly create the key as the (locatorURI.hashCode() + Integer.MAX_VALUE) modulo maxKey.

Parameters:
locatorURI - the URI locator
hashURI - if true then the key is created as hashCode of the locator; it set to 0, otherwise
maxValue - the maximal value the key can have (incremented by 1)
Throws:
java.lang.IllegalArgumentException - if the locatorURI is null

LongKey

public LongKey(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: "longKey locatorUri"

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

LongKey

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

Parameters:
input - the input to read the LongKey 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 long 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 long key converted to int.

Overrides:
hashCode in class AbstractObjectKey
Returns:
the long key converted to int

equals

public boolean equals(java.lang.Object obj)
Equals according to the long key. If the parameter is not of the LongKey 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()
Return 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