Created
October 3, 2019 12:03
-
-
Save newmen/db05825a09996d477b1b53103548a4b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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