/** * Builds a list of curve group definitions from the map of curves and their keys. * <p> * The keys specify which curve groups each curve belongs to and how it is used in the group, for example * as a discount curve for a particular currency or as a forward curve for an index. * * @param garMap the map of name to keys * @return a map of curve group name to curve group definition built from the curves */ private static ImmutableList<RatesCurveGroupDefinition> buildCurveGroups( Map<CurveName, Set<GroupAndReference>> garMap) { Multimap<CurveGroupName, RatesCurveGroupEntry> groups = LinkedHashMultimap.create(); for (Map.Entry<CurveName, Set<GroupAndReference>> entry : garMap.entrySet()) { CurveName curveName = entry.getKey(); Set<GroupAndReference> curveIds = entry.getValue(); Map<CurveGroupName, List<GroupAndReference>> idsByGroup = curveIds.stream().collect(groupingBy(p -> p.groupName)); for (Map.Entry<CurveGroupName, List<GroupAndReference>> groupEntry : idsByGroup.entrySet()) { CurveGroupName groupName = groupEntry.getKey(); List<GroupAndReference> gars = groupEntry.getValue(); groups.put(groupName, curveGroupEntry(curveName, gars)); } } return MapStream.of(groups.asMap()) .map((name, entry) -> RatesCurveGroupDefinition.of(name, entry, ImmutableList.of())) .collect(toImmutableList()); }
MapStream.empty().spliterator(); MapStream.empty().isParallel(); MapStream.empty().map(e -> e); MapStream.empty().mapToInt(e -> 0); MapStream.empty().mapToLong(e -> 0);
/** * Obtains an instance from a map of currency to amount. * * @param map the map of currency to amount * @return the amount */ public static MultiCurrencyAmount of(Map<Currency, Double> map) { ArgChecker.noNulls(map, "map"); return MapStream.of(map).map(CurrencyAmount::of).collect(MultiCurrencyAmount.collectorInternal()); }
public void map() { List<String> expected = ImmutableList.of("one1", "two2", "three3", "four4"); List<String> result = MapStream.of(map).map((k, v) -> k + v).collect(toList()); assertThat(result).isEqualTo(expected); }
public void flatMapKeysAndValuesToValues() { List<Pair<String, String>> expected = ImmutableList.of( Pair.of("one", "one"), Pair.of("one", "1"), Pair.of("two", "two"), Pair.of("two", "2"), Pair.of("three", "three"), Pair.of("three", "3"), Pair.of("four", "four"), Pair.of("four", "4")); List<Pair<String, String>> result = MapStream.of(map) .flatMapValues((key, value) -> Stream.of(key, Integer.toString(value))) .map((k, v) -> Pair.of(k, v)) .collect(toList()); assertThat(result).isEqualTo(expected); }
public void flatMapValuesToValues() { List<Pair<String, Integer>> expected = ImmutableList.of( Pair.of("one", 1), Pair.of("one", 1), Pair.of("two", 2), Pair.of("two", 4), Pair.of("three", 3), Pair.of("three", 9), Pair.of("four", 4), Pair.of("four", 16)); List<Pair<String, Integer>> result = MapStream.of(map) .flatMapValues(value -> Stream.of(value, value * value)) .map((k, v) -> Pair.of(k, v)) .collect(toList()); assertThat(result).isEqualTo(expected); }