/** * Returns a {@code DoubleCollector} implementing a cascaded "group by" * operation on input numbers, grouping them according to a classification * function, and then performing a reduction operation on the values * associated with a given key using the specified downstream * {@code IntCollector}. * * <p> * The classification function maps elements to some key type {@code K}. The * downstream collector produces a result of type {@code D}. The resulting * collector produces a {@code Map<K, D>}. * * <p> * There are no guarantees on the type, mutability, serializability, or * thread-safety of the {@code Map} returned. * * @param <K> the type of the keys * @param <A> the intermediate accumulation type of the downstream collector * @param <D> the result type of the downstream reduction * @param classifier a classifier function mapping input elements to keys * @param downstream a {@code DoubleCollector} implementing the downstream * reduction * @return a {@code DoubleCollector} implementing the cascaded group-by * operation */ static <K, D, A> DoubleCollector<?, Map<K, D>> groupingBy(DoubleFunction<? extends K> classifier, DoubleCollector<A, D> downstream) { return groupingBy(classifier, HashMap::new, downstream); }
/** * Returns a {@code DoubleCollector} implementing a "group by" operation on * input numbers, grouping them according to a classification function, and * returning the results in a {@code Map}. * * <p> * The classification function maps elements to some key type {@code K}. The * collector produces a {@code Map<K, double[]>} whose keys are the values * resulting from applying the classification function to the input numbers, * and whose corresponding values are arrays containing the input numbers * which map to the associated key under the classification function. * * <p> * There are no guarantees on the type, mutability, serializability, or * thread-safety of the {@code Map} objects returned. * * @param <K> the type of the keys * @param classifier the classifier function mapping input elements to keys * @return a {@code DoubleCollector} implementing the group-by operation */ static <K> DoubleCollector<?, Map<K, double[]>> groupingBy(DoubleFunction<? extends K> classifier) { return groupingBy(classifier, toArray()); }