Class Token

java.lang.Object
  extended by Token

public class Token
extends java.lang.Object

A Token class in which tokens know whether they are operators or numbers and can return appropriate values. If a token cannot be created from the string, an IllegalArgumentException is thrown. The legal operators are + - * / ( )

Author:
Beth Katz

Field Summary
static java.lang.String OperatorList
           
 
Constructor Summary
Token(java.lang.Double d)
          Build a number Token from a Double.
Token(java.lang.String s)
          Build a Token from a String.
 
Method Summary
 boolean hasHigherPrecedenceThan(Token other)
          Whether or not the Token has higher precedence than other Token
 boolean isLeftParen()
          Whether or not the Token is a left parentheses.
 boolean isNumber()
          Whether or not the Token is a number.
 boolean isOperator()
          Whether or not the Token is an operator.
 boolean isRightParen()
          Whether or not the Token is a right parentheses.
 java.lang.Double numberValue()
          The numeric value of the Token if it is a number Token Throws IllegalArgumentException if Token is not a number
 java.lang.Character operatorCharValue()
          The character value of the Token if it is an operator Token Throws IllegalArgumentException if Token is not an operator
 java.lang.String toString()
          String representation of the Token
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

OperatorList

public static final java.lang.String OperatorList
See Also:
Constant Field Values
Constructor Detail

Token

public Token(java.lang.Double d)
Build a number Token from a Double.

Parameters:
s - Double containing a Token.

Token

public Token(java.lang.String s)
Build a Token from a String. This can build number Tokens.

Parameters:
s - String containing a potential Token. Will throw IllegalArgumentException if Token cannot be built.
Method Detail

hasHigherPrecedenceThan

public boolean hasHigherPrecedenceThan(Token other)
Whether or not the Token has higher precedence than other Token

Returns:
true if Token has higher precedence, false if not

isLeftParen

public boolean isLeftParen()
Whether or not the Token is a left parentheses.

Returns:
true if Token is a left parentheses, false if not

isNumber

public boolean isNumber()
Whether or not the Token is a number.

Returns:
true if Token is a number, false if not

isOperator

public boolean isOperator()
Whether or not the Token is an operator. Parentheses are not operators.

Returns:
true if Token is a operator, false if not

isRightParen

public boolean isRightParen()
Whether or not the Token is a right parentheses.

Returns:
true if Token is a right parentheses, false if not

numberValue

public java.lang.Double numberValue()
The numeric value of the Token if it is a number Token Throws IllegalArgumentException if Token is not a number

Returns:
Token's Double value

operatorCharValue

public java.lang.Character operatorCharValue()
The character value of the Token if it is an operator Token Throws IllegalArgumentException if Token is not an operator

Returns:
Token's char value

toString

public java.lang.String toString()
String representation of the Token

Overrides:
toString in class java.lang.Object