Skip to content

Instantly share code, notes, and snippets.

@stevenwcarter
Last active May 12, 2016 01:23
Show Gist options
  • Save stevenwcarter/9ebb46c1e25d3b71e1b44d907de00ed0 to your computer and use it in GitHub Desktop.
Save stevenwcarter/9ebb46c1e25d3b71e1b44d907de00ed0 to your computer and use it in GitHub Desktop.
Java 7 -> 8
// Old way of writing it
List<PartFilter> partFilters = FilterQueryBuilder.getFilters(PartFilter.class, clonedFilters);
for (PartFilter f : partFilters) {
if (f.getPartTerms() != null) {
f.getPartTerms().remove("sub_category");
}
}
// New way with Java 8 Stream API and Lambda functions
FilterQueryBuilder.getFilters(PartFilter.class, clonedFilters).stream()
.filter(f -> f.getPartTerms() != null)
.forEach(filter -> filter.getPartTerms().remove("sub_category"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment