messif.objects.keys
Class AbstractObjectKey

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

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

This class encapsulates the standard key used by the AbstractObject - the URI locator. It is also an ancestor of all key classes to be used in the Abstact object.

See Also:
Serialized Form

Constructor Summary
protected AbstractObjectKey(BinaryInput input, BinarySerializator serializator)
          Creates a new instance of AbstractObjectKey loaded from binary input.
  AbstractObjectKey(java.lang.String locatorURI)
          Creates a new instance of AbstractObjectKey given the locator URI.
 
Method Summary
 int binarySerialize(BinaryOutput output, BinarySerializator serializator)
          Binary-serialize this object into the output.
 int compareTo(AbstractObjectKey o)
          Compare the keys according to their locators.
static
<T extends AbstractObjectKey>
T
create(java.lang.Class<? extends T> keyClass, java.lang.String keyData)
          Factory method for creating object key instances of arbitrary class.
 boolean equals(java.lang.Object obj)
          Returns whether this key is equal to the obj.
 int getBinarySize(BinarySerializator serializator)
          Returns the exact size of the binary-serialized version of this object in bytes.
 java.lang.String getLocatorURI()
          Returns the URI from this key as a string.
 int hashCode()
          Return the hashCode of the locator URI or 0, if it is null.
 java.lang.String toString()
          Returns the URI string.
 void write(java.io.OutputStream stream)
          Writes this object key into the output text stream.
protected  void writeData(java.io.OutputStream stream)
          Store this key's data to a text stream.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractObjectKey

public AbstractObjectKey(java.lang.String locatorURI)
Creates a new instance of AbstractObjectKey given the locator URI.

Parameters:
locatorURI - the URI locator

AbstractObjectKey

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

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

create

public static <T extends AbstractObjectKey> T create(java.lang.Class<? extends T> keyClass,
                                                     java.lang.String keyData)
Factory method for creating object key instances of arbitrary class. The key class must contain a public constructor with single String argument.

Type Parameters:
T - the class of created the object key
Parameters:
keyClass - the class of created the object key
keyData - the data from which to create the key
Returns:
a new instance of object key

getLocatorURI

public java.lang.String getLocatorURI()
Returns the URI from this key as a string.

Returns:
the URI from this key as a string

write

public final void write(java.io.OutputStream stream)
                 throws java.io.IOException
Writes this object key into the output text stream. The key is written using the following format:
#objectKey keyClass key value

Parameters:
stream - the stream to write the key to
Throws:
java.io.IOException - if any problem occures during comment writing

writeData

protected void writeData(java.io.OutputStream stream)
                  throws java.io.IOException
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).

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 their locators.

Specified by:
compareTo in interface java.lang.Comparable<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 hashCode of the locator URI or 0, if it is null.

Overrides:
hashCode in class java.lang.Object
Returns:
the hashCode of the locator URI or 0, if it is null

equals

public boolean equals(java.lang.Object obj)
Returns whether this key is equal to the obj. It is only and only if the obj is descendant of AbstractObjectKey and has an equal locator URI.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the 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()
Returns the URI string.

Overrides:
toString in class java.lang.Object
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
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
Parameters:
serializator - the serializator used to write objects
Returns:
size of the binary-serialized version of this object