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
or
grain 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:
  • Field Details

  • Constructor Details

    • FormulaParser

      public FormulaParser()
  • Method Details

    • 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 String
      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(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)
    • splitToFirstLevelOperation

      protected static String[] splitToFirstLevelOperation(String formula)
    • getFirstCompleteBracketString

      protected static String getFirstCompleteBracketString(String formula, int fromIndex)
    • kickOutSurroundingBracket

      protected static String kickOutSurroundingBracket(String formula)
      deletes a bracket that surrounds the whole formula from the formula.
      Parameters:
      formula - formula String
      Returns:
      formula String without surrounding bracket