Source:
public static CurveCurrencyParameterSensitivities linearRebucketing( CurveCurrencyParameterSensitivities sensitivities, List<LocalDate> targetDates) { int nbBuckets = targetDates.size(); List<CurveParameterMetadata> pmdTarget = new ArrayList<>(); for (int i = 0; i < nbBuckets; i++) { pmdTarget.add(SimpleCurveNodeMetadata.of(targetDates.get(i), targetDates.get(i).toString())); } ImmutableList<CurveCurrencyParameterSensitivity> listSensi = sensitivities.getSensitivities(); List<CurveCurrencyParameterSensitivity> sensitivityTarget = new ArrayList<>(); for (CurveCurrencyParameterSensitivity s : listSensi) { double[] rebucketedSensitivityAmounts = new double[nbBuckets]; CurveMetadata m = s.getMetadata(); DoubleArray sa = s.getSensitivity(); ArgChecker.isTrue(m.getParameterMetadata().isPresent(), "parameter metadata must be present"); List<CurveParameterMetadata> lm = m.getParameterMetadata().get(); for (int loopnode = 0; loopnode < sa.size(); loopnode++) { ArgChecker.isTrue(lm.get(loopnode) instanceof DatedCurveParameterMetadata, "re-bucketing require sensitivity date"); DatedCurveParameterMetadata dpm = (DatedCurveParameterMetadata) lm.get(loopnode); LocalDate nodeDate = dpm.getDate(); rebucketingArray(targetDates, nbBuckets, rebucketedSensitivityAmounts, sa.get(loopnode), nodeDate); } CurveCurrencyParameterSensitivity rebucketedSensitivity = CurveCurrencyParameterSensitivity.of( DefaultCurveMetadata.builder().curveName(s.getCurveName()).parameterMetadata(pmdTarget).build(), s.getCurrency(), DoubleArray.ofUnsafe(rebucketedSensitivityAmounts)); sensitivityTarget.add(rebucketedSensitivity); } return CurveCurrencyParameterSensitivities.of(sensitivityTarget); }

Target:
public static CurveCurrencyParameterSensitivities linearRebucketing( CurveCurrencyParameterSensitivities sensitivities, List<LocalDate> targetDates) { checkSortedDates(targetDates); int nbBuckets = targetDates.size(); List<CurveParameterMetadata> pmdTarget = targetDates.stream() .map(date -> SimpleCurveNodeMetadata.of(date, date.toString())) .collect(toList()); ImmutableList<CurveCurrencyParameterSensitivity> sensitivitiesList = sensitivities.getSensitivities(); List<CurveCurrencyParameterSensitivity> sensitivityTarget = new ArrayList<>(); for (CurveCurrencyParameterSensitivity sensitivity : sensitivitiesList) { double[] rebucketedSensitivityAmounts = new double[nbBuckets]; CurveMetadata metadataCurve = sensitivity.getMetadata(); DoubleArray sensitivityAmounts = sensitivity.getSensitivity(); List<CurveParameterMetadata> parameterMetadataList = metadataCurve.getParameterMetadata() .orElseThrow(() -> new IllegalArgumentException("parameter metadata must be present")); for (int loopnode = 0; loopnode < sensitivityAmounts.size(); loopnode++) { CurveParameterMetadata nodeMetadata = parameterMetadataList.get(loopnode); ArgChecker.isTrue(nodeMetadata instanceof DatedCurveParameterMetadata, "re-bucketing requires sensitivity date for node which is of type while 'DatedCurveParameterMetadata' is expected", nodeMetadata.getLabel(), nodeMetadata.getClass().getName()); DatedCurveParameterMetadata datedParameterMetadata = (DatedCurveParameterMetadata) nodeMetadata; LocalDate nodeDate = datedParameterMetadata.getDate(); rebucketingArray(targetDates, rebucketedSensitivityAmounts, sensitivityAmounts.get(loopnode), nodeDate); } CurveCurrencyParameterSensitivity rebucketedSensitivity = CurveCurrencyParameterSensitivity.of( DefaultCurveMetadata.builder().curveName(sensitivity.getCurveName()).parameterMetadata(pmdTarget).build(), sensitivity.getCurrency(), DoubleArray.ofUnsafe(rebucketedSensitivityAmounts)); sensitivityTarget.add(rebucketedSensitivity); } return CurveCurrencyParameterSensitivities.of(sensitivityTarget); }