Interface CalculationFunctions


  • public interface CalculationFunctions
    The calculation functions.

    This provides the complete set of functions that will be used in a calculation.

    The default implementation is accessed by the static factory methods. It matches the CalculationFunction by the type of the CalculationTarget. As such, the default implementation is essentially a Map where the keys are the target type Class that the function operates on.

    • Method Detail

      • empty

        static CalculationFunctions empty()
        Obtains an empty instance with no functions.
        Returns:
        the empty instance
      • of

        static CalculationFunctions of​(CalculationFunction<?>... functions)
        Obtains an instance from the specified functions.

        This returns an implementation that matches the function by the type of the target, as returned by CalculationFunction.targetType(). The list will be converted to a Map keyed by the target type. Each function must refer to a different target type.

        Parameters:
        functions - the functions
        Returns:
        the calculation functions
      • of

        static CalculationFunctions of​(java.util.List<? extends CalculationFunction<?>> functions)
        Obtains an instance from the specified functions.

        This returns an implementation that matches the function by the type of the target, as returned by CalculationFunction.targetType(). The list will be converted to a Map keyed by the target type. Each function must refer to a different target type.

        Parameters:
        functions - the functions
        Returns:
        the calculation functions
      • of

        static CalculationFunctions of​(java.util.Map<java.lang.Class<?>,​? extends CalculationFunction<?>> functions)
        Obtains an instance from the specified functions.

        This returns an implementation that matches the function by the type of the target. When finding the matching function, the target type is looked up in the specified map. The map will be validated to ensure the Class is consistent with CalculationFunction.targetType().

        Parameters:
        functions - the functions
        Returns:
        the calculation functions
      • getFunction

        default <T extends CalculationTargetCalculationFunction<? super T> getFunction​(T target)
        Gets the function that handles the specified target.

        If no function is found, a suitable default that can perform no calculations is provided.

        Type Parameters:
        T - the target type
        Parameters:
        target - the calculation target, such as a trade
        Returns:
        the function
      • findFunction

        <T extends CalculationTarget> java.util.Optional<CalculationFunction<? super T>> findFunction​(T target)
        Finds the function that handles the specified target.

        If no function is found the result is empty.

        Type Parameters:
        T - the target type
        Parameters:
        target - the calculation target, such as a trade
        Returns:
        the function, empty if not found
      • composedWith

        default CalculationFunctions composedWith​(CalculationFunctions other)
        Returns a set of calculation functions which combines the functions in this set with the functions in another.

        If both sets of functions contain a function for a target then the function from this set is returned.

        Parameters:
        other - another set of calculation functions
        Returns:
        a set of calculation functions which combines the functions in this set with the functions in the other
      • composedWith

        default CalculationFunctions composedWith​(DerivedCalculationFunction<?,​?>... functions)
        Returns a set of calculation functions which combines the functions in this set with some derived calculation functions.

        Each derived function calculates one measure for one type of target, possibly using other calculated measures as inputs.

        If any of the derived functions depend on each other they must be passed to this method in the correct order to ensure their dependencies can be satisfied. For example, if there is a derived function fnA which depends on the measure calculated by function fnB they must be passed to this method in the order fnB, fnA.

        Parameters:
        functions - the functions
        Returns:
        a set of calculation functions which combines the functions in this set with some derived calculation functions