Class OperatorTable
java.lang.Object
|
+--OperatorTable
- Direct Known Subclasses:
- ArithmeticOperatorTable
- public class OperatorTable
- extends java.lang.Object
Much like GroupingSymbolTable
this call serves as a holder for a set of other objects
and acts as an interface to allow use of them. In this case the objects are
Operators.
The most common usage of OperatorTable
is ArithmeticOperatorTable
.
Field Summary |
protected int |
capacity
The current maximum number of elements possible |
protected Operator[] |
operators
The elements contained in the table |
protected int |
size
The current number of elements |
Constructor Summary |
OperatorTable()
Creates a new empty table with a capacity of 20 elements |
OperatorTable(int i)
Creates a new empty table with a capacity of i elements. |
Method Summary |
void |
add(Operator o)
Adds an Operator to the table. |
java.lang.String[] |
getTokens()
|
boolean |
isAnOperator(java.lang.String token,
boolean preceededByAnOperand)
Identifies String token as being an
{@ Operator} in the table or not based on the context given by
preceededByAnOperand . |
Operator |
operatorFor(java.lang.String token,
boolean preceededByAnOperand)
Identifies String token and returns the appropriate
Operator . |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
capacity
protected int capacity
- The current maximum number of elements possible
size
protected int size
- The current number of elements
operators
protected Operator[] operators
- The elements contained in the table
OperatorTable
public OperatorTable()
- Creates a new empty table with a capacity of 20 elements
OperatorTable
public OperatorTable(int i)
- Creates a new empty table with a capacity of i elements.
If i is 0 then the capacity is set to 1.
add
public void add(Operator o)
- Adds an
Operator
to the table. If there is not room in the table for
the symbol then (in the fashion of Vector
) the capacity is
doubled thereby making space.
- Parameters:
o
- symbol to be added
isAnOperator
public boolean isAnOperator(java.lang.String token,
boolean preceededByAnOperand)
- Identifies
String
token
as being an
{@ Operator} in the table or not based on the context given by
preceededByAnOperand
.
- Parameters:
token
- String
to be identified- Returns:
true
if token
is in the table
operatorFor
public Operator operatorFor(java.lang.String token,
boolean preceededByAnOperand)
- Identifies
String
token
and returns the appropriate
Operator
.
If token
is not in the table then a NotATableElementExcepetion
will be thrown (once I get that running.)
- Parameters:
token
- String
to be identified- Returns:
- the
Operator
for token
.
getTokens
public java.lang.String[] getTokens()
- Returns:
- a
String
array contianing the tokens for the
Operators in the table.