org.kahina.core.breakpoint
Class TreeAutomaton

java.lang.Object
  extended by org.kahina.core.breakpoint.TreeAutomaton

public class TreeAutomaton
extends Object

Implements a tree automaton as used for tree pattern matching by Kahina's breakpoint system.

This special kind of bottom-up tree automaton operates on a tree it is monitoring. It does not only annotate a static tree to determine whether it matches the encoded pattern, but is also able to adapt to changes to the tree without recalculating everything, if the component controlling changes in the tree structure (usually a subclass of KahinaTreeBehavior) announces the changes.

A tree automaton is usually compiled from a KahinaBreakpoint, which contains If the associated breakpoint is active, the automaton will dispatch a KahinaTreeMatchEvent to its KahinaController as soon as the encoded pattern is found in the tree it monitors.


Constructor Summary
TreeAutomaton(KahinaBreakpoint bp)
          Class constructor specifying the breakpoint to be associated with the new automaton.
 
Method Summary
 boolean annotate(int nodeID, int stateID)
          Annotates a single node in the tree with some state ID and checks whether this resulted in a change.
 Set<Integer> getAnnotations(int nodeID)
          Retrieves the current annotations for a single tree node.
 Set<Integer> getChildAnnotations(int nodeID)
          Retrieves the current annotations for all the children of a single tree node.
 KahinaController getController()
          Gets the controller this automaton is informing about matches.
 void process(int nodeID)
          Annotates a tree node with all possible labels according to the rules and recursively reannotates parents if it triggers a change in annotation.
 void setConstellationMatch(boolean constellationMatch)
          Determine whether the automaton reports matches directly above new nodes twice.
 void setController(KahinaController ctrl)
          Sets the controller this automaton is to inform about matches.
 void setTree(KahinaTree tree)
          Sets or changes the tree this automaton is monitoring.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TreeAutomaton

public TreeAutomaton(KahinaBreakpoint bp)
Class constructor specifying the breakpoint to be associated with the new automaton. The first thing to be called by a KahinaBreakpoint when compiled.

Parameters:
bp - the breakpoint object to be associated with the new automaton
Method Detail

setTree

public void setTree(KahinaTree tree)
Sets or changes the tree this automaton is monitoring. The automaton will silently recompute its annotations in bottom-up manner.

Parameters:
tree - the tree model to be monitored by this automaton

setConstellationMatch

public void setConstellationMatch(boolean constellationMatch)
Determine whether the automaton reports matches directly above new nodes twice. Default value: false, which is suitable in most contexts.

Parameters:
constellationMatch - true for extra reports, false to suppress them

getController

public KahinaController getController()
Gets the controller this automaton is informing about matches.

Returns:
the controller this automaton is informing about matches

setController

public void setController(KahinaController ctrl)
Sets the controller this automaton is to inform about matches. Default is null, a controller must be determined for the breakpoint system to work.

Parameters:
ctrl - the controller this automaton is to inform about matches

process

public void process(int nodeID)
Annotates a tree node with all possible labels according to the rules and recursively reannotates parents if it triggers a change in annotation.

Parameters:
nodeID - the node to be (re)annotated by the automaton

annotate

public boolean annotate(int nodeID,
                        int stateID)
Annotates a single node in the tree with some state ID and checks whether this resulted in a change.

Parameters:
nodeID - the node to be annotated
stateID - the state ID the node is to be annotated with
Returns:
false if this annotation existed before, true if it was new

getAnnotations

public Set<Integer> getAnnotations(int nodeID)
Retrieves the current annotations for a single tree node.

Parameters:
nodeID - addresses the node whose annotations we want to get
Returns:
a set of stateIDs representing the annotations for the node

getChildAnnotations

public Set<Integer> getChildAnnotations(int nodeID)
Retrieves the current annotations for all the children of a single tree node.

Parameters:
nodeID - addresses the node whose children's annotations we want to get
Returns:
a set of stateIDs containing all the annotations for the children of the node

toString

public String toString()
Overrides:
toString in class Object