Example #1
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// Updates a parameter on the specified underlying.
        /// <para>
        /// 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.
        /// </para>
        /// <para>
        /// If the parameter index applies to the underlying, it is updated.
        /// If the parameter index does not apply to the underlying, no error occurs.
        ///
        /// </para>
        /// </summary>
        /// @param <R>  the type of the underlying </param>
        /// <param name="underlyingIndex">  the index of the underlying instance </param>
        /// <param name="underlyingType">  the type of the parameterized data at the specified index </param>
        /// <param name="parameterIndex">  the zero-based index of the parameter to change </param>
        /// <param name="newValue">  the new value for the specified parameter </param>
        /// <returns> a parameterized data instance based on this with the specified parameter altered </returns>
        /// <exception cref="IndexOutOfBoundsException"> if the index is invalid </exception>
        public R underlyingWithParameter <R>(int underlyingIndex, Type <R> underlyingType, int parameterIndex, double newValue) where R : ParameterizedData
        {
            ParameterizedData perturbed = underlyings[underlyingIndex];

            if (findUnderlyingIndex(parameterIndex) == underlyingIndex)
            {
                int adjustment = lookup[underlyingIndex];
                perturbed = perturbed.withParameter(parameterIndex - adjustment, newValue);
            }
            return(underlyingType.cast(perturbed));
        }
Example #2
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// Updates a parameter on the specified list of underlying instances.
        /// <para>
        /// The correct underlying is identified and updated, with the list returned.
        ///
        /// </para>
        /// </summary>
        /// @param <R>  the type of the underlying </param>
        /// <param name="underlyingType">  the type of the parameterized data at the specified index </param>
        /// <param name="parameterIndex">  the zero-based index of the parameter to change </param>
        /// <param name="newValue">  the new value for the specified parameter </param>
        /// <returns> a parameterized data instance based on this with the specified parameter altered </returns>
        /// <exception cref="IndexOutOfBoundsException"> if the index is invalid </exception>
        public IList <R> withParameter <R>(Type <R> underlyingType, int parameterIndex, double newValue) where R : ParameterizedData
        {
            int underlyingIndex = findUnderlyingIndex(parameterIndex);

            ImmutableList.Builder <R> builder = ImmutableList.builder();
            for (int i = 0; i < underlyings.Length; i++)
            {
                ParameterizedData underlying = underlyings[i];
                if (i == underlyingIndex)
                {
                    int adjustment = lookup[underlyingIndex];
                    ParameterizedData perturbed = underlying.withParameter(parameterIndex - adjustment, newValue);
                    builder.add(underlyingType.cast(perturbed));
                }
                else
                {
                    builder.add(underlyingType.cast(underlying));
                }
            }
            return(builder.build());
        }