diva.sketch.parser2d
Class CompositeConstituent

java.lang.Object
  |
  +--diva.sketch.parser2d.CompositeConstituent

public class CompositeConstituent
extends java.lang.Object
implements Constituent

A default implementation for a non-terminal constituent. Composite constituents cache the bounding box of their children once it is computed. Children of this constituent have names, which distinguish two children of the same type. For example, suppose you are parsing an "integral" mathematical expression, and the integral has a lower bound, upper bound, and body all of type expression. Then these would be distinguished by the names given in the parsing rule, such as "lowerBound", "upperBound", and "body".

Version:
$Revision: 1.1 $

Field Summary
(package private)  java.awt.geom.Rectangle2D _bounds
          Cache the bounds.
(package private)  java.lang.String[] _childNames
          The names of the children of this constituent.
(package private)  Constituent[] _children
          The children of this constituent.
(package private)  java.lang.String _type
          The type (LHS) of this constituent.
 
Constructor Summary
CompositeConstituent(java.lang.String type, Constituent[] children, java.lang.String[] childNames)
          Construct a composite constituent with the given type and children.
 
Method Summary
 java.util.Iterator children()
          Return an iterator of the child constituents.
 void clearCachedBounds()
          Clear the cached bounds (in case the child constituents have changed some way.
 boolean equals(java.lang.Object o)
          A customized equals implementation to enable parser memoization.
 java.awt.geom.Rectangle2D getBounds()
          Return the 2D bounding box of the constituent.
 Constituent getChild(java.lang.String name)
          Return the child with the given name; throw an IllegalArgument exception if the argument is not a child of this composite.
 java.lang.String getName(Constituent child)
          Return the name of the given child; throw an IllegalArgument exception if the argument is not a child of this composite.
 java.lang.String getType()
          Return the type of the constituent (its LHS)
 int hashCode()
          A customized hash code implementation to enable parser memoization.
 java.lang.String toString()
          Return a string with the type.
 
Methods inherited from class java.lang.Object
, clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

_bounds

java.awt.geom.Rectangle2D _bounds
Cache the bounds.

_type

java.lang.String _type
The type (LHS) of this constituent.

_children

Constituent[] _children
The children of this constituent.

_childNames

java.lang.String[] _childNames
The names of the children of this constituent.
Constructor Detail

CompositeConstituent

public CompositeConstituent(java.lang.String type,
                            Constituent[] children,
                            java.lang.String[] childNames)
Construct a composite constituent with the given type and children.
Method Detail

children

public java.util.Iterator children()
Return an iterator of the child constituents.

clearCachedBounds

public void clearCachedBounds()
Clear the cached bounds (in case the child constituents have changed some way.

equals

public boolean equals(java.lang.Object o)
A customized equals implementation to enable parser memoization. Equals if given object is also a composite constituent with the type and with equal children.
Overrides:
equals in class java.lang.Object

getChild

public Constituent getChild(java.lang.String name)
Return the child with the given name; throw an IllegalArgument exception if the argument is not a child of this composite.

getName

public java.lang.String getName(Constituent child)
Return the name of the given child; throw an IllegalArgument exception if the argument is not a child of this composite.

getBounds

public java.awt.geom.Rectangle2D getBounds()
Return the 2D bounding box of the constituent.
Specified by:
getBounds in interface Constituent

getType

public java.lang.String getType()
Return the type of the constituent (its LHS)
Specified by:
getType in interface Constituent

hashCode

public int hashCode()
A customized hash code implementation to enable parser memoization.
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Return a string with the type.
Overrides:
toString in class java.lang.Object