messif.operations
Class QueryOperation<TAnswer>

java.lang.Object
  extended by messif.operations.AbstractOperation
      extended by messif.operations.QueryOperation<TAnswer>
Type Parameters:
TAnswer - the class of objects returned in the query answer
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Clearable
Direct Known Subclasses:
ListingQueryOperation, RankingQueryOperation, SingletonQueryOperation

public abstract class QueryOperation<TAnswer>
extends AbstractOperation

The base class for all query operations. Query operations retrive data from indexing structures according to their specification, but they do not modify the indexed data. Once a query operation is executed on an index structure, its answer is updated.

There are three cathegories of query operations that return different types of answers:

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class messif.operations.AbstractOperation
AbstractOperation.DataEqualOperation, AbstractOperation.OperationConstructor, AbstractOperation.OperationName
 
Field Summary
protected  AnswerType answerType
          Types of objects this query operation will return
 
Fields inherited from class messif.operations.AbstractOperation
errValue, operID, suppData
 
Constructor Summary
protected QueryOperation(AnswerType answerType)
          Creates a new instance of QueryOperation.
 
Method Summary
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.
 void endOperation()
          End operation successfully
abstract  int evaluate(AbstractObjectIterator<? extends LocalAbstractObject> objects)
          Evaluate this query on a given set of objects.
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 AbstractObjects in the answer to this query.
 AnswerType getAnswerType()
          Returns the type of objects this operation stores in its answer.
abstract  void resetAnswer()
          Reset the current query answer.
 boolean wasSuccessful()
          Returns true if this operation has finished successfuly.
 
Methods inherited from class messif.operations.AbstractOperation
appendArguments, clearSurplusData, clone, createOperation, dataEquals, dataEqualsImpl, dataHashCode, endOperation, equals, getAnnotatedConstructor, getAnnotatedConstructor, getArgument, getArgumentCount, getConstructorArgumentDescriptions, getConstructorArgumentDescriptions, getConstructorArguments, getConstructorArguments, getConstructorDescription, getErrorCode, getName, getName, getOperationID, hashCode, isFinished, toString, updateFrom
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

answerType

protected final AnswerType answerType
Types of objects this query operation will return

Constructor Detail

QueryOperation

protected QueryOperation(AnswerType answerType)
Creates a new instance of QueryOperation.

Parameters:
answerType - the type of objects this operation stores in its answer
Method Detail

wasSuccessful

public boolean wasSuccessful()
Returns true if this operation has finished successfuly. Otherwise, false is returned - the operation was either unsuccessful or is has not finished yet.

Specified by:
wasSuccessful in class AbstractOperation
Returns:
true if this operation has finished successfuly

endOperation

public void endOperation()
End operation successfully

Specified by:
endOperation in class AbstractOperation

evaluate

public abstract int evaluate(AbstractObjectIterator<? extends LocalAbstractObject> objects)
Evaluate this query on a given set of objects. The objects found by this evaluation are added to the answer of the particular query.

Parameters:
objects - the collection of objects on which to evaluate this query
Returns:
number of objects satisfying the query

getAnswerType

public AnswerType getAnswerType()
Returns the type of objects this operation stores in its answer.

Returns:
the type of objects this operation stores in its answer

getAnswerClass

public abstract java.lang.Class<? extends TAnswer> getAnswerClass()
Returns the class of objects this operation stores in its answer.

Returns:
the class of objects this operation stores in its answer

getAnswerCount

public abstract int getAnswerCount()
Returns the number of objects in this query answer.

Returns:
the number of objects in this query answer

getAnswer

public abstract java.util.Iterator<TAnswer> getAnswer()
Returns an iterator over all objects in the answer to this query.

Returns:
an iterator over all objects in the answer to this query

getAnswer

public 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. If count is less than or equal to zero, all objects from the answer (except for skip) are returned.

Parameters:
skip - number of answer objects to skip
count - number of answer objects to iterate (maximally, actual number of results can be smaller)
Returns:
an iterator over the objects in the answer to this query

getAnswerObjects

public abstract java.util.Iterator<AbstractObject> getAnswerObjects()
Returns an iterator over all AbstractObjects in the answer to this query. This method unwraps the objects from the results.

Returns:
an iterator over all AbstractObjects in the answer to this query

resetAnswer

public abstract void resetAnswer()
Reset the current query answer. All objects from the answer are deleted, getAnswerCount() will return zero.


appendErrorCode

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.

Overrides:
appendErrorCode in class AbstractOperation
Parameters:
str - the string to add the error code to