messif.objects
Class MetaObject

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

public abstract class MetaObject
extends LocalAbstractObject

Represents a collection of LocalAbstractObjects encapsulated as one object. All the encapsulated objects share the same locator URI.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class messif.objects.LocalAbstractObject
LocalAbstractObject.DataEqualObject
 
Field Summary
 
Fields inherited from class messif.objects.LocalAbstractObject
counterDistanceComputations, counterLowerBoundDistanceComputations, counterUpperBoundDistanceComputations, MAX_DISTANCE, MIN_DISTANCE, suppData, UNKNOWN_DISTANCE
 
Constructor Summary
protected MetaObject()
          Creates a new instance of MetaObject.
protected MetaObject(AbstractObjectKey objectKey)
          Creates a new instance of MetaObject.
protected MetaObject(BinaryInput input, BinarySerializator serializator)
          Creates a new instance of MetaObject loaded from binary input.
protected MetaObject(java.lang.String locatorURI)
          Creates a new instance of MetaObject.
 
Method Summary
 void clearSurplusData()
          Clear non-messif data stored in this object and all its subobjects.
 boolean containsObject(java.lang.String name)
          Returns true if there is an encapsulated object for given symbolic name.
 float[] createMetaDistancesHolder()
          Returns the array that can hold distances to the respective encapsulated objects.
static MetaObject createSearchMetaObject(java.lang.String locatorURI)
          Create a new instance of a simple MetaObject wihout any encapsulated objects.
 boolean dataEquals(java.lang.Object obj)
          Indicates whether some other object has the same data as this one.
 int dataHashCode()
          Returns sum of hash code values for all the encapsulated objects' data.
protected  int fillMetaDistances(MetaObject obj, float distThreshold, float[] metaDistances)
          Convenience method that fills the given metaDistances array with distances.
protected  int fillMetaDistances(MetaObject obj, float distThreshold, float[] metaDistances, java.lang.String[] objectNames, float unknownDistance)
          Convenience method that fills the given metaDistances array with distances.
protected  float getDistanceImpl(LocalAbstractObject obj, float distThreshold)
          The actual implementation of the metric function.
protected abstract  float getDistanceImpl(LocalAbstractObject obj, float[] metaDistances, float distThreshold)
          The actual implementation of the metric function.
abstract  LocalAbstractObject getObject(java.lang.String name)
          Returns the encapsulated object for given symbolic name.
abstract  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.
abstract  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.
 int getSize()
          Returns the size of this object in bytes.
protected
<E> E
readObject(java.io.BufferedReader stream, java.lang.Class<E> objectClass)
          Reads one object with the specified class name from the stream.
protected  LocalAbstractObject readObject(java.io.BufferedReader stream, java.lang.String className)
          Reads one object with the specified class name from the stream.
 java.lang.String toString()
          Returns a string representation of this metaobject.
 
Methods inherited from class messif.objects.LocalAbstractObject
binarySerialize, chainDestroy, chainFilter, clone, clone, cloneRandomlyModify, create, create, excludeUsingPrecompDist, getBinarySize, getDistance, getDistance, getDistance, getDistanceFilter, getDistanceFilter, getDistanceFilter, getDistanceLowerBound, getDistanceUpperBound, getMaxDistance, getNormDistance, getRandomChar, getRandomNormal, includeUsingPrecompDist, readObjectComments, unchainFilter, write, write, writeData
 
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
 

Constructor Detail

MetaObject

protected MetaObject()
Creates a new instance of MetaObject. A new unique object ID is generated and the object's key is set to null.


MetaObject

protected MetaObject(AbstractObjectKey objectKey)
Creates a new instance of MetaObject. A new unique object ID is generated and the object's key is set to the specified key.

Parameters:
objectKey - the key to be associated with this object

MetaObject

protected MetaObject(java.lang.String locatorURI)
Creates a new instance of MetaObject. A new unique object ID is generated and a new AbstractObjectKey is generated for the specified locatorURI.

Parameters:
locatorURI - the locator URI for the new object

MetaObject

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

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

createSearchMetaObject

public static MetaObject createSearchMetaObject(java.lang.String locatorURI)
Create a new instance of a simple MetaObject wihout any encapsulated objects. This is meant primarilly for the locatorURI distance-based searching.

Parameters:
locatorURI - the locator URI for the new object
Returns:
a new instance of MetaObject without encapsulated objects

getObjectCount

public abstract int getObjectCount()
Returns the number of encapsulated objects.

Returns:
the number of encapsulated objects

getObjectNames

public abstract java.util.Collection<java.lang.String> getObjectNames()
Returns a set of symbolic names of the encapsulated objects.

Returns:
a set of symbolic names of the encapsulated objects

getObject

public abstract LocalAbstractObject getObject(java.lang.String name)
Returns the encapsulated object for given symbolic name.

Parameters:
name - the symbolic name of the object to return
Returns:
encapsulated object for given name or null if the key is unknown

containsObject

public boolean containsObject(java.lang.String name)
Returns true if there is an encapsulated object for given symbolic name.

Parameters:
name - the symbolic name of the object to return
Returns:
true if there is an encapsulated object for given symbolic name

getObjects

public java.util.Collection<LocalAbstractObject> getObjects()
Returns a collection of all the encapsulated objects.

Returns:
a collection of all the encapsulated objects

getObjectMap

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

Returns:
a map with symbolic names as keyas and the respective encapsulated objects as values

readObject

protected LocalAbstractObject readObject(java.io.BufferedReader stream,
                                         java.lang.String className)
                                  throws java.io.IOException
Reads one object with the specified class name from the stream. The class name is looked up first - it must be a descendant of LocalAbstractObject. Then, a constructor with BufferedReader argument is used to load the object up.

Parameters:
stream - the text stream to read the object from
className - the name of the class for the object
Returns:
a new instance of the object
Throws:
java.io.IOException - if there was an error resolving the specified class or its constuctor or a problem occurred while reading from the stream

readObject

protected <E> E readObject(java.io.BufferedReader stream,
                           java.lang.Class<E> objectClass)
                throws java.io.IOException
Reads one object with the specified class name from the stream. The class name is looked up first - it must be a descendant of LocalAbstractObject. Then, a constructor with BufferedReader argument is used to load the object up.

Type Parameters:
E - the class of the object that is read from the stream
Parameters:
stream - the text stream to read the object from
objectClass - the class of the object that is read from the stream
Returns:
a new instance of the object
Throws:
java.io.IOException - if there was an error resolving the specified class or its constuctor or a problem occurred while reading from the stream

dataEquals

public boolean dataEquals(java.lang.Object obj)
Indicates whether some other object has the same data as this one. All the stored local objects for equality with the other metaobject's list.

Specified by:
dataEquals in class LocalAbstractObject
Parameters:
obj - the reference object with which to compare (if it is not MetaObject, this method will return false)
Returns:
true if this object is the same as the obj argument; false otherwise.

dataHashCode

public int dataHashCode()
Returns sum of hash code values for all the encapsulated objects' data.

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

getDistanceImpl

protected final float getDistanceImpl(LocalAbstractObject obj,
                                      float distThreshold)
The actual implementation of the metric function. Method LocalAbstractObject.getDistance(messif.objects.LocalAbstractObject, float[], float) is called with null meta distances array in order to compute the actual distance.

Specified by:
getDistanceImpl in class LocalAbstractObject
Parameters:
obj - the object to compute distance to
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)

getDistanceImpl

protected abstract float getDistanceImpl(LocalAbstractObject obj,
                                         float[] metaDistances,
                                         float distThreshold)
The actual implementation of the metric function. If metaDistances parameter is not null, it should be filled with the distances to the respective encapsulated objects (method fillMetaDistances can be used).

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)

createMetaDistancesHolder

public float[] createMetaDistancesHolder()
Returns the array that can hold distances to the respective encapsulated objects. This method returns a valid array only for descendants of MetaObject, otherwise null is returned.

Overrides:
createMetaDistancesHolder in class LocalAbstractObject
Returns:
the array that can hold distances to meta distances

fillMetaDistances

protected final int fillMetaDistances(MetaObject obj,
                                      float distThreshold,
                                      float[] metaDistances,
                                      java.lang.String[] objectNames,
                                      float unknownDistance)
Convenience method that fills the given metaDistances array with distances. Every item of the array is filled with the distance between the encapsulated object stored in this metaobject under the name given in the respective item of objectNames and the encapsulated object stored in obj metaobject under the same name. If any of the two objects are null, the value of unknownDistance parameter is filled.

Parameters:
obj - the object to compute distance to
distThreshold - the threshold value on the distance
metaDistances - the array that is filled with the distances of the respective encapsulated objects, if it is not null
objectNames - the list of names of encapsulated objects to retrieve from this and obj (must have the same number of items as metaDistances
unknownDistance - the distance to fill if either this or obj's encapsulated object is null
Returns:
the number of computed distances (i.e. the number of distTreshold items minus the number of null objects)
See Also:
LocalAbstractObject.getDistance(messif.objects.LocalAbstractObject)

fillMetaDistances

protected final int fillMetaDistances(MetaObject obj,
                                      float distThreshold,
                                      float[] metaDistances)
Convenience method that fills the given metaDistances array with distances. Every item of the array is filled with the distance between all the encapsulated objects stored in this metaobject and the respective (using the same name) encapsulated object in obj. If any of the two objects are null, the value of LocalAbstractObject.UNKNOWN_DISTANCE is filled.

Parameters:
obj - the object to compute distance to
distThreshold - the threshold value on the distance
metaDistances - the array that is filled with the distances of the respective encapsulated objects, if it is not null
Returns:
the number of computed distances (i.e. the number of distTreshold items minus the number of null objects)
See Also:
LocalAbstractObject.getDistance(messif.objects.LocalAbstractObject)

getSize

public int getSize()
Returns the size of this object in bytes. Calculates the sum of sizes of all encapsulated objects.

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

clearSurplusData

public void clearSurplusData()
Clear non-messif data stored in this object and all its subobjects. This method is intended to be called whenever the object is sent back to client in order to minimize problems with unknown classes after deserialization.

Specified by:
clearSurplusData in interface Clearable
Overrides:
clearSurplusData in class LocalAbstractObject

toString

public java.lang.String toString()
Returns a string representation of this metaobject.

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