laser.regularlanguage.regularexpression
Class TreeNode<L extends LabelInterface>

java.lang.Object
  extended by laser.regularlanguage.regularexpression.TreeNode<L>
Type Parameters:
L - The type of Label associated with this regular expression
All Implemented Interfaces:
java.io.Serializable, REConstants
Direct Known Subclasses:
BinaryTreeNode, ClassSetNode, DotNode, EmptyNode, EpsilonNode, LabelNode, MarkerNode, NotClassSetNode, UnaryTreeNode

public abstract class TreeNode<L extends LabelInterface>
extends java.lang.Object
implements REConstants, java.io.Serializable

TreeNode is an abstract class that all classes used in building a Regular Expression inherit from.

NOTE: The TreeNode implements the visitor pattern. It is the element type.

REFERENCES:

Gamma, Erich, Helm, Richard, Johnson, Ralph, and Vlissides, John. "Design Patterns: Elements of Reusable Object-Oriented Software". Reading, Massachusetts: Addison-Wesley Longman, Inc, 1995.

Author:
Jamieson M. Cobleigh (laser-software@cs.umass.edu)
See Also:
Serialized Form

Field Summary
static java.lang.String LS
          The line separator for this platform
 
Fields inherited from interface laser.regularlanguage.regularexpression.REConstants
CHOICE, COMMA, COMMENT_PREFIX, CONCATENATION, DOT, EMPTY, EPSILON, EXPONENT, KLEENE_PLUS, KLEENE_STAR, LBRACE, LBRACKET, LPAREN, NOT, OPTION, RANGE, RBRACE, RBRACKET, RPAREN
 
Constructor Summary
protected TreeNode()
          Constructs a TreeNode with the default set of values
 
Method Summary
abstract  void apply(REVisitor<L> visitor, java.lang.Object context)
          Applies the given REVisitor to this TreeNode.
abstract  TreeNode<L> copyTree()
          Returns a copy of the Tree rooted at this node.
 boolean equalsTree(TreeNode<L> node2)
          Returns true if the tree rooted at this node and the tree rooted at the given node are equal and false otherwise.
abstract  java.util.List<TreeNode<L>> getChildren()
          Returns a List of the children of this TreeNode.
abstract  java.util.Set<L> getLabelsUsed()
          Returns a Set of the labels used by this TreeNode.
abstract  java.lang.String print(java.lang.String prefix)
          Prints the Tree rooted at this node.
 java.lang.String toString()
          Returns a string representation of this Object.
static void trace(java.lang.Object what)
          If the boolean variable trace is true, trace() prints out the object that was passed to it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LS

public static final java.lang.String LS
The line separator for this platform

Constructor Detail

TreeNode

protected TreeNode()
Constructs a TreeNode with the default set of values

Method Detail

getChildren

public abstract java.util.List<TreeNode<L>> getChildren()
Returns a List of the children of this TreeNode.

Returns:
A List of the children of this TreeNode

getLabelsUsed

public abstract java.util.Set<L> getLabelsUsed()
Returns a Set of the labels used by this TreeNode.

Returns:
A Set of the labels used by this TreeNode

apply

public abstract void apply(REVisitor<L> visitor,
                           java.lang.Object context)
                    throws REVisitorException
Applies the given REVisitor to this TreeNode.

Parameters:
visitor - The REVisitor to be applied
context - The calling context
Throws:
REVisitorException - if an error occurs

copyTree

public abstract TreeNode<L> copyTree()
Returns a copy of the Tree rooted at this node. This will fail to terminate if the tree becomes a cyclic graph.

Returns:
a copy of the Tree rooted at this node

print

public abstract java.lang.String print(java.lang.String prefix)
Prints the Tree rooted at this node. This will fail to terminate if the tree becomes a cyclic graph.

Parameters:
prefix - The string to be appended before everything printed for this level. Should be a String of spaces
Returns:
A string representation of this TreeNode

toString

public java.lang.String toString()
Returns a string representation of this Object.

Overrides:
toString in class java.lang.Object
Returns:
A string representation of this Object

equalsTree

public boolean equalsTree(TreeNode<L> node2)
Returns true if the tree rooted at this node and the tree rooted at the given node are equal and false otherwise.

NOTE: This will fail to terminate if the tree becomes a cyclic graph.

Parameters:
node2 - The second TreeNode
Returns:
True if this TreeNode and the given TreeNode are equal and false otherwise

trace

public static void trace(java.lang.Object what)
If the boolean variable trace is true, trace() prints out the object that was passed to it.

Parameters:
what - the Object to be printed.