it.unimi.di.mg4j.query.nodes
Interface QueryBuilderVisitor<T>

All Superinterfaces:
FlyweightPrototype<QueryBuilderVisitor<T>>
All Known Implementing Classes:
AbstractQueryBuilderVisitor, AbstractTermExpander.ExpanderVisitor, CheckForSelectQueryVisitor, DocumentIteratorBuilderVisitor, MultiIndexTermExpander.ExpanderVisitor, PrecomputeIndex.ReplacingDocumentIteratorBuilderVisitor

public interface QueryBuilderVisitor<T>
extends FlyweightPrototype<QueryBuilderVisitor<T>>

A visitor for a composite query.

Instances of this class are builder visitors, that is, visitors that during their visit build a complex object (of course, it is possible not building an object at all).

Implementations of this interface must be reusable. The user must invoke prepare() before a visit so that the internal state of the visitor can be suitably set up.

The most typical usage of this class is that of building document iterators following the structure of the query. By writing different builder visitors for different families of document iterators, parsing and document-iterator construction are completely decoupled.

Note that this visitor interface and that defined in DocumentIteratorVisitor are based on different principles: see the comments therein.

Author:
Sebastiano Vigna

Method Summary
 QueryBuilderVisitor<T> copy()
           
 T[] newArray(int len)
          Builds an array of given length of type T.
 QueryBuilderVisitor<T> prepare()
          Prepares the internal state of this visitor for a(nother) visit.
 T visit(False node)
          Visits False.
 T visit(Prefix node)
          Visits a Prefix.
 T visit(Range node)
          Visits a Range.
 T visit(Term node)
          Visits a Term.
 T visit(True node)
          Visits True.
 T visitPost(Align node, T[] subNodeResult)
          Visits an Align node after recursing into the corresponding subtree.
 T visitPost(And node, T[] subNodeResult)
          Visits an And node after recursing into the corresponding subtree.
 T visitPost(Consecutive node, T[] subNodeResult)
          Visits a Consecutive node after recursing into the corresponding subtree.
 T visitPost(Difference node, T[] subNodeResult)
          Visits an Difference node after recursing into the corresponding subtree.
 T visitPost(LowPass node, T subNodeResult)
          Visits a LowPass node after recursing into the corresponding subtree.
 T visitPost(MultiTerm node, T[] subNodeResult)
          Visits a MultiTerm node after recursing into the corresponding subtree.
 T visitPost(Not node, T subNodeResult)
          Visits a Not node after recursing into the corresponding subtree.
 T visitPost(OrderedAnd node, T[] subNodeResult)
          Visits an OrderedAnd node after recursing into the corresponding subtree.
 T visitPost(Or node, T[] subNodeResult)
          Visits an Or node after recursing into the corresponding subtree.
 T visitPost(Remap node, T subNodeResult)
          Visits a Remap node after recursing into the corresponding subtree.
 T visitPost(Select node, T subNodeResult)
          Visits a Select node after recursing into the corresponding subtree.
 T visitPost(Weight node, T subNodeResult)
          Visits a Weight node after recursing into the corresponding subtree.
 boolean visitPre(Align node)
          Visits an Align node before recursing into the corresponding subtree.
 boolean visitPre(And node)
          Visits an And node before recursing into the corresponding subtree.
 boolean visitPre(Consecutive node)
          Visits a Consecutive node before recursing into the corresponding subtree.
 boolean visitPre(Difference node)
          Visits an Difference node before recursing into the corresponding subtree.
 boolean visitPre(LowPass node)
          Visits a LowPass node before recursing into the corresponding subtree.
 boolean visitPre(MultiTerm node)
          Visits a MultiTerm node before recursing into the corresponding subtree.
 boolean visitPre(Not node)
          Visits a Not node before recursing into the corresponding subtree.
 boolean visitPre(Or node)
          Visits an Or node before recursing into the corresponding subtree.
 boolean visitPre(OrderedAnd node)
          Visits an OrderedAnd node before recursing into the corresponding subtree.
 boolean visitPre(Remap node)
          Visits a Remap node before recursing into the corresponding subtree.
 boolean visitPre(Select node)
          Visits a Select node before recursing into the corresponding subtree.
 boolean visitPre(Weight node)
          Visits a Weight node before recursing into the corresponding subtree.
 

Method Detail

prepare

QueryBuilderVisitor<T> prepare()
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.

Returns:
this visitor.

newArray

T[] newArray(int len)
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.

Parameters:
len - the required array length.
Returns:
an array of type T of length len.

visitPre

boolean visitPre(And node)
                 throws QueryBuilderVisitorException
Visits an And node before recursing into the corresponding subtree.

Parameters:
node - the node to be visited.
Returns:
true if the visit should continue.
Throws:
QueryBuilderVisitorException

visitPost

T visitPost(And node,
            T[] subNodeResult)
            throws QueryBuilderVisitorException
Visits an And node after recursing into the corresponding subtree.

Parameters:
node - 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 subNodeResult) if the visit should continue, or null.
Throws:
QueryBuilderVisitorException

visitPre

boolean visitPre(Consecutive node)
                 throws QueryBuilderVisitorException
Visits a Consecutive node before recursing into the corresponding subtree.

Parameters:
node - the node to be visited.
Returns:
true if the visit should continue.
Throws:
QueryBuilderVisitorException

visitPost

T visitPost(Consecutive node,
            T[] subNodeResult)
            throws QueryBuilderVisitorException
Visits a Consecutive node after recursing into the corresponding subtree.

Parameters:
node - 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 subNodeResult) if the visit should continue, or null.
Throws:
QueryBuilderVisitorException

visitPre

boolean visitPre(LowPass node)
                 throws QueryBuilderVisitorException
Visits a LowPass node before recursing into the corresponding subtree.

Parameters:
node - the node to be visited.
Returns:
true if the visit should continue.
Throws:
QueryBuilderVisitorException

visitPost

T visitPost(LowPass node,
            T subNodeResult)
            throws QueryBuilderVisitorException
Visits a LowPass node after recursing into the corresponding subtree.

Parameters:
node - the internal node to be visited.
subNodeResult - the of result returned by the sole subnode.
Returns:
an appropriate return value (usually, the object built using subNodeResult) if the visit should continue, or null.
Throws:
QueryBuilderVisitorException

visitPre

boolean visitPre(Not node)
                 throws QueryBuilderVisitorException
Visits a Not node before recursing into the corresponding subtree.

Parameters:
node - the node to be visited.
Returns:
true if the visit should continue.
Throws:
QueryBuilderVisitorException

visitPost

T visitPost(Not node,
            T subNodeResult)
            throws QueryBuilderVisitorException
Visits a Not node after recursing into the corresponding subtree.

Parameters:
node - the internal node to be visited.
subNodeResult - the of result returned by the sole subnode.
Returns:
an appropriate return value (usually, the object built using subNodeResult) if the visit should continue, or null.
Throws:
QueryBuilderVisitorException

visitPre

boolean visitPre(Or node)
                 throws QueryBuilderVisitorException
Visits an Or node before recursing into the corresponding subtree.

Parameters:
node - the node to be visited.
Returns:
true if the visit should continue.
Throws:
QueryBuilderVisitorException

visitPost

T visitPost(Or node,
            T[] subNodeResult)
            throws QueryBuilderVisitorException
Visits an Or node after recursing into the corresponding subtree.

Parameters:
node - the internal node to be visited.
Returns:
an appropriate return value (usually, the object built using the elements in subNodeResult) if the visit should continue, or null.
Throws:
QueryBuilderVisitorException

visitPre

boolean visitPre(OrderedAnd node)
                 throws QueryBuilderVisitorException
Visits an OrderedAnd node before recursing into the corresponding subtree.

Parameters:
node - the node to be visited.
Returns:
true if the visit should continue.
Throws:
QueryBuilderVisitorException

visitPost

T visitPost(OrderedAnd node,
            T[] subNodeResult)
            throws QueryBuilderVisitorException
Visits an OrderedAnd node after recursing into the corresponding subtree.

Parameters:
node - 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 subNodeResult) if the visit should continue, or null.
Throws:
QueryBuilderVisitorException

visitPre

boolean visitPre(Align node)
                 throws QueryBuilderVisitorException
Visits an Align node before recursing into the corresponding subtree.

Parameters:
node - the node to be visited.
Returns:
true if the visit should continue.
Throws:
QueryBuilderVisitorException

visitPost

T visitPost(Align node,
            T[] subNodeResult)
            throws QueryBuilderVisitorException
Visits an Align node after recursing into the corresponding subtree.

Parameters:
node - 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 subNodeResult) if the visit should continue, or null.
Throws:
QueryBuilderVisitorException

visitPre

boolean visitPre(Difference node)
                 throws QueryBuilderVisitorException
Visits an Difference node before recursing into the corresponding subtree.

