messif.objects.impl
Class MetaObjectMap

java.lang.Object
  extended by messif.objects.UniqueID
      extended by messif.objects.AbstractObject
          extended by messif.objects.LocalAbstractObject
              extended by messif.objects.MetaObject
                  extended by messif.objects.impl.MetaObjectMap
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<UniqueID>, BinarySerializable, Clearable

public class MetaObjectMap
extends MetaObject
implements BinarySerializable

Implementation of MetaObject that stores encapsulated objects in a hash table. The metric distance function for this object is the absolute value of the differences of locatorURI hashcodes.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class messif.objects.LocalAbstractObject
LocalAbstractObject.DataEqualObject
 
Field Summary
protected  java.util.Map<java.lang.String,LocalAbstractObject> objects
          List of encapsulated objects
 
Fields inherited from class messif.objects.LocalAbstractObject
counterDistanceComputations, counterLowerBoundDistanceComputations, counterUpperBoundDistanceComputations, MAX_DISTANCE, MIN_DISTANCE, suppData, UNKNOWN_DISTANCE
 
Constructor Summary
protected MetaObjectMap(BinaryInput input, BinarySerializator serializator)
          Creates a new instance of MetaObject loaded from binary input buffer.
  MetaObjectMap(java.io.BufferedReader stream)
          Creates a new instance of MetaObjectMap from a text stream.
  MetaObjectMap(java.io.BufferedReader stream, java.util.Set<java.lang.String> restrictNames)
          Creates a new instance of MetaObjectMap from a text stream.
  MetaObjectMap(java.io.BufferedReader stream, java.lang.String[] restrictNames)
          Creates a new instance of MetaObjectMap from a text stream.
  MetaObjectMap(java.lang.String locatorURI, java.util.Map<java.lang.String,LocalAbstractObject> objects)
          Creates a new instance of MetaObjectMap from a collection of named objects.
  MetaObjectMap(java.lang.String locatorURI, java.util.Map<java.lang.String,LocalAbstractObject> objects, boolean cloneObjects)
          Creates a new instance of MetaObjectMap from a collection of named objects.
 
Method Summary
 int binarySerialize(BinaryOutput output, BinarySerializator serializator)
          Binary-serialize this object into the output.
 LocalAbstractObject clone(boolean cloneFilterChain)
          Creates and returns a copy of this object.
 LocalAbstractObject cloneRandomlyModify(java.lang.Object... args)
          Creates and returns a randomly modified copy of this object.
static MetaObjectMap create(java.io.File file)
          Creates a meta object from the specified file.
 int getBinarySize(BinarySerializator serializator)
          Returns the exact size of the binary-serialized version of this object in bytes.
protected  float getDistanceImpl(LocalAbstractObject obj, float[] metaDistances, float distThreshold)
          The actual implementation of the metric function.
 LocalAbstractObject getObject(java.lang.String name)
          Returns the encapsulated object for given symbolic name.
 int getObjectCount()
          Returns the number of encapsulated objects.
 java.util.Map<java.lang.String,LocalAbstractObject> getObjectMap()
          Returns a collection of all the encapsulated objects associated with their symbolic names.
 java.util.Collection<java.lang.String> getObjectNames()
          Returns a set of symbolic names of the encapsulated objects.
 java.util.Collection<LocalAbstractObject> getObjects()
          Returns a collection of all the encapsulated objects.
protected  void readObjects(java.io.BufferedReader stream, java.util.Collection<java.lang.String> restrictNames)
          Fills this instance of MetaObject from a text stream.
protected  void writeData(java.io.OutputStream stream)
          Store this object to a text stream.
 
Methods inherited from class messif.objects.MetaObject
clearSurplusData, containsObject, createMetaDistancesHolder, createSearchMetaObject, dataEquals, dataHashCode, fillMetaDistances, fillMetaDistances, getDistanceImpl, getSize, readObject, readObject, toString
 
Methods inherited from class messif.objects.LocalAbstractObject
clone, create, create, excludeUsingPrecompDist, getDistance, getDistance, getDistance, getDistanceFilter, getDistanceFilter, getDistanceFilter, 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

objects

protected java.util.Map<java.lang.String,LocalAbstractObject> objects
List of encapsulated objects

Constructor Detail

MetaObjectMap

public MetaObjectMap(java.lang.String locatorURI,
                     java.util.Map<java.lang.String,LocalAbstractObject> objects,
                     boolean cloneObjects)
              throws java.lang.CloneNotSupportedException
Creates a new instance of MetaObjectMap from a collection of named objects. The locatorURI of every object from the collection is set to the provided one.

Parameters:
locatorURI - the locator URI for this object and all the provided objects will be set as well
objects - collection of objects with their symbolic names
cloneObjects - if true the provided objects will be cloned, otherwise the the locators of the provided objects will be replaced by the specified one
Throws:
java.lang.CloneNotSupportedException - if the clonning of the objects was unsuccessful

MetaObjectMap

public MetaObjectMap(java.lang.String locatorURI,
                     java.util.Map<java.lang.String,LocalAbstractObject> objects)
