Class StringToMathExpression


public class StringToMathExpression
extends java.lang.Object

This class provides all methodes to convert a StringTherm into an correct MathExpression. The MathExpression is provided as an Vector.

Field Summary

private int
COUNTER_STOP
private double
algebraicSign
private int
countedLeftParenthesis
private int
countedRightParenthesis
private int
counter
private boolean
diracEmpty
private boolean
eEmpty
private int
eFunctionComplexLength
private boolean
iError
private Vector
infix
private int
numberLength
private Vector
sumData
private boolean
sumEmpty
private boolean
trigonometricFunctionEmpty

Constructor Summary

StringToMathExpression()
StringToMathExpression Constructor initializes all Check Variables to proper state.

Method Summary

void
convertStringToMathExpression(String mathExpression)
Converts an String Term into an valid Math Expression.
private int
getEFunctionComplexLength()
Gives you the String.length() of the last extracted eFunction.
private String
getFunctionTherm(String mathExpression)
Extracts the Therm which has to be calculated of the given Therm.
Vector
getInfix()
Returns the infix Vector.
private double
getNumber(String numberToParse)
Extracts the number from the given String.
private int
getNumberLength()
Gives you the Stringh.length() of the last extracted number.
private String
getOperator(String operatorToParse)
Extracts the operator from the given String.
private int
getSumLength()
Gives you the String.length() of the last extracted sum.
private String
getTrigonometricFunction(String trigonometricFunctionToParse)
Extracts the trigonometric function from the given String.
private boolean
isDigit(char character)
Tests if the given char is a digit.
private boolean
isDirac(String mathExpression)
Tests if the given String contains a dirac function at the beginning.
private boolean
isEFunction(String mathExpression)
Tests if the given String contains a e function at the beginning.
private boolean
isEFunctionComplex(String mathExpression)
Tests if the given String contains a Complex e function at the beginning.
private boolean
isImaginary(String mathExpression)
Tests if the given String is an Imaginary Value.
private boolean
isLeftParenthesis(String mathExpression)
Tests if the given String contains an left parenthesis at the beginning.
private boolean
isLeftParenthesis(char character)
Tests if the given char is an left parenthesis.
private boolean
isNumber(String mathExpression)
Tests if the given String contains a number at the beginning.
private boolean
isOperator(char character)
Tests if the given char is an math operator (+,-,*,/,^).
private boolean
isPi(String mathExpression)
Tests if the given String contains a pi function at the beginning.
private boolean
isPoint(char character)
Tests if the given char is an point.
private boolean
isRightParenthesis(String mathExpression)
Tests if the given String contains an right parenthesis at the beginning.
private boolean
isRightParenthesis(char character)
Tests if the given char is an right parenthesis.
private boolean
isSum(String mathExpression)
Tests if the given String contains a sum function at the beginning.
private boolean
isTrigonometricFunction(String mathExpression)
Tests if the given String contains a trigonometric function (sin,cos,tan) at the beginning.
private boolean
isVariable(char character)
Tests if the given char contains a variable (f,n) at the beginning.
void
printInfix()
Prints the infix Vector to System.out.
private void
processEFunctionComplex(String mathExpression)
Separates the eFunction, into cos(eFunction)+i*sin(eFunction) at the beginning of the String.
private void
processSum(String mathExpression)
Separates the start, end and sumTerm of the sum at the beginning of the String.

Field Details

COUNTER_STOP

private final int COUNTER_STOP

algebraicSign

private double algebraicSign

countedLeftParenthesis

private int countedLeftParenthesis

countedRightParenthesis

private int countedRightParenthesis

counter

private int counter

diracEmpty

private boolean diracEmpty

eEmpty

private boolean eEmpty

eFunctionComplexLength

private int eFunctionComplexLength

iError

private boolean iError

infix

private Vector infix

numberLength

private int numberLength

sumData

private Vector sumData

sumEmpty

private boolean sumEmpty

trigonometricFunctionEmpty

private boolean trigonometricFunctionEmpty

Constructor Details

StringToMathExpression

public StringToMathExpression()
StringToMathExpression Constructor initializes all Check Variables to proper state.

Method Details

convertStringToMathExpression

public void convertStringToMathExpression(String mathExpression)
            throws IllegalMathExpressionException
Converts an String Term into an valid Math Expression. The MathExpression is stored in an Vector. Every Expression separated as an singel Vector entry. The String will be converted to lower case and all whitespaces will be deleted. This should provide more flexibility for the given String.
Parameters:
mathExpression - the String wich will be converted into an valid MathExpression.

getEFunctionComplexLength

private int getEFunctionComplexLength()
Gives you the String.length() of the last extracted eFunction.
Returns:
an int with the String.length() of the last extracted eFunction.

getFunctionTherm

private String getFunctionTherm(String mathExpression)
Extracts the Therm which has to be calculated of the given Therm.
Returns:
an String with the extracted FunctionTherm.

getInfix

public Vector getInfix()
Returns the infix Vector.
Returns:
the infix Vector.

