/**
  * Returns an instance with the specified operation applied to the sensitivity values.
  *
  * <p>The result will consist of the same entries, but with the operator applied to each
  * sensitivity value. This instance is immutable and unaffected by this method.
  *
  * <p>This is used to apply a mathematical operation to the sensitivity values. For example, the
  * operator could multiply the sensitivities by a constant, or take the inverse.
  *
  * <pre>
  *   inverse = base.mapSensitivities(value -> 1 / value);
  * </pre>
  *
  * @param operator the operator to be applied to the sensitivities
  * @return an instance based on this one, with the operator applied to the sensitivity values
  */
 public CurveCurrencyParameterSensitivities mapSensitivities(DoubleUnaryOperator operator) {
   return sensitivities
       .stream()
       .map(s -> s.mapSensitivity(operator))
       .collect(
           Collectors.collectingAndThen(
               Guavate.toImmutableList(), CurveCurrencyParameterSensitivities::new));
 }
Example #2
0
 /**
  * Returns a {@link Collector} that accumulates elements into an {@code ImmutableSortedMap} whose
  * keys and values are the result of applying the provided mapping functions to the input
  * elements.
  *
  * <p>If the mapped keys contain duplicates (according to the comparator), the the values are
  * merged using the specified merging function. Entries will appear in the encounter order of the
  * first occurrence of the key.
  *
  * @since 21.0
  */
 @Beta
 public static <T, K, V> Collector<T, ?, ImmutableSortedMap<K, V>> toImmutableSortedMap(
     Comparator<? super K> comparator,
     Function<? super T, ? extends K> keyFunction,
     Function<? super T, ? extends V> valueFunction,
     BinaryOperator<V> mergeFunction) {
   checkNotNull(comparator);
   checkNotNull(keyFunction);
   checkNotNull(valueFunction);
   checkNotNull(mergeFunction);
   return Collectors.collectingAndThen(
       Collectors.toMap(
           keyFunction, valueFunction, mergeFunction, () -> new TreeMap<K, V>(comparator)),
       ImmutableSortedMap::copyOfSorted);
 }