Last active
April 15, 2016 08:52
-
-
Save pdemanget/18cd1df4d69c4ef9cfa64287511a14de to your computer and use it in GitHub Desktop.
Revisions
-
pdemanget revised this gist
Apr 15, 2016 . 1 changed file with 8 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ /** * Group on 2 levels */ protected <K,V> Map<K, Map<K,List<V>>> groupByFields2 (List<V> modelList,Function<? super V, ? extends K> classifier1,Function<? super V, ? extends K> classifier2) { @@ -9,4 +9,11 @@ protected <K,V> Map<K, Map<K,List<V>>> groupByFields2 (List<V> modelList,Functio ,groupingBy2 ); return modelList.stream().collect(groupingBy); } /* Simple Example */ public static void main (String[] args) { Map map = groupByFields2(new ArrayList(Currency.getAvailableCurrencies()) , Currency::getDefaultFractionDigits, Currency::getDisplayName); System.out.println(map.toString().replace("{","\n{")); } -
pdemanget created this gist
Apr 15, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ /** * grouper sur 2 niveaux */ protected <K,V> Map<K, Map<K,List<V>>> groupByFields2 (List<V> modelList,Function<? super V, ? extends K> classifier1,Function<? super V, ? extends K> classifier2) { Collector<V, ?, Map<K, List<V>>> groupingBy2 = Collectors.groupingBy(classifier2); Collector<V, ?, Map<K, Map<K,List<V>>>> groupingBy = Collectors.groupingBy( classifier1 ,groupingBy2 ); return modelList.stream().collect(groupingBy); }