scphEditor
Class ExpressionNary

java.lang.Object
  extended by java.util.Observable
      extended by scphEditor.CloneableObservable
          extended by scphEditor.OperandVector
              extended by scphEditor.Operand
                  extended by scphEditor.Expression
                      extended by scphEditor.ExpressionNary
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class ExpressionNary
extends Expression

This class represents n-ary compound expressions.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class scphEditor.Expression
Expression.Replacement
 
Field Summary
 
Fields inherited from class scphEditor.Expression
children, op, paren, splitted
 
Constructor Summary
ExpressionNary(IOperator opOf)
          Constructs an n-ary Expression object with the given operator.
ExpressionNary(IOperator opOf, int n)
          Constructs an n-ary Expression object with the given operator.
 
Method Summary
 void acceptVisitor(OperandVisitor v)
          Calls v.visitExpressionNary(this).
 void addChild(Operand newChild, int atIndex)
          This implementation does not do anything.
 Operand delChild(int atIndex)
          This implementation returns null and does not do anything else.
 void group(int atIndex, int n)
           
 void setChild(Operand newChild, int atIndex)
          Adopts the given new child as my child at the given index, replacing the previous child at the same index.
protected  int ungroup_impl(int atIndex)
          The bulk of ungroup().
 void ungroup(int atIndex)
          Ungroups at the given index.
 
Methods inherited from class scphEditor.Expression
addParen, clone, countChildren, deParen, getChild, getChildren, getOperator, getParen, getSplit, setSplit
 
Methods inherited from class scphEditor.Operand
ensureParen, needParen, removeParen
 
Methods inherited from class scphEditor.CloneableObservable
addObserver, cloneObserverList, cloneObserverList, countObservers, deleteObserver, deleteObservers, notifyObservers, notifyObservers
 
Methods inherited from class java.util.Observable
clearChanged, hasChanged, setChanged
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExpressionNary

public ExpressionNary(IOperator opOf)
Constructs an n-ary Expression object with the given operator. The given operator will become the operator of this compound expression permanently. Two null children are set up initially.

Parameters:
opOf - the operator object for this Expression object.

ExpressionNary

public ExpressionNary(IOperator opOf,
                      int n)
Constructs an n-ary Expression object with the given operator. The given operator will become the operator of this compound expression permanently. null children are set up initially as specified by the parameters.

Parameters:
opOf - the operator object for this Expression object
n - number of initial null children to set up
Method Detail

setChild

public void setChild(Operand newChild,
                     int atIndex)
Description copied from class: OperandVector
Adopts the given new child as my child at the given index, replacing the previous child at the same index.

This default implementation is for a leaf node in which there must be no child, so it always throws an exception. A compound expression must re-implement this method sensibly.

Overrides:
setChild in class Expression
Parameters:
newChild - the new child
atIndex - the index to where newChild goes

addChild

public void addChild(Operand newChild,
                     int atIndex)
Description copied from class: Expression
This implementation does not do anything.

Overrides:
addChild in class Expression

delChild

public Operand delChild(int atIndex)
Description copied from class: Expression
This implementation returns null and does not do anything else.

Overrides:
delChild in class Expression

ungroup

public void ungroup(int atIndex)
Ungroups at the given index. In other words, if my operator is associative and the child at the given index has the same operator, then use associativity to expand the child into me.

Example: if I am 0 + (x + y) + 2, then ungroup(1) turns me into 0 + x + y + 2.

Parameters:
atIndex - the given index.

group

public void group(int atIndex,
                  int n)

ungroup_impl

protected int ungroup_impl(int atIndex)
The bulk of ungroup(). Helps ungroup() and addChild(). It does the ungrouping, but does not send out change notification. (So that ungroup() and addChild() can decide when to do so.)

Parameters:
atIndex - ungrouping occurs at my child at this index.
Returns:
0 if no ungrouping performed (e.g., operators are different or not associative); otherwise the number of new children in the expansion.
See Also:
addChild(scphEditor.Operand, int), ungroup(int)

acceptVisitor

public void acceptVisitor(OperandVisitor v)
Calls v.visitExpressionNary(this).

Overrides:
acceptVisitor in class Expression
Parameters:
v - the visitor object that wants to visit this operand.