Class FormulaParser


  • public class FormulaParser
    extends java.lang.Object
    This class parses a formula string into a List of tokens in RPN order. Inspired by Lets Build a Compiler, by Jack Crenshaw BNF for the formula expression is : ::= [ ]* ::= [ ]* ::= | () | | ::= ([expression [, expression]*])
    Author:
    Avik Sengupta , Andrew C. oliver (acoliver at apache dot org), Eric Ladner (eladner at goldinc dot com), Cameron Riley (criley at ekmail.com), Peter M. Murray (pete at quantrix dot com), Pavel Krupets (pkrupets at palmtreebusiness dot com)
    • Constructor Summary

      Constructors 
      Constructor Description
      FormulaParser​(java.lang.String formula, Workbook book)
      Create the formula parser, with the string that is to be parsed against the supplied workbook.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Ptg[] getRPNPtg()
      API call to retrive the array of Ptgs created as a result of the parsing
      Ptg[] getRPNPtg​(int formulaType)  
      void parse()
      API call to execute the parsing of the formula
      java.lang.String toFormulaString​(java.util.List lptgs)
      Convience method which takes in a list then passes it to the other toFormulaString signature.
      static java.lang.String toFormulaString​(Workbook book, java.util.List lptgs)
      Convience method which takes in a list then passes it to the other toFormulaString signature.
      static java.lang.String toFormulaString​(Workbook book, Ptg[] ptgs)
      Static method to convert an array of Ptgs in RPN order to a human readable string format in infix mode.
      java.lang.String toFormulaString​(Ptg[] ptgs)
      Static method to convert an array of Ptgs in RPN order to a human readable string format in infix mode.
      java.lang.String toString()
      toString on the parser instance returns the RPN ordered list of tokens Useful for testing
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • FORMULA_TYPE_CELL

        public static int FORMULA_TYPE_CELL
      • FORMULA_TYPE_SHARED

        public static int FORMULA_TYPE_SHARED
      • FORMULA_TYPE_ARRAY

        public static int FORMULA_TYPE_ARRAY
      • FORMULA_TYPE_CONDFOMRAT

        public static int FORMULA_TYPE_CONDFOMRAT
      • FORMULA_TYPE_NAMEDRANGE

        public static int FORMULA_TYPE_NAMEDRANGE
    • Constructor Detail

      • FormulaParser

        public FormulaParser​(java.lang.String formula,
                             Workbook book)
        Create the formula parser, with the string that is to be parsed against the supplied workbook. A later call the parse() method to return ptg list in rpn order, then call the getRPNPtg() to retrive the parse results. This class is recommended only for single threaded use. If you only have a usermodel.HSSFWorkbook, and not a model.Workbook, then use the convenience method on usermodel.HSSFFormulaEvaluator
    • Method Detail

      • parse

        public void parse()
        API call to execute the parsing of the formula
      • getRPNPtg

        public Ptg[] getRPNPtg()
        API call to retrive the array of Ptgs created as a result of the parsing
      • getRPNPtg

        public Ptg[] getRPNPtg​(int formulaType)
      • toFormulaString

        public static java.lang.String toFormulaString​(Workbook book,
                                                       java.util.List lptgs)
        Convience method which takes in a list then passes it to the other toFormulaString signature.
        Parameters:
        book - workbook for 3D and named references
        lptgs - list of Ptg, can be null or empty
        Returns:
        a human readable String
      • toFormulaString

        public java.lang.String toFormulaString​(java.util.List lptgs)
        Convience method which takes in a list then passes it to the other toFormulaString signature. Works on the current workbook for 3D and named references
        Parameters:
        lptgs - list of Ptg, can be null or empty
        Returns:
        a human readable String
      • toFormulaString

        public static java.lang.String toFormulaString​(Workbook book,
                                                       Ptg[] ptgs)
        Static method to convert an array of Ptgs in RPN order to a human readable string format in infix mode.
        Parameters:
        book - workbook for named and 3D references
        ptgs - array of Ptg, can be null or empty
        Returns:
        a human readable String
      • toFormulaString

        public java.lang.String toFormulaString​(Ptg[] ptgs)
        Static method to convert an array of Ptgs in RPN order to a human readable string format in infix mode. Works on the current workbook for named and 3D references.
        Parameters:
        ptgs - array of Ptg, can be null or empty
        Returns:
        a human readable String
      • toString

        public java.lang.String toString()
        toString on the parser instance returns the RPN ordered list of tokens Useful for testing
        Overrides:
        toString in class java.lang.Object