Class IterableTokenEvaluator


  • public class IterableTokenEvaluator
    extends TokenEvaluator<Iterable<?>>
    Evaluates a token against an iterable object and returns a value.

    The token can be the index of the item in the iterable (zero based). For example, this expression selects the start date of the first leg of a swap:

       Product.legs.0.startDate
     
    It is also possible to select items based on the value of their properties. For example, SwapLeg has a property payReceive whose value can be PAY or RECEIVE. It is possible to select a leg based on the value of this property:
       Product.legs.pay.startDate     // Pay leg start date
       Product.legs.receive.startDate // Receive leg start date
     
    The comparison between property values and expression values is case-insensitive.

    This works for any property where each item has a unique value. For example, consider a cross-currency swap where one leg has the currency USD and the other has the currency GBP:

       Product.legs.USD.startDate // USD leg start date
       Product.legs.GBP.startDate // GBP leg start date
     
    If both legs have the same currency it would obviously not be possible to use the currency to select a leg.
    • Constructor Detail

      • IterableTokenEvaluator

        public IterableTokenEvaluator()
    • Method Detail

      • tokens

        public Set<String> tokens​(Iterable<?> iterable)
        Description copied from class: TokenEvaluator
        Gets the set of supported token for the given object.
        Specified by:
        tokens in class TokenEvaluator<Iterable<?>>
        Parameters:
        iterable - the object against which tokens may be evaluated
        Returns:
        the set of supported tokens
      • evaluate

        public EvaluationResult evaluate​(Iterable<?> iterable,
                                         CalculationFunctions functions,
                                         String firstToken,
                                         List<String> remainingTokens)
        Description copied from class: TokenEvaluator
        Evaluates a token against a given object.
        Specified by:
        evaluate in class TokenEvaluator<Iterable<?>>
        Parameters:
        iterable - the object against which to evaluate the token
        functions - the calculation functions
        firstToken - the first token of the expression
        remainingTokens - the remaining tokens in the expression, possibly empty
        Returns:
        the result of the evaluation