messif.objects.impl
Class ObjectString

java.lang.Object
  extended by messif.objects.UniqueID
      extended by messif.objects.AbstractObject
          extended by messif.objects.LocalAbstractObject
              extended by messif.objects.impl.ObjectString
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<UniqueID>, BinarySerializable, Clearable
Direct Known Subclasses:
ObjectStringEditDist

public abstract class ObjectString
extends LocalAbstractObject
implements BinarySerializable

This object uses String as its data content. No implementation of distance function is provided - see ObjectStringEditDist.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class messif.objects.LocalAbstractObject
LocalAbstractObject.DataEqualObject
 
Field Summary
protected  java.lang.String text
          Data string
 
Fields inherited from class messif.objects.LocalAbstractObject
counterDistanceComputations, counterLowerBoundDistanceComputations, counterUpperBoundDistanceComputations, MAX_DISTANCE, MIN_DISTANCE, suppData, UNKNOWN_DISTANCE
 
Constructor Summary
  ObjectString()
          Creates a new instance of ObjectString with randomly generated string content.
protected ObjectString(BinaryInput input, BinarySerializator serializator)
          Creates a new instance of ObjectString loaded from binary input buffer.
  ObjectString(java.io.BufferedReader stream)
          Creates a new instance of ObjectString from text stream.
  ObjectString(int minLength, int maxLength)
          Creates a new instance of ObjectString with randomly generated string content.
  ObjectString(java.lang.String text)
          Creates a new instance of ObjectString.
 
Method Summary
 int binarySerialize(BinaryOutput output, BinarySerializator serializator)
          Binary-serialize this object into the output.
 LocalAbstractObject cloneRandomlyModify(java.lang.Object... args)
          Creates and returns a randomly modified copy of this string.
 boolean dataEquals(java.lang.Object obj)
          Indicates whether some other object has the same data as this one.
 int dataHashCode()
          Returns a hash code value for the data of this object.
static java.lang.String generateRandom(int minLength, int maxLength)
          Generate a random text.
 int getBinarySize(BinarySerializator serializator)
          Returns the exact size of the binary-serialized version of this object in bytes.
 int getSize()
          Returns the size of this object in bytes.
 java.lang.String getStringData()
          Returns the string that represents the contents of this object.
 int getStringLength()
          Returns the length of the content string.
 java.lang.String toString()
          Converts this object to a string representation.
 void writeData(java.io.OutputStream stream)
          Store this object's data to a text stream.
 
Methods inherited from class messif.objects.LocalAbstractObject
clearSurplusData, clone, clone, create, create, createMetaDistancesHolder, excludeUsingPrecompDist, getDistance, getDistance, getDistance, getDistanceFilter, getDistanceFilter, getDistanceFilter, getDistanceImpl, getDistanceLowerBound, getDistanceLowerBoundImpl, getDistanceUpperBound, getDistanceUpperBoundImpl, getMaxDistance, getNormDistance, getRandomChar, getRandomNormal, chainDestroy, chainFilter, includeUsingPrecompDist, readObjectComments, unchainFilter, write, write
 
Methods inherited from class messif.objects.AbstractObject
clone, getLocatorURI, getNoDataObject, getObjectID, getObjectKey, setObjectKey
 
Methods inherited from class messif.objects.UniqueID
compareTo, equals, hashCode
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

text

protected java.lang.String text
Data string

Constructor Detail

ObjectString

public ObjectString(java.lang.String text)
Creates a new instance of ObjectString.

Parameters:
text - the string content of the new object

ObjectString

public ObjectString()
Creates a new instance of ObjectString with randomly generated string content.


ObjectString

public ObjectString(int minLength,
                    int maxLength)
Creates a new instance of ObjectString with randomly generated string content. The string content is genereated with at least minLength characters and at most maxLength characters.

Parameters:
minLength - minimal length of the randomly generated string content
maxLength - maximal length of the randomly generated string content

ObjectString

public ObjectString(java.io.BufferedReader stream)
             throws java.io.EOFException,
                    java.io.IOException
Creates a new instance of ObjectString from text stream.

Parameters:
stream - the stream from which to read lines of text
Throws:
java.io.EOFException - if the end-of-file of the given stream is reached
java.io.IOException - if there was an I/O error during reading from the stream

ObjectString

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

Parameters:
input - the buffer to read the ObjectString from
serializator - the serializator used to write objects
Throws:
java.io.IOException - if there was an I/O error reading from the buffer
Method Detail

generateRandom

public static java.lang.String generateRandom(int minLength,
                                              int maxLength)
Generate a random text. The generated text has at least minLength characters and at most maxLength characters.

Parameters:
minLength - minimal length of the randomly generated text
maxLength - maximal length of the randomly generated text
Returns:
a random text

writeData

public void writeData(java.io.OutputStream stream)
               throws java.io.IOException
Description copied from class: LocalAbstractObject
Store this object's data to a text stream. This method should have the opposite deserialization in constructor of a given object class.

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

dataEquals

public boolean dataEquals(java.lang.Object obj)
Description copied from class: LocalAbstractObject
Indicates whether some other object has the same data as this one.

Specified by:
dataEquals in class LocalAbstractObject
Parameters:
obj - the reference object with which to compare.
Returns:
true if this object is the same as the obj argument; false otherwise.

dataHashCode

public int dataHashCode()
Description copied from class: LocalAbstractObject
Returns a hash code value for the data of this object.

Specified by:
dataHashCode in class LocalAbstractObject
Returns:
a hash code value for the data of this object

getStringData

public java.lang.String getStringData()
Returns the string that represents the contents of this object.

Returns:
the string that represents the contents of this object

getStringLength

public int getStringLength()
Returns the length of the content string.

Returns:
the length of the content string

getSize

public int getSize()
Description copied from class: LocalAbstractObject
Returns the size of this object in bytes.

Specified by:
getSize in class LocalAbstractObject
Returns:
the size of this object in bytes

cloneRandomlyModify

public LocalAbstractObject cloneRandomlyModify(java.lang.Object... args)
                                        throws java.lang.CloneNotSupportedException
Creates and returns a randomly modified copy of this string. Selects a string position in random and changes it - possible char values are in the passed argument.

Overrides:
cloneRandomlyModify in class LocalAbstractObject
Parameters:
args - expected size of the args array is 1: ObjectString containing all possible chars
Returns:
a randomly modified clone of this instance.
Throws:
java.lang.CloneNotSupportedException - if the object's class does not support clonning or there was an error

toString

public java.lang.String toString()
Converts this object to a string representation.

Overrides:
toString in class AbstractObject
Returns:
a string representation of this abstract object

binarySerialize

public int binarySerialize(BinaryOutput output,
                           BinarySerializator serializator)
                    throws java.io.IOException
Description copied from class: LocalAbstractObject
Binary-serialize this object into the output.

Specified by:
binarySerialize in interface BinarySerializable
Overrides:
binarySerialize in class LocalAbstractObject
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)
Description copied from class: LocalAbstractObject
Returns the exact size of the binary-serialized version of this object in bytes.

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