@@ -0,0 +1,1730 @@
+package com.insightfullogic.java8.answers.chapter5;%0D%0A%0D%0Aimport java.util.ArrayList;%0D%0Aimport java.util.HashMap;%0D%0Aimport java.util.HashSet;%0D%0Aimport java.util.List;%0D%0Aimport java.util.Map;%0D%0Aimport java.util.Set;%0D%0Aimport java.util.function.BiConsumer;%0D%0Aimport java.util.function.BinaryOperator;%0D%0Aimport java.util.function.Function;%0D%0Aimport java.util.function.Supplier;%0D%0Aimport java.util.stream.Collector;%0D%0A%0D%0Apublic class GroupingBy%3CT, K%3E implements Collector%3CT, Map%3CK, List%3CT%3E%3E, Map%3CK, List%3CT%3E%3E%3E %7B%0D%0A%0D%0A%09private final static Set%3CCharacteristics%3E characteristics = new HashSet%3C%3E();%0D%0A%09static %7B%0D%0A%09%09characteristics.add(Characteristics.IDENTITY_FINISH);%0D%0A%09%7D%0D%0A%0D%0A%09private final Function%3C? super T, ? extends K%3E classifier;%0D%0A%0D%0A%09public GroupingBy(Function%3C? super T, ? extends K%3E classifier) %7B%0D%0A%09%09this.classifier = classifier;%0D%0A%09%7D%0D%0A%0D%0A%09@Override%0D%0A%09public Supplier%3CMap%3CK, List%3CT%3E%3E%3E supplier() %7B%0D%0A%09%09return HashMap::new;%0D%0A%09%7D%0D%0A%0D%0A%09@Override%0D%0A%09public BiConsumer%3CMap%3CK, List%3CT%3E%3E, T%3E accumulator() %7B%0D%0A%09%09return (map, element) -%3E %7B%0D%0A%09%09%09K key = classifier.apply(element);%0D%0A%09%09%09List%3CT%3E elements = map.computeIfAbsent(key, k -%3E new ArrayList%3C%3E());%0D%0A%09%09%09elements.add(element);%0D%0A%09%09%7D;%0D%0A%09%7D%0D%0A%0D%0A%09@Override%0D%0A%09public BinaryOperator%3CMap%3CK, List%3CT%3E%3E%3E combiner() %7B%0D%0A%09%09return (left,right)-%3E%7B%0D%0A%09%09%09right.forEach((key,value)-%3E%7B%0D%0A%09%09%09%09left.merge(key, value, (leftValue,rightValue)-%3E%7B%0D%0A%09%09%09%09%09leftValue.addAll(rightValue);%0D%0A%09%09%09%09%09return leftValue;%0D%0A%09%09%09%09%7D);%0D%0A%09%09%09%7D);%0D%0A%09%09%09return left;%0D%0A%09%09%7D;%0D%0A%09%7D%0D%0A%0D%0A%09@Override%0D%0A%09public Function%3CMap%3CK, List%3CT%3E%3E, Map%3CK, List%3CT%3E%3E%3E finisher() %7B%0D%0A%09%09// TODO Auto-generated method stub%0D%0A%09%09return null;%0D%0A%09%7D%0D%0A%0D%0A%09@Override%0D%0A%09public Set%3Cjava.util.stream.Collector.Characteristics%3E characteristics() %7B%0D%0A%09%09// TODO Auto-generated method stub%0D%0A%09%09return null;%0D%0A%09%7D%0D%0A%0D%0A%7D%0D%0A

add GroupingBy<T, K> class for chapter5