-
-
Save tomaszalusky/851beeaab86eb2c37a9c to your computer and use it in GitHub Desktop.
This file contains hidden or 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<Integer,? extends Address> getAddressIndex(Optional<SubjectData> currentSubjectData) { | |
| return currentSubjectData | |
| .map(subjectData -> subjectData | |
| .getAddresses() | |
| .stream() | |
| .filter(address -> address.getEsoId() != null) | |
| .collect(toMap(Address::getEsoId, t -> t)) | |
| ) | |
| .orElse(emptyMap()) | |
| ; | |
| } | |
| // HYPOTHETICAL SOLUTION WITH GUAVA Optional: | |
| private Map<Integer,? extends Address> getAddressIndex(Optional<SubjectData> currentSubjectData) { | |
| return currentSubjectData | |
| .asSet() // Guava Optional's method, in JDK8 must be simulated with map(...).get() | |
| .stream() | |
| .flatMap(sd -> sd.getAddresses().stream()) | |
| .filter(address -> address.getEsoId() != null) | |
| .collect(toMap(Address::getEsoId, t -> t)) | |
| ; | |
| //.orElse(emptyMap()); // unnecessary here, asSet did the work | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment