public abstract class MetaObject extends LocalAbstractObject
LocalAbstractObject.DataEqualObject, LocalAbstractObject.TextStreamFactory<T extends LocalAbstractObject>, LocalAbstractObject.TrivialDistanceFunction
counterDistanceComputations, counterLowerBoundDistanceComputations, counterPrecomputedDistanceSavings, counterUpperBoundDistanceComputations, MAX_DISTANCE, MIN_DISTANCE, suppData, trivialDistanceFunction, UNKNOWN_DISTANCE
Modifier | Constructor and Description |
---|---|
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.
|
Modifier and Type | Method and Description |
---|---|
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 without 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.
|
protected static <T> T |
getObjectFromMap(java.util.Map<java.lang.String,? extends LocalAbstractObject> objects,
java.lang.String name,
java.lang.Class<? extends T> objectClass,
boolean clone,
AbstractObjectKey cloneKey)
|
java.util.Map<java.lang.String,? extends 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<? extends LocalAbstractObject> |
getObjects()
Returns a collection of all the encapsulated objects.
|
int |
getSize()
Returns the size of this object in bytes.
|
protected static float |
implementationGetDistance(LocalAbstractObject o1,
LocalAbstractObject o2,
float distThreshold)
Convenience method that allows to call the metric function implementation
directly for encapsulated objects (so that the statistics and caching does not apply).
|
protected static <E> E |
readObject(java.io.BufferedReader stream,
java.lang.Class<E> objectClass)
Reads one object with the specified class name from the stream.
|
protected static LocalAbstractObject |
readObject(java.io.BufferedReader stream,
java.lang.String className)
Reads one object with the specified class name from the stream.
|
protected java.util.Map<java.lang.String,LocalAbstractObject> |
readObjects(java.io.BufferedReader stream,
java.util.Collection<java.lang.String> restrictNames,
java.lang.String[] namesAndClasses,
java.util.Map<java.lang.String,LocalAbstractObject> objects)
Utility method for reading objects from a text stream.
|
protected LocalAbstractObject[] |
readObjects(java.io.BufferedReader stream,
int count,
java.lang.Class<? extends LocalAbstractObject> objectClass)
Utility method for reading
count objects of class objectClass from a text stream. |
protected java.lang.String[] |
readObjectsHeader(java.io.BufferedReader stream)
Utility method for reading metaobject header from a text stream.
|
java.lang.String |
toString()
Returns a string representation of this metaobject.
|
protected void |
writeObjects(java.io.OutputStream stream,
java.util.Collection<? extends LocalAbstractObject> objects)
Utility method for writing a the given objects to a text stream.
|
protected <T extends LocalAbstractObject> |
writeObjectsHeader(java.io.OutputStream stream,
java.util.Map<java.lang.String,T> objects)
Utility method for writing a metaobject header to a given text stream.
|
binarySerialize, clone, clone, cloneRandomlyModify, create, create, excludeUsingPrecompDist, getBinarySize, getDistance, getDistance, getDistance, getDistanceFilter, getDistanceFilter, getDistanceFilter, getDistanceFilter, getDistanceLowerBound, getDistanceLowerBoundImpl, getDistanceStorePrecomputed, getDistanceStorePrecomputed, getDistanceStorePrecomputed, getDistanceUpperBound, getDistanceUpperBoundImpl, getFieldsForNames, getMaxDistance, getNormDistance, getPrecomputedDistance, getPrecomputedDistance, getRandomChar, getRandomNormal, chainDestroy, chainFilter, includeUsingPrecompDist, isDistanceCompatible, parseObjectComment, peekNextChar, readAttributesFromStream, readObjectComments, readObjectCommentsWithoutData, unchainFilter, write, write, writeAttributesToStream, writeData, writeObjectComment
clone, getLocatorURI, getNoDataObject, getObjectKey, getObjectKey, getObjectLocatorURI, setObjectKey
protected MetaObject()
protected MetaObject(AbstractObjectKey objectKey)
objectKey
- the key to be associated with this objectprotected MetaObject(java.lang.String locatorURI)
AbstractObjectKey
is generated for
the specified locatorURI
.locatorURI
- the locator URI for the new objectprotected MetaObject(BinaryInput input, BinarySerializator serializator) throws java.io.IOException
input
- the input to read the MetaObject fromserializator
- the serializator used to write objectsjava.io.IOException
- if there was an I/O error reading from the bufferpublic static MetaObject createSearchMetaObject(java.lang.String locatorURI)
locatorURI
- the locator URI for the new objectprotected static <T> T getObjectFromMap(java.util.Map<java.lang.String,? extends LocalAbstractObject> objects, java.lang.String name, java.lang.Class<? extends T> objectClass, boolean clone, AbstractObjectKey cloneKey) throws java.lang.ClassCastException, java.lang.CloneNotSupportedException
T
- the type of the object to retrieve from the mapobjects
- the map of named objectsname
- the name of the object to retrieveobjectClass
- the class of the object to retrieveclone
- flag whether to clone the retrieved object (true) or not (false)cloneKey
- the object key to set for the cloned datajava.lang.ClassCastException
- if there was an object with the given name in the map, but it has a different classjava.lang.CloneNotSupportedException
- if the cloning was not supported by the objectpublic abstract int getObjectCount()
public abstract java.util.Collection<java.lang.String> getObjectNames()
public abstract LocalAbstractObject getObject(java.lang.String name)
name
- the symbolic name of the object to returnpublic boolean containsObject(java.lang.String name)
name
- the symbolic name of the object to returnpublic java.util.Collection<? extends LocalAbstractObject> getObjects()
public java.util.Map<java.lang.String,? extends LocalAbstractObject> getObjectMap()
protected static LocalAbstractObject readObject(java.io.BufferedReader stream, java.lang.String className) throws java.io.IOException
LocalAbstractObject
.
Then, a constructor with BufferedReader
argument is used to load the object up.stream
- the text stream to read the object fromclassName
- the name of the class for the objectjava.io.IOException
- if there was an error resolving the specified class or its constructor or a problem
occurred while reading from the streamprotected static <E> E readObject(java.io.BufferedReader stream, java.lang.Class<E> objectClass) throws java.io.IOException
LocalAbstractObject
.
Then, a constructor with BufferedReader
argument is used to load the object up.E
- the class of the object that is read from the streamstream
- the text stream to read the object fromobjectClass
- the class of the object that is read from the streamjava.io.IOException
- if there was an error resolving the specified class or its constructor or a problem
occurred while reading from the streamprotected final java.lang.String[] readObjectsHeader(java.io.BufferedReader stream) throws java.io.IOException
BufferedReader
constructor.
Note that this method also reads the object comments
.stream
- the text stream to read the header fromjava.io.IOException
- when an error appears during reading from given stream,
EOFException is returned if end of the given stream is reached.writeObjectsHeader(java.io.OutputStream, java.util.Map)
,
writeObjects(java.io.OutputStream, java.util.Collection)
protected final java.util.Map<java.lang.String,LocalAbstractObject> readObjects(java.io.BufferedReader stream, java.util.Collection<java.lang.String> restrictNames, java.lang.String[] namesAndClasses, java.util.Map<java.lang.String,LocalAbstractObject> objects) throws java.io.IOException
BufferedReader
constructor.
The namesAndClasses
parameter can be retrieved by readObjectsHeader(java.io.BufferedReader)
method.stream
- the text stream to read the objects fromrestrictNames
- if not null only the names specified in this collection are added to the objects tablenamesAndClasses
- the list of names and object classes pairs
(the name of the first object is the first item, the class of the first object is the second item, and so on)objects
- the map into which the objects are storedjava.io.IOException
- when an error appears during reading from given stream,
EOFException is returned if end of the given stream is reached.writeObjectsHeader(java.io.OutputStream, java.util.Map)
,
writeObjects(java.io.OutputStream, java.util.Collection)
protected final LocalAbstractObject[] readObjects(java.io.BufferedReader stream, int count, java.lang.Class<? extends LocalAbstractObject> objectClass) throws java.io.IOException, java.lang.IllegalArgumentException
count
objects of class objectClass
from a text stream.
This method is intended to be used in subclasses to implement the BufferedReader
constructor.stream
- the text stream to read the objects fromcount
- the number of objects to read from the streamobjectClass
- the class of objects to readjava.io.IOException
- when an error appears during reading from given stream,
EOFException is returned if end of the given stream is reached.java.lang.IllegalArgumentException
- if the count parameter is negativeprotected final <T extends LocalAbstractObject> java.util.Collection<T> writeObjectsHeader(java.io.OutputStream stream, java.util.Map<java.lang.String,T> objects) throws java.io.IOException
T
- the type of objects stored in the mapstream
- the stream to write the header and encapsulated objects toobjects
- the objects the header of which to writejava.io.IOException
- if there was an error while writing to streamreadObjectsHeader(java.io.BufferedReader)
,
readObjects(java.io.BufferedReader, java.util.Collection, java.lang.String[], java.util.Map)
protected final void writeObjects(java.io.OutputStream stream, java.util.Collection<? extends LocalAbstractObject> objects) throws java.io.IOException
objects
parameter can be prepared by writeObjectsHeader(java.io.OutputStream, java.util.Map<java.lang.String, T>)
method.stream
- the stream to write the header and encapsulated objects toobjects
- the objects to writejava.io.IOException
- if there was an error while writing to streamreadObjectsHeader(java.io.BufferedReader)
,
readObjects(java.io.BufferedReader, java.util.Collection, java.lang.String[], java.util.Map)
public boolean dataEquals(java.lang.Object obj)
dataEquals
in class LocalAbstractObject
obj
- the reference object with which to compare (if it is not MetaObject, this method will return false
)true
if this object is the same as the obj
argument; false
otherwise.public int dataHashCode()
dataHashCode
in class LocalAbstractObject
protected final float getDistanceImpl(LocalAbstractObject obj, float distThreshold)
LocalAbstractObject.getDistance(messif.objects.LocalAbstractObject, float[], float)
is called with null meta distances array in order to compute the
actual distance.getDistanceImpl
in class LocalAbstractObject
obj
- the object to compute distance todistThreshold
- the threshold value on the distanceLocalAbstractObject.getDistance(messif.objects.LocalAbstractObject)
protected abstract float getDistanceImpl(LocalAbstractObject obj, float[] metaDistances, float distThreshold)
metaDistances
parameter is not null, it should be filled
with the distances to the respective encapsulated objects (method
fillMetaDistances
can be used).obj
- the object to compute distance tometaDistances
- the array that is filled with the distances of the respective encapsulated objects, if it is not nulldistThreshold
- the threshold value on the distanceLocalAbstractObject.getDistance(messif.objects.LocalAbstractObject)
public float[] createMetaDistancesHolder()
MetaObject
,
otherwise null is returned.createMetaDistancesHolder
in class LocalAbstractObject
protected final int fillMetaDistances(MetaObject obj, float distThreshold, float[] metaDistances, java.lang.String[] objectNames, float unknownDistance)
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.obj
- the object to compute distance todistThreshold
- the threshold value on the distancemetaDistances
- the array that is filled with the distances of the respective encapsulated objects, if it is not nullobjectNames
- 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 nullLocalAbstractObject.getDistance(messif.objects.LocalAbstractObject)
protected final int fillMetaDistances(MetaObject obj, float distThreshold, float[] metaDistances)
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.obj
- the object to compute distance todistThreshold
- the threshold value on the distancemetaDistances
- the array that is filled with the distances of the respective encapsulated objects, if it is not nullLocalAbstractObject.getDistance(messif.objects.LocalAbstractObject)
protected static float implementationGetDistance(LocalAbstractObject o1, LocalAbstractObject o2, float distThreshold)
o1
or o2
is null, the
LocalAbstractObject.UNKNOWN_DISTANCE
is returned.o1
- the object to compute distance fromo2
- the object to compute distance todistThreshold
- the threshold value on the distanceLocalAbstractObject.UNKNOWN_DISTANCE
if either o1
or o2
is nullLocalAbstractObject.getDistance
public int getSize()
getSize
in class LocalAbstractObject
public void clearSurplusData()
clearSurplusData
in interface Clearable
clearSurplusData
in class LocalAbstractObject
public java.lang.String toString()
toString
in class AbstractObject