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 theCalculationTarget
. As such, the default implementation is essentially aMap
where the keys are the target typeClass
that the function operates on.


Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default CalculationFunctions
composedWith(CalculationFunctions other)
Returns a set of calculation functions which combines the functions in this set with the functions in another.default CalculationFunctions
composedWith(DerivedCalculationFunction<?,?>... functions)
Returns a set of calculation functions which combines the functions in this set with some derived calculation functions.default CalculationFunctions
composedWith(List<DerivedCalculationFunction<?,?>> functions)
Returns a set of calculation functions which combines the functions in this set with some derived calculation functions.static CalculationFunctions
empty()
Obtains an empty instance with no functions.<T extends CalculationTarget>
Optional<CalculationFunction<? super T>>findFunction(T target)
Finds the function that handles the specified target.default <T extends CalculationTarget>
CalculationFunction<? super T>getFunction(T target)
Gets the function that handles the specified target.static CalculationFunctions
of(CalculationFunction<?>... functions)
Obtains an instance from the specified functions.static CalculationFunctions
of(List<? extends CalculationFunction<?>> functions)
Obtains an instance from the specified functions.static CalculationFunctions
of(Map<Class<?>,? extends CalculationFunction<?>> functions)
Obtains an instance from the specified functions.



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 aMap
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(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 aMap
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(Map<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 withCalculationFunction.targetType()
. Parameters:
functions
 the functions Returns:
 the calculation functions

getFunction
default <T extends CalculationTarget> CalculationFunction<? 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> 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 functionfnB
they must be passed to this method in the orderfnB, fnA
. Parameters:
functions
 the functions Returns:
 a set of calculation functions which combines the functions in this set with some derived calculation functions

composedWith
default CalculationFunctions composedWith(List<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 functionfnB
they must be passed to this method in the orderfnB, fnA
. Parameters:
functions
 the functions Returns:
 a set of calculation functions which combines the functions in this set with some derived calculation functions

