Class CalculationParameters

  • All Implemented Interfaces:
    java.io.Serializable, Bean, ImmutableBean

    public final class CalculationParameters
    extends java.lang.Object
    implements ImmutableBean, java.io.Serializable
    The calculation parameters.

    This provides a set of parameters that will be used in a calculation. Each parameter defines a query type, thus the functions are keyed in a Map by the query type Class.

    Parameters exist to provide control over the calculation. For example, ReportingCurrency is a parameter that controls currency conversion. If specified, on a Column, or in CalculationRules, then the output will be converted to the specified currency.

    See Also:
    Serialized Form
    • Method Detail

      • empty

        public static CalculationParameters empty()
        Obtains an empty instance with no parameters.
        Returns:
        the empty instance
      • of

        public static CalculationParameters of​(CalculationParameter... parameters)
        Obtains an instance from the specified parameters.

        The list will be converted to a Map using CalculationParameter.queryType(). Each parameter must refer to a different query type.

        If a parameter implements an interface that also extends CalculationParameter, that type will also be able to be searched for (unless it has been directly registered).

        Parameters:
        parameters - the parameters
        Returns:
        the calculation parameters
        Throws:
        java.lang.IllegalArgumentException - if two parameters have same query type
      • of

        public static CalculationParameters of​(java.util.List<? extends CalculationParameter> parameters)
        Obtains an instance from the specified parameters.

        The list will be converted to a Map using CalculationParameter.queryType(). Each parameter must refer to a different query type.

        If a parameter implements an interface that also extends CalculationParameter, that type will also be able to be searched for (unless it has been directly registered).

        Parameters:
        parameters - the parameters
        Returns:
        the calculation parameters
        Throws:
        java.lang.IllegalArgumentException - if two parameters have same query type
      • combinedWith

        public CalculationParameters combinedWith​(CalculationParameters other)
        Combines this set of parameters with the specified set.

        This set of parameters takes priority.

        Parameters:
        other - the other parameters
        Returns:
        the combined calculation parameters
      • with

        public CalculationParameters with​(CalculationParameter parameter)
        Returns a copy of this instance with the specified parameter added.

        If this instance already has a parameter with the query type, it will be replaced.

        Parameters:
        parameter - the parameter to add
        Returns:
        the new instance based on this with the parameter added
      • without

        public CalculationParameters without​(java.lang.Class<? extends CalculationParameter> type)
        Filters the parameters, returning a set without the specified type.
        Parameters:
        type - the type to remove
        Returns:
        the filtered calculation parameters
      • filter

        public CalculationParameters filter​(CalculationTarget target,
                                            Measure measure)
        Filters the parameters, matching only those that are applicable for the target and measure.

        The resulting parameters are filtered to the target and measure. The implementation of each parameter may be changed by this process. If two parameters are filtered to the same query type then an exception will be thrown

        Parameters:
        target - the calculation target, such as a trade
        measure - the measure to be calculated
        Returns:
        the filtered calculation parameters
        Throws:
        java.lang.IllegalArgumentException - if two parameters are filtered to the same query type
      • findParameter

        public <T extends CalculationParameter> java.util.Optional<T> findParameter​(java.lang.Class<T> type)
        Finds the parameter that matches the specified query type.

        This method may throw an exception if the parameters have not been filtered.

        Type Parameters:
        T - the type of the parameter
        Parameters:
        type - the query type to find
        Returns:
        the parameter
      • getParameter

        public <T extends CalculationParameter> T getParameter​(java.lang.Class<T> type)
        Returns the parameter that matches the specified query type throwing an exception if not available.

        This method may throw an exception if the parameters have not been filtered.

        Type Parameters:
        T - the type of the parameter
        Parameters:
        type - the query type to return
        Returns:
        the parameter
        Throws:
        java.lang.IllegalArgumentException - if no parameter if found for the type
      • getParameters

        public com.google.common.collect.ImmutableMap<java.lang.Class<? extends CalculationParameter>,​CalculationParameter> getParameters()
        Gets the parameters, keyed by query type.
        Returns:
        the value of the property, not null
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object