Last active
August 29, 2015 14:10
-
-
Save rupertbates/d2970a005204d8dc5b4a to your computer and use it in GitHub Desktop.
getContributorCounts method in a functional style
This file contains 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
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