a-foundation/src/main/java/com/ajjpj/afoundation/collection/ACollectionHelper.java
public static <T, X, E extends Throwable> Map<X, Collection<T>> groupBy (Iterable<T> coll, AFunction1<? super T, ? extends X, E> f) throws E {
        final Map<X, Collection<T>> result = new HashMap<>();
        for(T o: coll) {
            final X key = f.apply(o);
            Collection<T> perKey = result.get(key);
            if(perKey == null) {
                perKey = new ArrayList<>();
                result.put(key, perKey);
            }
            perKey.add(o);
        }
        return result;
    }
public static <T, X, E extends Throwable> Map<X, Collection<T>> groupBy (Iterable<T> coll, AFunction1<? super T, ? extends X, E> f) throws E {
        final Map<X, Collection<T>> result = new HashMap<>();
        for(T o: coll) {
            final X key = f.apply(o);
            Collection<T> perKey = result.get(key);
            if(perKey == null) {
                perKey = new ArrayList<>();
                result.put(key, perKey);
            }
            perKey.add(o);
        }
        return result;
    }
public static < T , X , E extends Throwable > Map < X , Collection < T > > groupBy ( Iterable < T > coll , AFunction1 < ? super T , ? extends X , E > f ) throws E { final Map < X , Collection < T > > result = new HashMap <> ( ) ; for ( T o : coll ) { final X key = f . apply ( o ) ; Collection < T > perKey = result . get ( key ) ; if ( perKey == null ) { perKey = new ArrayList <> ( ) ; result . put ( key , perKey ) ; } perKey . add ( o ) ; } return result ; }
Creates a Map from a collection. Each element's key is determined by applying a function to the element. All
elements with the same key are stored as that key's value in the returned Map.
Creates a Map from a collection . Each element s key is determined by applying a function to the element . All elements with the same key are stored as that key s value in the returned Map .