java.lang.ObjectToken
public class Token
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 + - * / ( )
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 |
---|
public static final java.lang.String OperatorList
Constructor Detail |
---|
public Token(java.lang.Double d)
s
- Double containing a Token.public Token(java.lang.String s)
s
- String containing a potential Token.
Will throw IllegalArgumentException if Token cannot be built.Method Detail |
---|
public boolean hasHigherPrecedenceThan(Token other)
public boolean isLeftParen()
public boolean isNumber()
public boolean isOperator()
public boolean isRightParen()
public java.lang.Double numberValue()
public java.lang.Character operatorCharValue()
public java.lang.String toString()
toString
in class java.lang.Object