public static Map<String, List<ForwardSensitivity>> cleanedFwd( final Map<String, List<ForwardSensitivity>> map) { // TODO: improve the sorting algorithm. final Map<String, List<ForwardSensitivity>> result = new HashMap<>(); for (final Map.Entry<String, List<ForwardSensitivity>> entry : map.entrySet()) { final List<ForwardSensitivity> list = entry.getValue(); final List<ForwardSensitivity> listClean = new ArrayList<>(); final Set<Triple<Double, Double, Double>> set = new TreeSet<>(); for (final ForwardSensitivity pair : list) { set.add(new Triple<>(pair.getStartTime(), pair.getEndTime(), pair.getAccrualFactor())); } for (final Triple<Double, Double, Double> time : set) { double sensi = 0; for (int looplist = 0; looplist < list.size(); looplist++) { final ForwardSensitivity fwdSensitivity = list.get(looplist); final Triple<Double, Double, Double> triple = new Triple<>( fwdSensitivity.getStartTime(), fwdSensitivity.getEndTime(), fwdSensitivity.getAccrualFactor()); if (triple.equals(time)) { sensi += list.get(looplist).getValue(); } } listClean.add( new ForwardSensitivity(time.getFirst(), time.getSecond(), time.getThird(), sensi)); } result.put(entry.getKey(), listClean); } return result; }