no.sesat.search.query.parser.alt
Class AbstractAlternation

java.lang.Object
  extended by no.sesat.search.query.parser.alt.AbstractAlternation
All Implemented Interfaces:
Alternation
Direct Known Subclasses:
FullnameAlternation, RotationAlternation

public abstract class AbstractAlternation
extends Object
implements Alternation

Base abstraction class for any Alternation implementation. Contains helper methods that are typically used within the alternation process. Some of these methods inturn delegate to visitor implementations found under the finder package.

Version:
$Id: AbstractAlternation.java 7225 2009-04-09 00:32:20Z ssmiweve $

Nested Class Summary
 
Nested classes/interfaces inherited from interface no.sesat.search.query.parser.alt.Alternation
Alternation.Context
 
Field Summary
protected  Alternation.Context context
          The context to work within.
 
Constructor Summary
AbstractAlternation(Alternation.Context cxt)
          Creates a new instance of AbstractAlternation
 
Method Summary
protected
<T extends UnaryClause>
T
createOperatorClause(Clause left, Clause right, T replacementFor)
          Create a new operator clause, of type opCls, with the left and right children.
protected  XorClause createXorClause(LinkedList<? extends Clause> alternatives)
          Create XorClauses required to present all the alternatives in the query tree.
protected abstract  XorClause.Hint getAlternationHint()
          What XorClause.Hint is used for newly created XorClause alternations.
protected  Clause leftChild(UnaryClause clause)
          return the left child, left or operation.
protected
<T extends BinaryClause>
T
leftOpChild(T clause)
          will return null instead of a leafClause
protected
<T extends UnaryClause>
T
parent(T root, Clause child)
          return the parent operation clause of the given child.
protected
<T extends UnaryClause>
List<T>
parents(T root, Clause child)
          return all parents operation clauses of the given child.
protected  UnaryClause replaceDescendant(BinaryClause root, BinaryClause newChild, BinaryClause originalChild, BinaryClause originalParent)
          Build new DoubleOperatorClauses from newChild all the way back up to the root.
protected
<T extends UnaryClause>
T
replaceOperatorClause(Clause newChild, Clause originalChild, T originalParent)
          Replace the originalChild that exists under the originalParent will the newChild.
protected  Clause rightChild(BinaryClause clause)
          will return right child, leaf or operation.
protected
<T extends BinaryClause>
T
rightOpChild(T clause)
          will return null instead of a leafClause
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface no.sesat.search.query.parser.alt.Alternation
alternate
 

Field Detail

context

protected final Alternation.Context context
The context to work within.

Constructor Detail

AbstractAlternation

public AbstractAlternation(Alternation.Context cxt)
Creates a new instance of AbstractAlternation

Parameters:
cxt -
Method Detail

leftOpChild

protected <T extends BinaryClause> T leftOpChild(T clause)
will return null instead of a leafClause

Parameters:
clause -
Returns:

leftChild

protected Clause leftChild(UnaryClause clause)
return the left child, left or operation.

Parameters:
clause -
Returns:

rightOpChild

protected <T extends BinaryClause> T rightOpChild(T clause)
will return null instead of a leafClause

Parameters:
clause -
Returns:

rightChild

protected Clause rightChild(BinaryClause clause)
will return right child, leaf or operation.

Parameters:
clause -
Returns:

parent

protected <T extends UnaryClause> T parent(T root,
                                           Clause child)
return the parent operation clause of the given child. And the child must be a descendant of the root. The result will also be assignable from the root argument's class. If there exists multiple parents all of the required class an IllegalStateException is thrown.

Parameters:
child -
root -

parents

protected <T extends UnaryClause> List<T> parents(T root,
                                                  Clause child)
return all parents operation clauses of the given child.

Parameters:
root -
child -
Returns:

replaceDescendant

protected UnaryClause replaceDescendant(BinaryClause root,
                                        BinaryClause newChild,
                                        BinaryClause originalChild,
                                        BinaryClause originalParent)
Build new DoubleOperatorClauses from newChild all the way back up to the root. XXX Only handles single splits, or one layer of variations, denoted by the originalParent argument. This could be solved by using an array, specifying ancestry line, for the argument instead.

If, under root, originalParent cannot be found then root is returned unaltered.

Parameters:
root - the root clause. an altered version of this will be returned.
newChild - the new child.
originalChild - the original child.
originalParent - the original parent of the original child. expected to be found under root.
Returns:
the root clause where the originalChild has been replaced with the newChild.

replaceOperatorClause

protected <T extends UnaryClause> T replaceOperatorClause(Clause newChild,
                                                          Clause originalChild,
                                                          T originalParent)
Replace the originalChild that exists under the originalParent will the newChild.

Parameters:
newChild -
originalChild -
originalParent -
Returns:

createOperatorClause

protected <T extends UnaryClause> T createOperatorClause(Clause left,
                                                         Clause right,
                                                         T replacementFor)
Create a new operator clause, of type opCls, with the left and right children. We must also specify for whom it is to be a replacement for. The replacementFor must be from the original branch.

Parameters:
left -
right -
replacementFor -
Returns:

createXorClause

protected XorClause createXorClause(LinkedList<? extends Clause> alternatives)
Create XorClauses required to present all the alternatives in the query tree. There will be alternatives.size()-1 XorClauses aligned in a right-leaning branch.

Parameters:
alternatives - what will be leaves of the right-leaning XorClause branch returned
Returns:
the right-leaning XorClause branch

getAlternationHint

protected abstract XorClause.Hint getAlternationHint()
What XorClause.Hint is used for newly created XorClause alternations.

Returns:
the XorClause.Hint used during this alternation process.


Copyright © 2005-2009 Schibsted ASA. All Rights Reserved.