java.lang.Object
org.rrd4j.data.RpnCalculator
Reverse Polish Notation (RPN) expression calculator.
Evaluates mathematical expressions on RRD data sources using RPN notation for efficient computation.
Evaluates mathematical expressions on RRD data sources using RPN notation for efficient computation.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classRpnStack class.private final classState class.private static final classToken class.private static enumToken_Symbol class.Field Summary
FieldsModifier and TypeFieldDescriptionprivate final double[]Calculated valuesprivate final DataProcessorData processorprivate static final PerfectStringHashPerfect hash mapping token text to its symbol.private final StringRpn expressionprivate final StringSource nameSources namesprivate final RpnCalculator.RpnStackThe stack the expression evaluates on.private static final RpnCalculator.Token_Symbol[]Every token, for name lookup.private final long[]Array of timestamps for the data seriesprivate final doubleTime stepprivate final RpnCalculator.Token[]The parsed RPN expression.Constructor Summary
ConstructorsConstructorDescriptionRpnCalculator(String rpnExpression, String sourceName, DataProcessor dataProcessor) Rpn calculatorMethod Summary
Private MethodsModifier and TypeMethodDescription(package private) double[]Calculate valuesprivate RpnCalculator.TokencreateToken(String parsedText) Create tokenprivate doublegetCalendarField(double timestamp, int field) Calendar field value from timestamp.private booleanWhether the stack holds no values.private doublepeek()Examine the top value on the stack without removing itprivate doublepop()Pop a value from the RPN stackprivate voidpush(double x) Push a value onto the RPN stackprivate voidClear all values from the RPN calculation stack
Field Details
symbols
Every token, for name lookup.perfect
Perfect hash mapping token text to its symbol.rpnExpression
Rpn expressionsourceName
Source namedataProcessor
Data processortokens
The parsed RPN expression.stack
The stack the expression evaluates on.calculatedValues
private final double[] calculatedValuesCalculated valuestimestamps
private final long[] timestampsArray of timestamps for the data seriestimeStep
private final double timeStepTime stepsourcesNames
Constructor Details
RpnCalculator
RpnCalculator(String rpnExpression, String sourceName, DataProcessor dataProcessor) Rpn calculator- Parameters:
rpnExpression- the RPN expression, its tokens separated by commassourceName- the data series an unqualified PREV token refers todataProcessor- supplies the timestamps and the per-source value arrays
Method Details
createToken
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 secondsfield- 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 stackisStackEmpty
private boolean isStackEmpty()Whether the stack holds no values.- Returns:
- true if the stack is empty