TAnswer
- the class of objects returned in the query answerpublic abstract class QueryOperation<TAnswer> extends AbstractOperation implements java.lang.Iterable<TAnswer>
There are three categories of query operations that return different types of answers:
SingletonQueryOperation
- returns a single AbstractObject
ListingQueryOperation
- returns a collection of AbstractObject
RankingQueryOperation
- returns a distance-ranked collection of AbstractObject
Modifier and Type | Class and Description |
---|---|
static class |
QueryOperation.DataEqualOperation
A wrapper class that allows to hash/equal abstract objects
using their data and not ID.
|
AbstractOperation.OperationConstructor, AbstractOperation.OperationName
suppData, uuidOperationComparator
Modifier | Constructor and Description |
---|---|
protected |
QueryOperation(AnswerType answerType)
Creates a new instance of QueryOperation.
|
Modifier and Type | Method and Description |
---|---|
protected void |
appendErrorCode(java.lang.StringBuilder str)
Appends the error code of this query to the specified string along with
the information about the number of objects in the current answer.
|
QueryOperation<TAnswer> |
clone()
Create a duplicate of this operation.
|
QueryOperation<TAnswer> |
clone(boolean preserveAnswer)
Create a duplicate of this operation.
|
boolean |
dataEquals(QueryOperation operation)
Indicates whether some other operation has the same data as this one.
|
protected abstract boolean |
dataEqualsImpl(QueryOperation operation)
Indicates whether some other operation has the same data as this one.
|
abstract int |
dataHashCode()
Returns a hash code value for the data of this operation.
|
void |
endOperation()
End operation successfully
|
abstract int |
evaluate(AbstractObjectIterator<? extends LocalAbstractObject> objects)
Evaluate this query on a given set of objects.
|
java.util.Collection<java.util.Iterator<? extends TAnswer>> |
getAllSubAnswers()
Returns a collection of iterators over all objects in all answer sub-collections.
|
abstract java.util.Iterator<TAnswer> |
getAnswer()
Returns an iterator over all objects in the answer to this query.
|
abstract java.util.Iterator<TAnswer> |
getAnswer(int skip,
int count)
Returns an iterator over all objects in the answer skipping the first
skip items and returning only count elements. |
abstract java.lang.Class<? extends TAnswer> |
getAnswerClass()
Returns the class of objects this operation stores in its answer.
|
abstract int |
getAnswerCount()
Returns the number of objects in this query answer.
|
abstract java.util.Iterator<AbstractObject> |
getAnswerObjects()
Returns an iterator over all
AbstractObject s in the answer to this query. |
AnswerType |
getAnswerType()
Returns the type of objects this operation stores in its answer.
|
static <T> java.util.Iterator<? extends T> |
getQueryAnswer(AbstractObjectIterator<? extends LocalAbstractObject> objects,
java.lang.Class<? extends QueryOperation<? extends T>> operationClass,
java.lang.Object... arguments)
Execute query operation on the given objects iterator and return the answer.
|
abstract java.util.Iterator<? extends TAnswer> |
getSubAnswer(int index)
Returns an iterator over all objects in the answer sub-collection with the given index.
|
abstract java.util.Iterator<? extends TAnswer> |
getSubAnswer(java.lang.Object key)
Returns an iterator over all objects in the answer sub-collection with the given key.
|
abstract int |
getSubAnswerCount()
Returns the number of answer sub-collections.
|
java.util.Iterator<TAnswer> |
iterator()
Returns an iterator over all objects in the answer to this query.
|
abstract void |
resetAnswer()
Reset the current query answer.
|
void |
setAnswerType(AnswerType answerType)
Set the type of objects this operation stores in its answer.
|
boolean |
wasSuccessful()
Returns true if this operation has finished successfuly.
|
appendArguments, clearSurplusData, containsParameter, createOperation, endOperation, equals, getAnnotatedConstructor, getAnnotatedConstructor, getArgument, getArgumentCount, getArgumentString, getConstructorArgumentDescriptions, getConstructorArgumentDescriptions, getConstructorArguments, getConstructorArguments, getConstructorDescription, getErrorCode, getName, getName, getOperationID, getParameter, getParameter, getParameter, getParameterCount, getParameterMap, getParameterNames, getRequiredParameter, getRequiredParameter, hashCode, isErrorCode, isFinished, removeParameter, setParameter, toString, updateFrom
protected QueryOperation(AnswerType answerType)
answerType
- the type of objects this operation stores in its answerpublic boolean wasSuccessful()
AbstractOperation
wasSuccessful
in class AbstractOperation
public void endOperation()
endOperation
in class AbstractOperation
public abstract int evaluate(AbstractObjectIterator<? extends LocalAbstractObject> objects)
objects
- the collection of objects on which to evaluate this querypublic static <T> java.util.Iterator<? extends T> getQueryAnswer(AbstractObjectIterator<? extends LocalAbstractObject> objects, java.lang.Class<? extends QueryOperation<? extends T>> operationClass, java.lang.Object... arguments) throws java.lang.IllegalArgumentException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException
AbstractOperation.createOperation(java.lang.Class, java.lang.Object[])
,
evaluate(messif.objects.util.AbstractObjectIterator<? extends messif.objects.LocalAbstractObject>)
and getAnswer()
.T
- the type of query operation answerobjects
- the collection of objects on which to evaluate this queryoperationClass
- the class of the operation to execute on this algorithmarguments
- the arguments for the operation constructorjava.lang.IllegalArgumentException
- if the argument count or their types don't match the specified operation class constructorjava.lang.reflect.InvocationTargetException
- if the operation constructor has thrown an exceptionjava.lang.NoSuchMethodException
- if the operation is unknown or unsupported by this algorithmpublic final QueryOperation<TAnswer> clone() throws java.lang.CloneNotSupportedException
clone
in class AbstractOperation
java.lang.CloneNotSupportedException
- if the operation instance cannot be clonedpublic QueryOperation<TAnswer> clone(boolean preserveAnswer) throws java.lang.CloneNotSupportedException
preserveAnswer
is true the answer is
not cloned but both this and the cloned operation share the same answer collection.preserveAnswer
- flag whether to clone the answer (false) or preserve
the same answer collection (true) in the cloned operationjava.lang.CloneNotSupportedException
- if the operation instance cannot be clonedpublic AnswerType getAnswerType()
public void setAnswerType(AnswerType answerType)
answerType
- the type of objects this operation stores in its answerpublic abstract java.lang.Class<? extends TAnswer> getAnswerClass()
public abstract int getAnswerCount()
public abstract java.util.Iterator<TAnswer> getAnswer()
public final java.util.Iterator<TAnswer> iterator()
Iterable
interface
by calling the getAnswer()
method.iterator
in interface java.lang.Iterable<TAnswer>
public abstract java.util.Iterator<TAnswer> getAnswer(int skip, int count)
skip
items and returning only count
elements. If count
is less than or equal to zero, all objects from the answer (except for
skip
) are returned.skip
- number of answer objects to skipcount
- number of answer objects to iterate (maximally, actual number of results can be smaller)public abstract java.util.Iterator<AbstractObject> getAnswerObjects()
AbstractObject
s in the answer to this query.
This method unwraps the objects from the results.AbstractObject
s in the answer to this querypublic abstract void resetAnswer()
getAnswerCount()
will return zero.public abstract int getSubAnswerCount()
public abstract java.util.Iterator<? extends TAnswer> getSubAnswer(int index) throws java.lang.IndexOutOfBoundsException
index
- the index of the answer sub-collection to returnjava.lang.IndexOutOfBoundsException
- if the given index is negative or
greater or equal to getSubAnswerCount()
public abstract java.util.Iterator<? extends TAnswer> getSubAnswer(java.lang.Object key)
key
- the key of the answer sub-collection to returnpublic java.util.Collection<java.util.Iterator<? extends TAnswer>> getAllSubAnswers()
public final boolean dataEquals(QueryOperation operation)
operation
- the reference object with which to compare.true
if this object has the same data as the obj
argument; false
otherwise.protected abstract boolean dataEqualsImpl(QueryOperation operation)
operation
- the reference object with which to compare.true
if this object has the same data as the obj
argument; false
otherwise.public abstract int dataHashCode()
protected void appendErrorCode(java.lang.StringBuilder str)
appendErrorCode
in class AbstractOperation
str
- the string to add the error code to