Skip to content

Instantly share code, notes, and snippets.

@rupertbates
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rupertbates/d2970a005204d8dc5b4a to your computer and use it in GitHub Desktop.
Save rupertbates/d2970a005204d8dc5b4a to your computer and use it in GitHub Desktop.
getContributorCounts method in a functional style
public List<ContributorCount> getContributorCounts(){
List<ArticleView> articleViews = getArticleViews();
return articleViews
.map(a -> a.contributor) //Get the contributor names from the article views
.sort(Ord.stringOrd) //Need to sort before grouping
.group(Equal.stringEqual) //Group by contributor name
.filter(l -> l.length() > 1) //remove any contributors who only appear once
.map(l -> new ContributorCount(l.head(), l.length())); //Map to the return type
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment