/** * Gets the metadata of the parameter at the specified index. * <p> * This gets the parameter metadata from the correct instance. * * @param parameterIndex the zero-based index of the parameter to get * @return the metadata of the parameter * @throws IndexOutOfBoundsException if the index is invalid */ public ParameterMetadata getParameterMetadata(int parameterIndex) { int underlyingIndex = findUnderlyingIndex(parameterIndex); int adjustment = lookup[underlyingIndex]; return underlyings[underlyingIndex].getParameterMetadata(parameterIndex - adjustment); }
/** * Gets the value of the parameter at the specified index. * <p> * This gets the parameter from the correct instance. * * @param parameterIndex the zero-based index of the parameter to get * @return the value of the parameter * @throws IndexOutOfBoundsException if the index is invalid */ public double getParameter(int parameterIndex) { int underlyingIndex = findUnderlyingIndex(parameterIndex); int adjustment = lookup[underlyingIndex]; return underlyings[underlyingIndex].getParameter(parameterIndex - adjustment); }
/** * Updates a parameter on the specified list of underlying instances. * <p> * The correct underlying is identified and updated, with the list returned. * * @param <R> the type of the underlying * @param underlyingType the type of the parameterized data at the specified index * @param parameterIndex the zero-based index of the parameter to change * @param newValue the new value for the specified parameter * @return a parameterized data instance based on this with the specified parameter altered * @throws IndexOutOfBoundsException if the index is invalid */ public <R extends ParameterizedData> List<R> withParameter( Class<R> underlyingType, int parameterIndex, double newValue) { 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(); }
/** * Updates a parameter on the specified underlying. * <p> * 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. * <p> * If the parameter index applies to the underlying, it is updated. * If the parameter index does not apply to the underlying, no error occurs. * * @param <R> the type of the underlying * @param underlyingIndex the index of the underlying instance * @param underlyingType the type of the parameterized data at the specified index * @param parameterIndex the zero-based index of the parameter to change * @param newValue the new value for the specified parameter * @return a parameterized data instance based on this with the specified parameter altered * @throws IndexOutOfBoundsException if the index is invalid */ public <R extends ParameterizedData> R underlyingWithParameter( int underlyingIndex, Class<R> underlyingType, int parameterIndex, double newValue) { ParameterizedData perturbed = underlyings[underlyingIndex]; if (findUnderlyingIndex(parameterIndex) == underlyingIndex) { int adjustment = lookup[underlyingIndex]; perturbed = perturbed.withParameter(parameterIndex - adjustment, newValue); } return underlyingType.cast(perturbed); }