Class BinaryOperator

java.lang.Object
  |
  +--BinaryOperator
All Implemented Interfaces:
Node
Direct Known Subclasses:
Addition, Division, Multiplication, Subtraction

public abstract class BinaryOperator
extends Object
implements Node

Represents a binary operator (an operator that has two arguments).


Field Summary
protected  Node left
           
protected  Node right
           
 
Constructor Summary
BinaryOperator(Node left, Node right)
          Constructs a BinaryOperator.
 
Method Summary
 Node getChild(int i)
          Returns the nth child of this node.
 int getNumChildren()
          Returns the number of children this node has.
abstract  int getValue()
          Returns the numeric value of the node as an integer.
abstract  String toString()
          Returns the String representation of this node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

left

protected Node left

right

protected Node right
Constructor Detail

BinaryOperator

public BinaryOperator(Node left,
                      Node right)
Constructs a BinaryOperator.
Parameters:
left - Child 0
right - Child 1
Method Detail

getValue

public abstract int getValue()
Description copied from interface: Node
Returns the numeric value of the node as an integer. For example, if the node is a constant 5, then 5 should be returned. If the node is an operator, for example + and its children are 5 and 5, then 10 should be returned.
Specified by:
getValue in interface Node

getNumChildren

public int getNumChildren()
Description copied from interface: Node
Returns the number of children this node has.
Specified by:
getNumChildren in interface Node

getChild

public Node getChild(int i)
Description copied from interface: Node
Returns the nth child of this node. The first child is child 0. If there is no child with the given number, null is returned, and no error is generated.
Specified by:
getChild in interface Node

toString

public abstract String toString()
Description copied from interface: Node
Returns the String representation of this node. For example, the value of the integer 5 should return a "5" and the value of an addition operator should return a "+".
Specified by:
toString in interface Node
Overrides:
toString in class Object