Interface QueryBuilderVisitor<T>
-
- All Superinterfaces:
FlyweightPrototype<QueryBuilderVisitor<T>>
- All Known Implementing Classes:
AbstractQueryBuilderVisitor
,AbstractTermExpander.ExpanderVisitor
,CheckForSelectQueryVisitor
,DocumentIteratorBuilderVisitor
,MultiIndexTermExpander.ExpanderVisitor
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
Modifier and Type Method Description QueryBuilderVisitor<T>
copy()
T[]
newArray(int len)
Builds an array of given length of typeT
.QueryBuilderVisitor<T>
prepare()
Prepares the internal state of this visitor for a(nother) visit.T
visit(False node)
VisitsFalse
.T
visit(Prefix node)
Visits aPrefix
.T
visit(Range node)
Visits aRange
.T
visit(Term node)
Visits aTerm
.T
visit(True node)
VisitsTrue
.T
visitPost(Align node, T[] subNodeResult)
Visits anAlign
node after recursing into the corresponding subtree.T
visitPost(And node, T[] subNodeResult)
Visits anAnd
node after recursing into the corresponding subtree.T
visitPost(Annotation node, T subNodeResult)
Visits aAnnotation
node after recursing into the corresponding subtree.T
visitPost(Consecutive node, T[] subNodeResult)
Visits aConsecutive
node after recursing into the corresponding subtree.T
visitPost(Containment node, T[] subNodeResult)
Visits anContainment
node after recursing into the corresponding subtree.T
visitPost(Difference node, T[] subNodeResult)
Visits aDifference
node after recursing into the corresponding subtree.T
visitPost(Inclusion node, T[] subNodeResult)
Visits anInclusion
node after recursing into the corresponding subtree.T
visitPost(LowPass node, T subNodeResult)
Visits aLowPass
node after recursing into the corresponding subtree.T
visitPost(MultiTerm node, T[] subNodeResult)
Visits aMultiTerm
node after recursing into the corresponding subtree.T
visitPost(Not node, T subNodeResult)
Visits aNot
node after recursing into the corresponding subtree.T
visitPost(OrderedAnd node, T[] subNodeResult)
Visits anOrderedAnd
node after recursing into the corresponding subtree.T
visitPost(Or node, T[] subNodeResult)
Visits anOr
node after recursing into the corresponding subtree.T
visitPost(Remap node, T subNodeResult)
Visits aRemap
node after recursing into the corresponding subtree.T
visitPost(Select node, T subNodeResult)
Visits aSelect
node after recursing into the corresponding subtree.T
visitPost(Weight node, T subNodeResult)
Visits aWeight
node after recursing into the corresponding subtree.boolean
visitPre(Align node)
Visits anAlign
node before recursing into the corresponding subtree.boolean
visitPre(And node)
Visits anAnd
node before recursing into the corresponding subtree.boolean
visitPre(Annotation node)
Visits aAnnotation
node before recursing into the corresponding subtree.boolean
visitPre(Consecutive node)
Visits aConsecutive
node before recursing into the corresponding subtree.boolean
visitPre(Containment node)
Visits anContainment
node before recursing into the corresponding subtree.boolean
visitPre(Difference node)
Visits aDifference
node before recursing into the corresponding subtree.boolean
visitPre(Inclusion node)
Visits anInclusion
node before recursing into the corresponding subtree.boolean
visitPre(LowPass node)
Visits aLowPass
node before recursing into the corresponding subtree.boolean
visitPre(MultiTerm node)
Visits aMultiTerm
node before recursing into the corresponding subtree.boolean
visitPre(Not node)
Visits aNot
node before recursing into the corresponding subtree.boolean
visitPre(Or node)
Visits anOr
node before recursing into the corresponding subtree.boolean
visitPre(OrderedAnd node)
Visits anOrderedAnd
node before recursing into the corresponding subtree.boolean
visitPre(Remap node)
Visits aRemap
node before recursing into the corresponding subtree.boolean
visitPre(Select node)
Visits aSelect
node before recursing into the corresponding subtree.boolean
visitPre(Weight node)
Visits aWeight
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 typeT
.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 typeT
. This method must provide an array of given length that is an acceptable input for allvisitPost()
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 inArray
.- Parameters:
len
- the required array length.- Returns:
- an array of type
T
of lengthlen
.
-
visitPre
boolean visitPre(And node) throws QueryBuilderVisitorException
Visits anAnd
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 anAnd
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, ornull
. - Throws:
QueryBuilderVisitorException
-
visitPre
boolean visitPre(Consecutive node) throws QueryBuilderVisitorException
Visits aConsecutive
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 aConsecutive
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, ornull
. - Throws:
QueryBuilderVisitorException
-
visitPre
boolean visitPre(LowPass node) throws QueryBuilderVisitorException
Visits aLowPass
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 aLowPass
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, ornull
. - Throws:
QueryBuilderVisitorException
-
visitPre
boolean visitPre(Annotation node) throws QueryBuilderVisitorException
Visits aAnnotation
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(Annotation node, T subNodeResult) throws QueryBuilderVisitorException
Visits aAnnotation
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, ornull
. - Throws:
QueryBuilderVisitorException
-
visitPre
boolean visitPre(Not node) throws QueryBuilderVisitorException
Visits aNot
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 aNot
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, ornull
. - Throws:
QueryBuilderVisitorException
-
visitPre
boolean visitPre(Or node) throws QueryBuilderVisitorException
Visits anOr
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 anOr
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, ornull
. - Throws:
QueryBuilderVisitorException
-
visitPre
boolean visitPre(OrderedAnd node) throws QueryBuilderVisitorException
Visits anOrderedAnd
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 anOrderedAnd
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, ornull
. - Throws:
QueryBuilderVisitorException
-
visitPre
boolean visitPre(Align node) throws QueryBuilderVisitorException
Visits anAlign
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 anAlign
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, ornull
. - Throws:
QueryBuilderVisitorException
-
visitPre
boolean visitPre(Difference node) throws QueryBuilderVisitorException
Visits aDifference
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 aDifference
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, ornull
. - Throws:
QueryBuilderVisitorException
-
visitPre
boolean visitPre(Inclusion node) throws QueryBuilderVisitorException
Visits anInclusion
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(Inclusion node, T[] subNodeResult) throws QueryBuilderVisitorException
Visits anInclusion
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, ornull
. - Throws:
QueryBuilderVisitorException
-
visitPre
boolean visitPre(Containment node) throws QueryBuilderVisitorException
Visits anContainment
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(Containment node, T[] subNodeResult) throws QueryBuilderVisitorException
Visits anContainment
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, ornull
. - Throws:
QueryBuilderVisitorException
-
visitPre
boolean visitPre(MultiTerm node) throws QueryBuilderVisitorException
Visits aMultiTerm
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 aMultiTerm
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, ornull
. - Throws:
QueryBuilderVisitorException
-
visitPre
boolean visitPre(Select node) throws QueryBuilderVisitorException
Visits aSelect
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 aSelect
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, ornull
. - Throws:
QueryBuilderVisitorException
-
visitPre
boolean visitPre(Remap node) throws QueryBuilderVisitorException
Visits aRemap
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 aRemap
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, ornull
. - Throws:
QueryBuilderVisitorException
-
visitPre
boolean visitPre(Weight node) throws QueryBuilderVisitorException
Visits aWeight
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 aWeight
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, ornull
. - Throws:
QueryBuilderVisitorException
-
visit
T visit(Term node) throws QueryBuilderVisitorException
Visits aTerm
.- Parameters:
node
- the leaf to be visited.- Returns:
- true if the visit should continue.
- Throws:
QueryBuilderVisitorException
-
visit
T visit(Prefix node) throws QueryBuilderVisitorException
Visits aPrefix
.- 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, ornull
. - Throws:
QueryBuilderVisitorException
-
visit
T visit(Range node) throws QueryBuilderVisitorException
Visits aRange
.- Parameters:
node
- the leaf to be visited.- Returns:
- true if the visit should continue.
- Throws:
QueryBuilderVisitorException
-
visit
T visit(True node) throws QueryBuilderVisitorException
VisitsTrue
.- Parameters:
node
- the leaf to be visited.- Returns:
- true if the visit should continue.
- Throws:
QueryBuilderVisitorException
-
visit
T visit(False node) throws QueryBuilderVisitorException
VisitsFalse
.- Parameters:
node
- the leaf to be visited.- Returns:
- true if the visit should continue.
- Throws:
QueryBuilderVisitorException
-
copy
QueryBuilderVisitor<T> copy()
- Specified by:
copy
in interfaceFlyweightPrototype<T>
-
-