Class ParameterizedDataCombiner


  • public final class ParameterizedDataCombiner
    extends java.lang.Object
    Helper that can be used to combine two or more underlying instances of ParameterizedData.

    This is used by implementations of ParameterizedData that are based on more than one underlying ParameterizedData instance.

    This helper should be created in the constructor of the combined instance. In each of the five ParameterizedData methods of the combined instance, this helper should be invoked. See DiscountFxForwardRates for sample usage.

    • Method Detail

      • of

        public static ParameterizedDataCombiner of​(ParameterizedData... instances)
        Obtains an instance that can combine the specified underlying instances.
        Parameters:
        instances - the underlying instances to combine
        Returns:
        the combiner
      • of

        public static ParameterizedDataCombiner of​(java.util.List<? extends ParameterizedData> instances)
        Obtains an instance that can combine the specified underlying instances.
        Parameters:
        instances - the underlying instances to combine
        Returns:
        the combiner
      • getParameterCount

        public int getParameterCount()
        Gets the number of parameters.

        This returns the total parameter count of all the instances.

        Returns:
        the number of parameters
      • getParameter

        public double getParameter​(int parameterIndex)
        Gets the value of the parameter at the specified index.

        This gets the parameter from the correct instance.

        Parameters:
        parameterIndex - the zero-based index of the parameter to get
        Returns:
        the value of the parameter
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is invalid
      • getParameterMetadata

        public ParameterMetadata getParameterMetadata​(int parameterIndex)
        Gets the metadata of the parameter at the specified index.

        This gets the parameter metadata from the correct instance.

        Parameters:
        parameterIndex - the zero-based index of the parameter to get
        Returns:
        the metadata of the parameter
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is invalid
      • underlyingWithParameter

        public <R extends ParameterizedData> R underlyingWithParameter​(int underlyingIndex,
                                                                       java.lang.Class<R> underlyingType,
                                                                       int parameterIndex,
                                                                       double newValue)
        Updates a parameter on the specified underlying.

        This should be invoked once for each of the underlying instances. It is intended to be used to pass the result of each invocation to the constructor of the combined instance.

        If the parameter index applies to the underlying, it is updated. If the parameter index does not apply to the underlying, no error occurs.

        Type Parameters:
        R - the type of the underlying
        Parameters:
        underlyingIndex - the index of the underlying instance
        underlyingType - the type of the parameterized data at the specified index
        parameterIndex - the zero-based index of the parameter to change
        newValue - the new value for the specified parameter
        Returns:
        a parameterized data instance based on this with the specified parameter altered
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is invalid
      • underlyingWithPerturbation

        public <R extends ParameterizedData> R underlyingWithPerturbation​(int underlyingIndex,
                                                                          java.lang.Class<R> underlyingType,
                                                                          ParameterPerturbation perturbation)
        Applies a perturbation to the specified underlying.

        This should be invoked once for each of the underlying instances. It is intended to be used to pass the result of each invocation to the constructor of the combined instance.

        Type Parameters:
        R - the type of the underlying
        Parameters:
        underlyingIndex - the index of the underlying instance
        underlyingType - the type of the parameterized data at the specified index
        perturbation - the perturbation to apply
        Returns:
        a parameterized data instance based on this with the specified perturbation applied
      • withParameter

        public <R extends ParameterizedData> java.util.List<R> withParameter​(java.lang.Class<R> underlyingType,
                                                                             int parameterIndex,
                                                                             double newValue)
        Updates a parameter on the specified list of underlying instances.

        The correct underlying is identified and updated, with the list returned.

        Type Parameters:
        R - the type of the underlying
        Parameters:
        underlyingType - the type of the parameterized data at the specified index
        parameterIndex - the zero-based index of the parameter to change
        newValue - the new value for the specified parameter
        Returns:
        a parameterized data instance based on this with the specified parameter altered
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is invalid
      • withPerturbation

        public <R extends ParameterizedData> java.util.List<R> withPerturbation​(java.lang.Class<R> underlyingType,
                                                                                ParameterPerturbation perturbation)
        Applies a perturbation to each underlying.

        The updated list of underlying instances is returned.

        Type Parameters:
        R - the type of the underlying
        Parameters:
        underlyingType - the type of the parameterized data at the specified index
        perturbation - the perturbation to apply
        Returns:
        a parameterized data instance based on this with the specified parameter altered
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is invalid