vec_math
Class Operator<E>

java.lang.Object
  extended by vec_math.Operator<E>
All Implemented Interfaces:
Serializable

public class Operator<E>
extends Object
implements Serializable

An abstract definition of mathematical operators. Defines an operator symbol, an operator precedence and the number of operands. The precedence runs from higher numbers to lower ones and should if possible, reflect the precedence of the JAVA language specification.

No actions are assigned to these operands, this class acts only as a description for operators.

See Also:
Serialized Form

Field Summary
private  int number
          Number of operands needed for the operator.
private  int precedence
          Precedence of the operator.
private  E symbol
          Operator symbol, e.g.
 
Constructor Summary
Operator(E sym, int type, int priority)
          Constructs a new fully qualified operator.
 
Method Summary
 int getNumber()
          Returns the number of operands needed for this operator.
 int getPrecedence()
          Gets the precedence of the operator.
 E getSource()
          Returns the symbol of the operator, e.g.
 boolean isBinary()
          Returns true if this operator is binary (i.e.
 boolean isUnary()
          Returns true if this operator is unary (i.e.
protected  void setNumber(int num)
          Sets the number of operands this operator acts on.
protected  void setPrecedence(int priority)
          Sets the precedence of this operator.
protected  void setSource(E sym)
          Sets the symbol of the operator.
 String toString()
          String representation of the operator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

symbol

private E symbol
Operator symbol, e.g. '+'


number

private int number
Number of operands needed for the operator.


precedence

private int precedence
Precedence of the operator.

Constructor Detail

Operator

public Operator(E sym,
                int type,
                int priority)
Constructs a new fully qualified operator.

Parameters:
sym - The symbol of the operator, e.g. '+'.
type - The number of operands, normally 1 or 2.
priority - The precedence of the operator, e.g. 12 for '*'.
See Also:
isUnary(), isBinary()
Method Detail

getSource

public E getSource()
Returns the symbol of the operator, e.g. '+', as an Object.


setSource

protected void setSource(E sym)
Sets the symbol of the operator.


isUnary

public boolean isUnary()
Returns true if this operator is unary (i.e. acts one a single operand).


isBinary

public boolean isBinary()
Returns true if this operator is binary (i.e. acts on two operands).


getNumber

public int getNumber()
Returns the number of operands needed for this operator.

See Also:
isUnary(), isBinary()

setNumber

protected void setNumber(int num)
Sets the number of operands this operator acts on.


getPrecedence

public int getPrecedence()
Gets the precedence of the operator. Higher numbers mean a higher priority.


setPrecedence

protected void setPrecedence(int priority)
Sets the precedence of this operator.


toString

public String toString()
String representation of the operator

Overrides:
toString in class Object