math
Class MathToken
java.lang.Object
math.MathToken
public class MathToken
- extends java.lang.Object
Parsing token representation
This class describes a single object that may be encountered in a mathematical equations,
which may be a constant, a variable, a function, or an operation on teo numbers.
This class contains static methods that convert a user inputted Equation into an instance
of Equation, a special binary tree of MathTokens that allws the computer to evaluate custom
equations. The conversion methods are not efficient, but they are not used excessivly either.
This class also contains methods for performing any possible opertaion stored in a MathToken,
with reasonable efficiency.
Created by Michael Rule on Mon Aug 09 2004.
Method Summary |
boolean |
equals(int num)
|
boolean |
equals(MathToken otherToken)
|
static MathToken |
extractToken(java.lang.String data)
|
static java.lang.String |
functions()
Remaining methods are associated with the main block, which tests the functionality of this class * |
static int |
getEndParenthesis(MathToken[] token,
int start)
|
MathToken[] |
getEquation()
|
float |
getNumber()
|
int |
getOperationTypeId()
|
int |
getToken()
|
char |
getVar()
|
static boolean |
isFirst(java.lang.String data,
java.lang.String token)
|
boolean |
isFunction()
|
boolean |
isOperator()
|
boolean |
isVariable()
|
static void |
main(java.lang.String[] args)
|
static MathToken[] |
remove(MathToken[] data,
int start,
int end)
|
static java.lang.String |
removeWhiteSpace(java.lang.String data)
|
static MathToken[] |
replace(MathToken[] data,
int start,
int end,
MathToken replacement)
|
static MathToken[] |
replace(MathToken[] data,
int start,
int end,
MathToken[] replacement)
|
static MathToken[] |
substring(MathToken[] data,
int start,
int end)
|
static Equation |
toEquation(java.lang.String data)
Calls the methods that convert a String into an Equation |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
masterTokens
public static final java.lang.String[][] masterTokens
MathToken
public MathToken(char Char)
- Parameters:
Char
-
MathToken
public MathToken(int num)
- Parameters:
num
-
MathToken
public MathToken(float num)
- Parameters:
num
-
MathToken
public MathToken(MathToken token)
- Parameters:
token
-
MathToken
public MathToken(MathToken[] otherTokens)
- Parameters:
otherTokens
-
MathToken
public MathToken(java.lang.String data)
- Parameters:
data
-
getToken
public int getToken()
- Returns:
isVariable
public boolean isVariable()
- Returns:
getOperationTypeId
public int getOperationTypeId()
- Returns:
getVar
public char getVar()
- Returns:
getNumber
public float getNumber()
- Returns:
getEquation
public MathToken[] getEquation()
- Returns:
equals
public boolean equals(MathToken otherToken)
- Parameters:
otherToken
-
- Returns:
equals
public boolean equals(int num)
- Parameters:
num
-
- Returns:
isOperator
public boolean isOperator()
- Returns:
isFunction
public boolean isFunction()
- Returns:
extractToken
public static MathToken extractToken(java.lang.String data)
- Parameters:
data
-
- Returns:
isFirst
public static boolean isFirst(java.lang.String data,
java.lang.String token)
- Parameters:
data
- token
-
- Returns:
removeWhiteSpace
public static java.lang.String removeWhiteSpace(java.lang.String data)
- Parameters:
data
-
- Returns:
toEquation
public static Equation toEquation(java.lang.String data)
- Calls the methods that convert a String into an Equation
- Parameters:
data
-
- Returns:
replace
public static MathToken[] replace(MathToken[] data,
int start,
int end,
MathToken[] replacement)
- Parameters:
data
- start
- end
- replacement
-
- Returns:
replace
public static MathToken[] replace(MathToken[] data,
int start,
int end,
MathToken replacement)
- Parameters:
data
- start
- end
- replacement
-
- Returns:
remove
public static MathToken[] remove(MathToken[] data,
int start,
int end)
- Parameters:
data
- start
- end
-
- Returns:
substring
public static MathToken[] substring(MathToken[] data,
int start,
int end)
- Parameters:
data
- start
- end
-
- Returns:
getEndParenthesis
public static int getEndParenthesis(MathToken[] token,
int start)
- Parameters:
token
- start
-
- Returns:
toString
public java.lang.String toString()
- Overrides:
toString
in class java.lang.Object
- Returns:
functions
public static java.lang.String functions()
- Remaining methods are associated with the main block, which tests the functionality of this class *
- Returns:
main
public static void main(java.lang.String[] args)
throws java.io.IOException
- Parameters:
args
-
- Throws:
java.io.IOException