Creates a new instance of MetaObjectMap from a collection of named objects. The locatorURI of every object from the collection is set to the provided one.

Parameters:
locatorURI - the locator URI for this object and all the provided objects will be set as well
objects - collection of objects with their symbolic names

MetaObjectMap

public MetaObjectMap(java.io.BufferedReader stream,
                     java.util.Set<java.lang.String> restrictNames)
              throws java.io.IOException
Creates a new instance of MetaObjectMap from a text stream. Only objects for names specified in restrictNames are added.

Parameters:
stream - the text stream to read an object from
restrictNames - if not null only the names specified in this collection are added to the objects table
Throws:
java.io.IOException - when an error appears during reading from given stream, EOFException is returned if end of the given stream is reached.

MetaObjectMap

public MetaObjectMap(java.io.BufferedReader stream,
                     java.lang.String[] restrictNames)
              throws java.io.IOException
Creates a new instance of MetaObjectMap from a text stream. Only objects for names specified in restrictNames are added.

Parameters:
stream - the text stream to read an object from
restrictNames - if not null only the names specified in this collection are added to the objects table
Throws:
java.io.IOException - when an error appears during reading from given stream, EOFException is returned if end of the given stream is reached.

MetaObjectMap

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

Parameters:
stream - the text stream to read an object from
Throws:
java.io.IOException - when an error appears during reading from given stream, EOFException is returned if end of the given stream is reached.

MetaObjectMap

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

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

create

public static MetaObjectMap create(java.io.File file)
                            throws java.io.IOException
Creates a meta object from the specified file. The constructor from BufferedReader is used.

Parameters:
file - the file to create the object from
Returns:
a new instance of MetaObjectMap
Throws:
java.io.IOException - if there was an error reading from the specified file

clone

public LocalAbstractObject clone(boolean cloneFilterChain)
                          throws java.lang.CloneNotSupportedException
Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object.

Overrides:
clone in class LocalAbstractObject
Parameters:
cloneFilterChain - the flag wheter the filter chain must be cloned as well.
Returns:
a clone of this instance.
Throws:
java.lang.CloneNotSupportedException - if the object's class does not support clonning or there was an error

cloneRandomlyModify

public LocalAbstractObject cloneRandomlyModify(java.lang.Object... args)
                                        throws java.lang.CloneNotSupportedException
Creates and returns a randomly modified copy of this object. The modification depends on particular subclass implementation.

Overrides:
cloneRandomlyModify in class LocalAbstractObject
Parameters:
args - any parameters required by the subclass implementation - usually two objects with the miminal and the maximal possible values
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

readObjects

protected void readObjects(java.io.BufferedReader stream,
                           java.util.Collection<java.lang.String> restrictNames)
                    throws java.io.IOException
Fills this instance of MetaObject from a text stream.

Parameters:
stream - the text stream to read the objects from
restrictNames - if not null only the names specified in this collection are added to the objects table
Throws:
java.io.IOException - when an error appears during reading from given stream, EOFException is returned if end of the given stream is reached.

writeData

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

getObjectMap

public java.util.Map<java.lang.String,LocalAbstractObject> getObjectMap()
Returns a collection of all the encapsulated objects associated with their symbolic names. Note that the collection can contain null values.

Overrides:
getObjectMap in class MetaObject
Returns:
a map with symbolic names as keyas and the respective encapsulated objects as values

getObject

public LocalAbstractObject getObject(java.lang.String name)
Description copied from class: MetaObject
Returns the encapsulated object for given symbolic name.

Specified by:
getObject in class MetaObject
Parameters:
name - the symbolic name of the object to return
Returns:
encapsulated object for given name or null if the key is unknown

getObjectNames

public java.util.Collection<java.lang.String> getObjectNames()
Description copied from class: MetaObject
Returns a set of symbolic names of the encapsulated objects.

Specified by:
getObjectNames in class MetaObject
Returns:
a set of symbolic names of the encapsulated objects

getObjects

public java.util.Collection<LocalAbstractObject> getObjects()
Description copied from class: MetaObject
Returns a collection of all the encapsulated objects.

Overrides:
getObjects in class MetaObject
Returns:
a collection of all the encapsulated objects

getObjectCount

public int getObjectCount()
Description copied from class: MetaObject
Returns the number of encapsulated objects.

Specified by:
getObjectCount in class MetaObject
Returns:
the number of encapsulated objects

getDistanceImpl

protected float getDistanceImpl(LocalAbstractObject obj,
                                float[] metaDistances,
                                float distThreshold)
The actual implementation of the metric function. The distance is computed as the difference of this and obj's locator hash-codes. The array metaDistances is ignored.

Specified by:
getDistanceImpl in class MetaObject
Parameters:
obj - the object to compute distance to
metaDistances - the array that is filled with the distances of the respective encapsulated objects, if it is not null
distThreshold - the threshold value on the distance
Returns:
the actual distance between obj and this if the distance is lower than distThreshold
See Also:
LocalAbstractObject.getDistance(messif.objects.LocalAbstractObject)

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