Skip to content

Instantly share code, notes, and snippets.

@sunxboy
Created August 21, 2018 02:27
Show Gist options
  • Save sunxboy/ce3a9e5588e42f6ccdbb1b57ff68f20b to your computer and use it in GitHub Desktop.
Save sunxboy/ce3a9e5588e42f6ccdbb1b57ff68f20b to your computer and use it in GitHub Desktop.
java8 collection filter
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);
});
}
@sunxboy
Copy link
Author

sunxboy commented Aug 22, 2018

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());
});
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment