Class FormulaParser
- java.lang.Object
-
- de.fho.jump.pirol.utilities.FormulaParsing.FormulaParser
-
public class FormulaParser extends Object
This class is a utility to parse formulas, that describe how an additional attribute value is to be calculated on a by feature basis. Formulas thereby can contain constant values as well as attribute values, that need to be extracted for each feature.
Formulas are exspected to be space-separated: Each attribute name, constant value, bracket or operator has to be surrounded by empty spaces.
A valid formulas (for a FeatureSchema that has the attributes "yield" and "grain mois") would look like this:( 4 + 6 ) * yield
orgrain mois / 2.- Version:
- $Rev$
- Author:
- Ole Rahn
FH Osnabrück - University of Applied Sciences Osnabrück,
Project: PIROL (2005),
Subproject: Daten- und Wissensmanagement - See Also:
FeatureCollectionTools.applyFormulaToFeatureCollection(FeatureCollection, AttributeInfo, FormulaValue, boolean)
-
-
Field Summary
Fields Modifier and Type Field Description static StringKEY_ACOSstatic StringKEY_ASINstatic StringKEY_ATANstatic StringKEY_COSstatic StringKEY_EXPstatic StringKEY_LOGstatic StringKEY_LOG10static StringKEY_PIstatic StringKEY_POWstatic StringKEY_SINstatic StringKEY_SQRTstatic StringKEY_TANstatic StringKEY_TODEGstatic StringKEY_TORADprotected static PersonalLoggerlogger
-
Constructor Summary
Constructors Constructor Description FormulaParser()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description protected static intfindFirstAddSubOperatorOutsideABracket(String formula, int fromIndex)protected static intfindFirstMultiDivOperatorOutsideABracket(String formula, int fromIndex)protected static intfindFirstOccuranceOutsideABracket(String toBeFound, String formula, int fromIndex)protected static StringgetFirstCompleteBracketString(String formula, int fromIndex)static FormulaValuegetValue(String formula, FeatureSchema featSchema)Recursively parses a given (sub-) formula into a FormulaValue, which can be an operation with sub-FormularValues or a value.protected static booleanisBracket(String brack)protected static booleanisOperator(String op)protected static StringkickOutSurroundingBracket(String formula)deletes a bracket that surrounds the whole formula from the formula.protected static String[]splitToFirstLevelOperation(String formula)
-
-
-
Field Detail
-
logger
protected static PersonalLogger logger
-
KEY_SQRT
public static final String KEY_SQRT
- See Also:
- Constant Field Values
-
KEY_POW
public static final String KEY_POW
- See Also:
- Constant Field Values
-
KEY_PI
public static final String KEY_PI
- See Also:
- Constant Field Values
-
KEY_LOG
public static final String KEY_LOG
- See Also:
- Constant Field Values
-
KEY_SIN
public static final String KEY_SIN
- See Also:
- Constant Field Values
-
KEY_COS
public static final String KEY_COS
- See Also:
- Constant Field Values
-
KEY_TAN
public static final String KEY_TAN
- See Also:
- Constant Field Values
-
KEY_EXP
public static final String KEY_EXP
- See Also:
- Constant Field Values
-
KEY_ASIN
public static final String KEY_ASIN
- See Also:
- Constant Field Values
-
KEY_ACOS
public static final String KEY_ACOS
- See Also:
- Constant Field Values
-
KEY_ATAN
public static final String KEY_ATAN
- See Also:
- Constant Field Values
-
KEY_LOG10
public static final String KEY_LOG10
- See Also:
- Constant Field Values
-
KEY_TODEG
public static final String KEY_TODEG
- See Also:
- Constant Field Values
-
KEY_TORAD
public static final String KEY_TORAD
- See Also:
- Constant Field Values
-
-
Method Detail
-
getValue
public static FormulaValue getValue(String formula, FeatureSchema featSchema)
Recursively parses a given (sub-) formula into a FormulaValue, which can be an operation with sub-FormularValues or a value.- Parameters:
formula- the formula passed as a StringfeatSchema- The feature schema to check attribute names, if neccessary- Returns:
- the given formula parsed into a FormulaValue or null if the given String did not contain formula information
-
isOperator
protected static boolean isOperator(String op)
-
isBracket
protected static boolean isBracket(String brack)
-
findFirstOccuranceOutsideABracket
protected static int findFirstOccuranceOutsideABracket(String toBeFound, String formula, int fromIndex)
-
findFirstAddSubOperatorOutsideABracket
protected static int findFirstAddSubOperatorOutsideABracket(String formula, int fromIndex)
-
findFirstMultiDivOperatorOutsideABracket
protected static int findFirstMultiDivOperatorOutsideABracket(String formula, int fromIndex)
-
getFirstCompleteBracketString
protected static String getFirstCompleteBracketString(String formula, int fromIndex)
-
-