Class RPNWrapper

java.lang.Object
com.caplin.transformer.module.wrappers.RPNWrapper

public class RPNWrapper extends Object

Provides a Java Transformer module access to the Reverse Polish Notation (RPN) C Transformer module. The RPN module is capable of evaluating a rule to calculate a value to use, or to verify whether a certain condition has been met.

A rule is made up of parameters and operators. The parameters can be predefined numbers, or they can be the values of fields from either an update or a cached TransformerData. For example, a Mid price can be calculated using the rule $BID $ASK + 2 /". Alternatively, a check to find out if the Last price for an update is less than the High price for the cached data can be expressed by the rule $TRDPRC_1 @HIGH_1 <.

A rule that evaluates a boolean expression will return TRUE if the expression evaluated to true, or FALSE if it was false.

The possible operators are:

+ Adds two parameters together (e.g. "8 4 +"; result = 12.0)
- Subtracts second parameter from the first (e.g. "8 4 -"; result = 4.0)
* Multiplies two parameters together (e.g. "8 4 *"; result = 32.0)
/ Divides first parameter by the second (e.g. "8 4 /"; result = 2.0)
= Checks if two parameters are equal (e.g. "8 4 ="; result = RPNWrapper.FALSE)
! Checks two parameters are not equal (e.g. "8 4 !"; result = RPNWrapper.TRUE)
{ Checks if first parameter is less than or equal to the second (e.g. "8 4 {"; result = RPNWrapper.FALSE)
} Checks if first parameter is greater than or equal to the second (e.g. "8 4 }"; result = RPNWrapper.TRUE)
< Checks if first parameter is less than the second (e.g. "8 4 <"; result = RPNWrapper.FALSE)
> Checks if first parameter is greater than the second (e.g. "8 4 >"; result = RPNWrapper.TRUE)
& Logically ANDs the two parameters together (e.g. "15 0 &"; result = RPNWrapper.FALSE)
| Logically ORs the two parameters together (e.g. "15 0 |"; result = RPNWrapper.TRUE)
~ Converts a single parameter to its absolute value (e.g. "-4 ~"; result = 4.0)
$FIELDNAME  The value for the specified field name from the current update (e.g. "$BID 100 <")
@FIELDNAME  The value for the specified field name from the cached update (e.g. "$LAST @HIGH >")
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
    Value returned from evaluateRule for a boolean rule for which the result was false.
    static final double
    Value returned from evaluateRule for a boolean rule for which the result was true.
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    evaluateRule(String rule, TransformerData updateData, TransformerData cachedData)
    Evalutes the specified rule and returns the result of the evaluation.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • TRUE

      public static final double TRUE

      Value returned from evaluateRule for a boolean rule for which the result was true.

      See Also:
    • FALSE

      public static final double FALSE

      Value returned from evaluateRule for a boolean rule for which the result was false.

      See Also:
  • Method Details

    • evaluateRule

      public static double evaluateRule(String rule, TransformerData updateData, TransformerData cachedData)

      Evalutes the specified rule and returns the result of the evaluation.

      Parameters:
      rule - The rule to be evaluated.
      updateData - The TransformerData object containing the values for any field names defined in the rule that are prefixed with $.
      cachedData - The TransformerData object containing the values for any field names defined in the rule that are prefixed with @.
      Returns:
      The value evaluated for the rule. If this is a boolean rule, then RPNWrapper.TRUE is returned if the expression was true, otherwise RPNWrapper.FALSE is returned.