Skip to content

Instantly share code, notes, and snippets.

@newmen
Created October 3, 2019 12:03
Show Gist options
  • Save newmen/db05825a09996d477b1b53103548a4b6 to your computer and use it in GitHub Desktop.
Save newmen/db05825a09996d477b1b53103548a4b6 to your computer and use it in GitHub Desktop.
private Map<String, Map<String, Map<SchemaInternalOperation, List<SchemaCharge>>>> splitTotal(List<SchemaCharge> charges) {
return MapSeq.map(splitByOffer(charges), (String k, List<SchemaCharge> v) -> {
return MapSeq.map(splitByResource(v), w -> splitByOperation(w));
});
}
private Map<String, List<SchemaCharge>> splitByOffer(List<SchemaCharge> charges) {
return MapSeq.orderedGroupBy(charges, SchemaCharge::getOfferId);
}
private Map<String, List<SchemaCharge>> splitByResource(List<SchemaCharge> charges) {
Map<String, List<SchemaCharge>> map = MapSeq.orderedGroupBy(charges, SchemaCharge::getSku);
return MapSeq.map(
map,
chs -> chs.stream()
.sorted(Comparator.comparing(
ch -> ch.getStartDate()
.map(Optional::of)
.orElseGet(ch::getShipmentDate)
.map(LocalDate::parse)
.orElseGet(() -> LocalDate.from(ch.getCreateDatetime()))
))
.collect(Collectors.toList())
);
}
private Map<SchemaInternalOperation, List<SchemaCharge>> splitByOperation(List<SchemaCharge> charges) {
return MapSeq.orderedGroupBy(charges, SchemaCharge::getOperation);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment