/** * 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()); }