it.unimi.di.mg4j.search.visitor
Class AbstractDocumentIteratorVisitor

java.lang.Object
  extended by it.unimi.di.mg4j.search.visitor.AbstractDocumentIteratorVisitor
All Implemented Interfaces:
DocumentIteratorVisitor<Boolean>
Direct Known Subclasses:
BM25FScorer.Visitor, CounterCollectionVisitor, CounterSetupVisitor, TermCollectionVisitor, TrueTermsCollectionVisitor

public abstract class AbstractDocumentIteratorVisitor
extends Object
implements DocumentIteratorVisitor<Boolean>

An abstract implementation of a DocumentIteratorVisitor without return values.

This implementation is hardwired to Boolean, returns always true on visitPre(DocumentIterator), returns Boolean.TRUE on all internal nodes if no subnode returns null, returns Boolean.TRUE on true/false document iterators, returns null on calls to newArray(int), and delegates visit(MultiTermIndexIterator) to DocumentIteratorVisitor.visit(IndexIterator).


Constructor Summary
AbstractDocumentIteratorVisitor()
           
 
Method Summary
 Boolean[] newArray(int len)
          Builds an array of given length of type T.
 AbstractDocumentIteratorVisitor prepare()
          Prepares the internal state of this visitor for a(nother) visit.
 Boolean visit(FalseDocumentIterator falseDocumentIterator)
          Visits a FalseDocumentIterator leaf.
 Boolean visit(MultiTermIndexIterator indexIterator)
          Visits a MultiTermIndexIterator leaf.
 Boolean visit(TrueDocumentIterator trueDocumentIterator)
          Visits a TrueDocumentIterator leaf.
 Boolean visitPost(DocumentIterator documentIterator, Boolean[] subNodeResult)
          Visits an internal node after recursing into the corresponding subtree.
 boolean visitPre(DocumentIterator documentIterator)
          Visits an internal node before recursing into the corresponding subtree.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface it.unimi.di.mg4j.search.visitor.DocumentIteratorVisitor
visit
 

Constructor Detail

AbstractDocumentIteratorVisitor

public AbstractDocumentIteratorVisitor()
Method Detail

prepare

public AbstractDocumentIteratorVisitor prepare()
Description copied from interface: DocumentIteratorVisitor
Prepares the internal state of this visitor for a(nother) visit.

By specification, it must be safe to call this method any number of times.

Specified by:
prepare in interface DocumentIteratorVisitor<Boolean>
Returns:
this visitor.

visitPre

public boolean visitPre(DocumentIterator documentIterator)
Description copied from interface: DocumentIteratorVisitor
Visits an internal node before recursing into the corresponding subtree.

Specified by:
visitPre in interface DocumentIteratorVisitor<Boolean>
Parameters:
documentIterator - the internal node to be visited.
Returns:
true if the visit should continue.

newArray

public Boolean[] newArray(int len)
Description copied from interface: DocumentIteratorVisitor
Builds an array of given length of type T.

Because of erasure, generic classes in Java cannot allocate arrays of generic types. This impossibility can be a problem if for some reason the visitPost() methods expect an actual array of type T. This method must provide an array of given length that is an acceptable input for all visitPost() methods.

Note that by declaring an implementing class of this interface that has a sole constructor accepting an argument of type Class<T>, you will force the user to provide the class of the generic type, opening the way for the reflective methods in Array.

Specified by:
newArray in interface DocumentIteratorVisitor<Boolean>
Parameters:
len - the required array length.
Returns:
an array of type T of length len, or null if this document iterator visitor does not return values.

visitPost

public Boolean visitPost(DocumentIterator documentIterator,
                         Boolean[] subNodeResult)
Description copied from interface: DocumentIteratorVisitor
Visits an internal node after recursing into the corresponding subtree.

Specified by:
visitPost in interface DocumentIteratorVisitor<Boolean>
Parameters:
documentIterator - the internal node to be visited.
subNodeResult - the array of results returned by subnodes.
Returns:
an appropriate return value (usually, the object built using the elements in subNode) if the visit should continue, or null.

visit

public Boolean visit(MultiTermIndexIterator indexIterator)
              throws IOException
Description copied from interface: DocumentIteratorVisitor
Visits a MultiTermIndexIterator leaf.

Specified by:
visit in interface DocumentIteratorVisitor<Boolean>
Parameters:
indexIterator - the leaf to be visited.
Returns:
an appropriate return value if the visit should continue, or null.
Throws:
IOException

visit

public Boolean visit(TrueDocumentIterator trueDocumentIterator)
Description copied from interface: DocumentIteratorVisitor
Visits a TrueDocumentIterator leaf.

Specified by:
visit in interface DocumentIteratorVisitor<Boolean>
Parameters:
trueDocumentIterator - the leaf to be visited.
Returns:
an appropriate return value if the visit should continue, or null.

visit

public Boolean visit(FalseDocumentIterator falseDocumentIterator)
Description copied from interface: DocumentIteratorVisitor
Visits a FalseDocumentIterator leaf.

Specified by:
visit in interface DocumentIteratorVisitor<Boolean>
Parameters:
falseDocumentIterator - the leaf to be visited.
Returns:
an appropriate return value if the visit should continue, or null.