java.lang.Object
org.rrd4j.data.RpnCalculator

class RpnCalculatorextends Object
Reverse Polish Notation (RPN) expression calculator.
Evaluates mathematical expressions on RRD data sources using RPN notation for efficient computation.
  • Field Details

    • symbols

      private static final RpnCalculator.Token_Symbol[] symbols
      Every token, for name lookup.
    • perfect

      private static final PerfectStringHash perfect
      Perfect hash mapping token text to its symbol.
    • rpnExpression

      private final String rpnExpression
      Rpn expression
    • sourceName

      private final String sourceName
      Source name
    • dataProcessor

      private final DataProcessor dataProcessor
      Data processor
    • tokens

      private final RpnCalculator.Token[] tokens
      The parsed RPN expression.
    • stack

      private final RpnCalculator.RpnStack stack
      The stack the expression evaluates on.
    • calculatedValues

      private final double[] calculatedValues
      Calculated values
    • timestamps

      private final long[] timestamps
      Array of timestamps for the data series
    • timeStep

      private final double timeStep
      Time step
    • sourcesNames

      private final List<String> sourcesNames
      Sources names
  • Constructor Details

    • RpnCalculator

      RpnCalculator(String rpnExpression, String sourceName, DataProcessor dataProcessor)
      Rpn calculator
      Parameters:
      rpnExpression - the RPN expression, its tokens separated by commas
      sourceName - the data series an unqualified PREV token refers to
      dataProcessor - supplies the timestamps and the per-source value arrays
  • Method Details

    • createToken

      private RpnCalculator.Token createToken(String parsedText)
      Create token
      Parameters:
      parsedText - one RPN token string: a symbol, PREV, PREV(variable), a number or a source name
      Returns:
      the token built from the text
    • calculateValues

      double[] calculateValues()
      Calculate values
      Returns:
      one value per timestamp, the expression evaluated at each step
    • getCalendarField

      private double getCalendarField(double timestamp, int field)
      Calendar field value from timestamp.
      Parameters:
      timestamp - the unix time in seconds
      field - the java.util.Calendar field constant to read
      Returns:
      the value of that field at the time
    • push

      private void push(double x)
      Push a value onto the RPN stack
      Parameters:
      x - the value to push
    • pop

      private double pop()
      Pop a value from the RPN stack
      Returns:
      the top value, removed from the stack
    • peek

      private double peek()
      Examine the top value on the stack without removing it
      Returns:
      the top value, left on the stack
    • resetStack

      private void resetStack()
      Clear all values from the RPN calculation stack
    • isStackEmpty

      private boolean isStackEmpty()
      Whether the stack holds no values.
      Returns:
      true if the stack is empty