/** * Checks and adjusts the parameter metadata. * <p> * The supplied function is invoked for each parameter metadata in this sensitivities. * If the function returns the same metadata for two different inputs, the sensitivity values will be summed. * A typical use case would be to normalize parameter metadata tenors to be valid for an underlying system. * * @param mdFn the function for checking and adjusting the metadata * @return the adjusted sensitivity * @throws IllegalArgumentException if any metadata instance is empty * @throws RuntimeException if the function throws an exception */ public CurrencyParameterSensitivities withParameterMetadatas(UnaryOperator<ParameterMetadata> mdFn) { return toBuilder().mapMetadata(mdFn).build(); }
public void test_builder_mapMetadata() { CurrencyParameterSensitivity entry1 = CurrencyParameterSensitivity.of(NAME1, METADATA1B, USD, DoubleArray.of(0, 1, 2, 3)); CurrencyParameterSensitivity expected = CurrencyParameterSensitivity.of(NAME1, ImmutableList.of(TENOR_MD_1Y), USD, DoubleArray.of(6)); CurrencyParameterSensitivities test = CurrencyParameterSensitivities.builder() .add(entry1) .mapMetadata(md -> TENOR_MD_1Y) .build(); assertEquals(test.getSensitivities().size(), 1); assertEquals(test.getSensitivities().get(0), expected); }