org.imemex.logicalplan.treewalkers
Class AbstractTreeWalker

java.lang.Object
  extended by org.imemex.logicalplan.treewalkers.AbstractTreeWalker
All Implemented Interfaces:
LogicalTreeWalker
Direct Known Subclasses:
AbstractRewriteRule, CanonicalOrder, ContextTransformer, DataSourcePluginAnalyzer, DefaultSemanticITrailHandler, iTrailDictionaryBox, LogicalNodeIdentifier, LogNodeSimplePrinter, LogNodeXMLPrinter, LogTreeAnnotate, SnapshotSemanticITrailMatcher, TestTreeWalker, WarehouseAnalyzer

public abstract class AbstractTreeWalker
extends java.lang.Object
implements LogicalTreeWalker

Version:
1.0
Author:
ogirard

Constructor Summary
AbstractTreeWalker(LogicalNode pattern)
          instantiate tree walker for pattern
AbstractTreeWalker(java.lang.String patternString)
          instantiate tree walker for pattern string
AbstractTreeWalker(java.lang.String[] patternStrings)
          instantiate tree walker for pattern strings
 
Method Summary
static
<T extends AbstractTreeWalker>
LogicalNode
applyRules(java.util.List<T> rules, LogicalNode node)
          Try to rewrite given logical node using the given rules.
 boolean defaultMatch(LogicalNode node)
          call this method if you want to use the default pattern matching
one of the indicated pattern has to hold only (OR).
 LogicalNode doAfterEnd(LogicalNode node)
          This method is executed after the tree has been traversed
 LogicalNode doBeforeStart(LogicalNode node)
          This method is executed before the tree is traversed.
 java.util.Iterator<LogicalNode> getMatches(LogicalNode lognode)
          gets iterator of all matching nodes
 LogicalNode[] getPatterns()
          gets pattern
 boolean hasMatch(LogicalNode node)
          traverses tree recursively and checks if match present
 LogicalNode processTree(LogicalNode lognode)
          processes logical tree and rewrites matching nodes
NO recursive application of action.
 LogicalNode processTree(LogicalNode lognode, boolean rec)
          processes logical tree and rewrites matching nodes
 boolean wasChanged()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractTreeWalker

public AbstractTreeWalker(LogicalNode pattern)
instantiate tree walker for pattern

Parameters:
pattern -

AbstractTreeWalker

public AbstractTreeWalker(java.lang.String patternString)
instantiate tree walker for pattern string

Parameters:
patternString -
See Also:
LogicalPattern

AbstractTreeWalker

public AbstractTreeWalker(java.lang.String[] patternStrings)
instantiate tree walker for pattern strings

Parameters:
pattern -
See Also:
LogicalPattern
Method Detail

defaultMatch

public boolean defaultMatch(LogicalNode node)
call this method if you want to use the default pattern matching
one of the indicated pattern has to hold only (OR).

Parameters:
node - input node
Returns:
true if node matches pattern, false otherwise

doBeforeStart

public LogicalNode doBeforeStart(LogicalNode node)
Description copied from interface: LogicalTreeWalker
This method is executed before the tree is traversed.

Specified by:
doBeforeStart in interface LogicalTreeWalker
Parameters:
node - tree root before execution
Returns:

doAfterEnd

public LogicalNode doAfterEnd(LogicalNode node)
Description copied from interface: LogicalTreeWalker
This method is executed after the tree has been traversed

Specified by:
doAfterEnd in interface LogicalTreeWalker
Parameters:
node - tree root after execution
Returns:

hasMatch

public boolean hasMatch(LogicalNode node)
Description copied from interface: LogicalTreeWalker
traverses tree recursively and checks if match present

Specified by:
hasMatch in interface LogicalTreeWalker

processTree

public LogicalNode processTree(LogicalNode lognode,
                               boolean rec)
Description copied from interface: LogicalTreeWalker
processes logical tree and rewrites matching nodes

Specified by:
processTree in interface LogicalTreeWalker
Parameters:
lognode - logical tree to be processed
rec - true if recursion is enabled (meaning: inserted parts may be replaced again)
false if only matches in the original tree should be considered
Returns:
rewritten tree

processTree

public LogicalNode processTree(LogicalNode lognode)
Description copied from interface: LogicalTreeWalker
processes logical tree and rewrites matching nodes
NO recursive application of action.

Specified by:
processTree in interface LogicalTreeWalker
Parameters:
lognode - logical tree to be processed
Returns:
rewritten tree

getPatterns

public LogicalNode[] getPatterns()
Description copied from interface: LogicalTreeWalker
gets pattern

Specified by:
getPatterns in interface LogicalTreeWalker
Returns:

getMatches

public java.util.Iterator<LogicalNode> getMatches(LogicalNode lognode)
Description copied from interface: LogicalTreeWalker
gets iterator of all matching nodes

Specified by:
getMatches in interface LogicalTreeWalker
Returns:

wasChanged

public boolean wasChanged()

applyRules

public static <T extends AbstractTreeWalker> LogicalNode applyRules(java.util.List<T> rules,
                                                                    LogicalNode node)
Try to rewrite given logical node using the given rules. If node could be rewritten, a rewritten copy will be returned, otherwise the original node is returned.

Parameters:
rules - rules to try.
node - logical node who should be rewritten.