Parameters:
node - the node to be visited.
Returns:
true if the visit should continue.
Throws:
QueryBuilderVisitorException

visitPost

T visitPost(Difference node,
            T[] subNodeResult)
            throws QueryBuilderVisitorException
Visits an Difference node after recursing into the corresponding subtree.

Parameters:
node - 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 subNodeResult) if the visit should continue, or null.
Throws:
QueryBuilderVisitorException

visitPre

boolean visitPre(MultiTerm node)
                 throws QueryBuilderVisitorException
Visits a MultiTerm node before recursing into the corresponding subtree.

Parameters:
node - the node to be visited.
Returns:
true if the visit should continue.
Throws:
QueryBuilderVisitorException

visitPost

T visitPost(MultiTerm node,
            T[] subNodeResult)
            throws QueryBuilderVisitorException
Visits a MultiTerm node after recursing into the corresponding subtree.

Parameters:
node - the internal node to be visited.
subNodeResult - the of result returned by the sole subnode.
Returns:
an appropriate return value (usually, the object built using subNodeResult) if the visit should continue, or null.
Throws:
QueryBuilderVisitorException

visitPre

boolean visitPre(Select node)
                 throws QueryBuilderVisitorException
Visits a Select node before recursing into the corresponding subtree.

Parameters:
node - the node to be visited.
Returns:
true if the visit should continue.
Throws:
QueryBuilderVisitorException

visitPost

T visitPost(Select node,
            T subNodeResult)
            throws QueryBuilderVisitorException
Visits a Select node after recursing into the corresponding subtree.

Parameters:
node - the internal node to be visited.
subNodeResult - the of result returned by the sole subnode.
Returns:
an appropriate return value (usually, the object built using subNodeResult) if the visit should continue, or null.
Throws:
QueryBuilderVisitorException

visitPre

boolean visitPre(Remap node)
                 throws QueryBuilderVisitorException
Visits a Remap node before recursing into the corresponding subtree.

Parameters:
node - the node to be visited.
Returns:
true if the visit should continue.
Throws:
QueryBuilderVisitorException

visitPost

T visitPost(Remap node,
            T subNodeResult)
            throws QueryBuilderVisitorException
Visits a Remap node after recursing into the corresponding subtree.

Parameters:
node - the internal node to be visited.
subNodeResult - the of result returned by the sole subnode.
Returns:
an appropriate return value (usually, the object built using subNodeResult) if the visit should continue, or null.
Throws:
QueryBuilderVisitorException

visitPre

boolean visitPre(Weight node)
                 throws QueryBuilderVisitorException
Visits a Weight node before recursing into the corresponding subtree.

Parameters:
node - the node to be visited.
Returns:
true if the visit should continue.
Throws:
QueryBuilderVisitorException

visitPost

T visitPost(Weight node,
            T subNodeResult)
            throws QueryBuilderVisitorException
Visits a Weight node after recursing into the corresponding subtree.

Parameters:
node - the internal node to be visited.
subNodeResult - the of result returned by the sole subnode.
Returns:
an appropriate return value (usually, the object built using subNodeResult) if the visit should continue, or null.
Throws:
QueryBuilderVisitorException

visit

T visit(Term node)
        throws QueryBuilderVisitorException
Visits a Term.

Parameters:
node - the leaf to be visited.
Returns:
true if the visit should continue.
Throws:
QueryBuilderVisitorException

visit

T visit(Prefix node)
        throws QueryBuilderVisitorException
Visits a Prefix.

Parameters:
node - the leaf to be visited.
Returns:
an appropriate return value (usually, the object built using the elements in subNodeResult) if the visit should continue, or null.
Throws:
QueryBuilderVisitorException

visit

T visit(Range node)
        throws QueryBuilderVisitorException
Visits a Range.

Parameters:
node - the leaf to be visited.
Returns:
true if the visit should continue.
Throws:
QueryBuilderVisitorException

visit

T visit(True node)
        throws QueryBuilderVisitorException
Visits True.

Parameters:
node - the leaf to be visited.
Returns:
true if the visit should continue.
Throws:
QueryBuilderVisitorException

visit

T visit(False node)
        throws QueryBuilderVisitorException
Visits False.

Parameters:
node - the leaf to be visited.
Returns:
true if the visit should continue.
Throws:
QueryBuilderVisitorException

copy

QueryBuilderVisitor<T> copy()
Specified by:
copy in interface FlyweightPrototype<QueryBuilderVisitor<T>>