Created
August 21, 2018 02:27
-
-
Save sunxboy/ce3a9e5588e42f6ccdbb1b57ff68f20b to your computer and use it in GitHub Desktop.
java8 collection filter
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 void cleanDeadData(List<BcpResend> list) { | |
java.util.Set<String> grupingThanFilter = | |
list.stream().collect(Collectors.collectingAndThen(Collectors.groupingBy(BcpResend::getCid, Collectors.counting()), map -> { | |
map.values().removeIf(l -> l < 50); | |
return map.keySet(); | |
})); | |
grupingThanFilter.forEach(cid -> { | |
repository.deleteByCid(cid); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
private void cleanDeadData(List list) {
java.util.Set<Optional> grupingThanFilter =
list.stream()
.collect(Collectors.collectingAndThen(
Collectors.groupingBy((c -> Optional.ofNullable(c.getCid())), Collectors.counting())
, map -> {
map.values().removeIf(l -> l < 50);
return map.keySet();
}));
grupingThanFilter.stream()
.filter(Optional::isPresent)
.forEach(cid -> {
repository.deleteByCid(cid.get());
});
}