de.fho.jump.pirol.utilities.FormulaParsing
Class FormulaParser

java.lang.Object
  extended by de.fho.jump.pirol.utilities.FormulaParsing.FormulaParser

public class FormulaParser
extends java.lang.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
or
grain mois / 2.

Version:
$Rev: 2551 $
Author:
Ole Rahn

FH Osnabrück - University of Applied Sciences Osnabrück,
Project: PIROL (2005),
Subproject: Daten- und Wissensmanagement
See Also:
de.fho.jump.pirol.utilities.FeatureCollectionTools#applyFormulaToFeatureCollection(FeatureCollection, AttributeInfo, FormulaValue, boolean)

Field Summary
static java.lang.String KEY_ACOS
           
static java.lang.String KEY_ASIN
           
static java.lang.String KEY_ATAN
           
static java.lang.String KEY_COS
           
static java.lang.String KEY_EXP
           
static java.lang.String KEY_LOG
           
static java.lang.String KEY_LOG10
           
static java.lang.String KEY_PI
           
static java.lang.String KEY_POW
           
static java.lang.String KEY_SIN
           
static java.lang.String KEY_SQRT
           
static java.lang.String KEY_TAN
           
static java.lang.String KEY_TODEG
           
static java.lang.String KEY_TORAD
           
protected static PersonalLogger logger
           
 
Constructor Summary
FormulaParser()
           
 
Method Summary
protected static int findFirstAddSubOperatorOutsideABracket(java.lang.String formula, int fromIndex)
           
protected static int findFirstMultiDivOperatorOutsideABracket(java.lang.String formula, int fromIndex)
           
protected static int findFirstOccuranceOutsideABracket(java.lang.String toBeFound, java.lang.String formula, int fromIndex)
           
protected static java.lang.String getFirstCompleteBracketString(java.lang.String formula, int fromIndex)
           
static FormulaValue getValue(java.lang.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 boolean isBracket(java.lang.String brack)
           
protected static boolean isOperator(java.lang.String op)
           
protected static java.lang.String kickOutSurroundingBracket(java.lang.String formula)
          deletes a bracket that surrounds the whole formula from the formula.
protected static java.lang.String[] splitToFirstLevelOperation(java.lang.String formula)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static PersonalLogger logger

KEY_SQRT

public static final java.lang.String KEY_SQRT
See Also:
Constant Field Values

KEY_POW

public static final java.lang.String KEY_POW
See Also:
Constant Field Values

KEY_PI

public static final java.lang.String KEY_PI
See Also:
Constant Field Values

KEY_LOG

public static final java.lang.String KEY_LOG
See Also:
Constant Field Values

KEY_SIN

public static final java.lang.String KEY_SIN
See Also:
Constant Field Values

KEY_COS

public static final java.lang.String KEY_COS
See Also:
Constant Field Values

KEY_TAN

public static final java.lang.String KEY_TAN
See Also:
Constant Field Values

KEY_EXP

public static final java.lang.String KEY_EXP
See Also:
Constant Field Values

KEY_ASIN

public static final java.lang.String KEY_ASIN
See Also:
Constant Field Values

KEY_ACOS

public static final java.lang.String KEY_ACOS
See Also:
Constant Field Values

KEY_ATAN

public static final java.lang.String KEY_ATAN
See Also:
Constant Field Values

KEY_LOG10

public static final java.lang.String KEY_LOG10
See Also:
Constant Field Values

KEY_TODEG

public static final java.lang.String KEY_TODEG
See Also:
Constant Field Values

KEY_TORAD

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

FormulaParser

public FormulaParser()
Method Detail

getValue

public static FormulaValue getValue(java.lang.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 -
featSchema - 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(java.lang.String op)

isBracket

protected static boolean isBracket(java.lang.String brack)

findFirstOccuranceOutsideABracket

protected static int findFirstOccuranceOutsideABracket(java.lang.String toBeFound,
                                                       java.lang.String formula,
                                                       int fromIndex)

findFirstAddSubOperatorOutsideABracket

protected static int findFirstAddSubOperatorOutsideABracket(java.lang.String formula,
                                                            int fromIndex)

findFirstMultiDivOperatorOutsideABracket

protected static int findFirstMultiDivOperatorOutsideABracket(java.lang.String formula,
                                                              int fromIndex)

splitToFirstLevelOperation

protected static java.lang.String[] splitToFirstLevelOperation(java.lang.String formula)

getFirstCompleteBracketString

protected static java.lang.String getFirstCompleteBracketString(java.lang.String formula,
                                                                int fromIndex)

kickOutSurroundingBracket

protected static java.lang.String kickOutSurroundingBracket(java.lang.String formula)
deletes a bracket that surrounds the whole formula from the formula.

Parameters:
formula - formula String
Returns:
formula String without surrounding bracket