getNumber

private double getNumber(String numberToParse)
Extracts the number from the given String. It also accepts negative numbers.
Parameters:
numberToParse - the String from wich the number will be extracted.
Returns:
an double with the extracted Number.

getNumberLength

private int getNumberLength()
Gives you the Stringh.length() of the last extracted number.
Returns:
an int with the String.length() of the last extracted Number.

getOperator

private String getOperator(String operatorToParse)
Extracts the operator from the given String.
Parameters:
operatorToParse - the String from wich the operator will be extracted.
Returns:
an String with the extracted operator.

getSumLength

private int getSumLength()
Gives you the String.length() of the last extracted sum.
Returns:
an int with the String.length() of the last extracted sum.

getTrigonometricFunction

private String getTrigonometricFunction(String trigonometricFunctionToParse)
Extracts the trigonometric function from the given String.
Parameters:
trigonometricFunctionToParse - the String from wich the trigonometric function will be extracted.
Returns:
an String with the extracted trigonometric function.

isDigit

private boolean isDigit(char character)
Tests if the given char is a digit.
Parameters:
Returns:
an boolean specifying the test result.
See Also:
isNumber(String mathExpression)

isDirac

private boolean isDirac(String mathExpression)
Tests if the given String contains a dirac function at the beginning.
Parameters:
mathExpression - the String to test.
Returns:
an boolean specifying the test result.

isEFunction

private boolean isEFunction(String mathExpression)
Tests if the given String contains a e function at the beginning.
Parameters:
mathExpression - the String to test.
Returns:
an boolean specifying the test result.

isEFunctionComplex

private boolean isEFunctionComplex(String mathExpression)
Tests if the given String contains a Complex e function at the beginning.
Parameters:
mathExpression - the String to test.
Returns:
an boolean specifying the test result.

isImaginary

private boolean isImaginary(String mathExpression)
Tests if the given String is an Imaginary Value.
Parameters:
mathExpression - the String to test.
Returns:
an boolean specifying the test result.

isLeftParenthesis

private boolean isLeftParenthesis(String mathExpression)
Tests if the given String contains an left parenthesis at the beginning.
Parameters:
mathExpression - the String to test.
Returns:
an boolean specifying the test result.
See Also:
isLeftParenthesis(char character)

isLeftParenthesis

private boolean isLeftParenthesis(char character)
Tests if the given char is an left parenthesis.
Parameters:
character - the char to test.
Returns:
an boolean specifying the test result.
See Also:
isLeftParenthesis(String mathExpression)

isNumber

private boolean isNumber(String mathExpression)
Tests if the given String contains a number at the beginning. It also accepts negative numbers.
Parameters:
mathExpression - the String to test.
Returns:
an boolean specifying the test result.
See Also:
isDigit(char character)

isOperator

private boolean isOperator(char character)
Tests if the given char is an math operator (+,-,*,/,^).
Parameters:
character - the char to test.
Returns:
an boolean specifying the test result.

isPi

private boolean isPi(String mathExpression)
Tests if the given String contains a pi function at the beginning.
Parameters:
mathExpression - the String to test.
Returns:
an boolean specifying the test result.

isPoint

private boolean isPoint(char character)
Tests if the given char is an point.
Parameters:
character - the char to test.
Returns:
an boolean specifying the test result.

isRightParenthesis

private boolean isRightParenthesis(String mathExpression)
Tests if the given String contains an right parenthesis at the beginning.
Parameters:
mathExpression - the String to test.
Returns:
an boolean specifying the test result.
See Also:
isLeftParenthesis(char character)

isRightParenthesis

private boolean isRightParenthesis(char character)
Tests if the given char is an right parenthesis.
Parameters:
character - the char to test.
Returns:
an boolean specifying the test result.
See Also:
isRightParenthesis(String mathExpression)

isSum

private boolean isSum(String mathExpression)
Tests if the given String contains a sum function at the beginning.
Parameters:
mathExpression - the String to test.
Returns:
an boolean specifying the test result.

isTrigonometricFunction

private boolean isTrigonometricFunction(String mathExpression)
Tests if the given String contains a trigonometric function (sin,cos,tan) at the beginning.
Parameters:
mathExpression - the String to test.
Returns:
an boolean specifying the test result.

isVariable

private boolean isVariable(char character)
Tests if the given char contains a variable (f,n) at the beginning.
Parameters:
character - the char to test.
Returns:
an boolean specifying the test result.

printInfix

public void printInfix()
Prints the infix Vector to System.out. Only for debug!

processEFunctionComplex

private void processEFunctionComplex(String mathExpression)
Separates the eFunction, into cos(eFunction)+i*sin(eFunction) at the beginning of the String.
Parameters:
mathExpression - the String from wich the start, end and sumTerm will be extracted.

processSum

private void processSum(String mathExpression)
Separates the start, end and sumTerm of the sum at the beginning of the String.
Parameters:
mathExpression - the String from wich the start, end and sumTerm will be extracted.