Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2016 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package java.util.stream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.DoubleSummaryStatistics;
import java.util.HashMap;
import java.util.HashSet;
import java.util.IntSummaryStatistics;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.LongSummaryStatistics;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.StringJoiner;
import java.util.function.BiConsumer;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.function.ToDoubleFunction;
import java.util.function.ToIntFunction;
import java.util.function.ToLongFunction;
/**
* See the
* official Java API doc for details.
*/
public final class Collectors {
public static Collector averagingDouble(ToDoubleFunction super T> mapper) {
// TODO simplify to only collect average if possible
return collectingAndThen(summarizingDouble(mapper), DoubleSummaryStatistics::getAverage);
}
public static Collector averagingInt(ToIntFunction super T> mapper) {
// TODO simplify to only collect average if possible
return collectingAndThen(summarizingInt(mapper), IntSummaryStatistics::getAverage);
}
public static Collector averagingLong(ToLongFunction super T> mapper) {
// TODO simplify to only collect average if possible
return collectingAndThen(summarizingLong(mapper), LongSummaryStatistics::getAverage);
}
public static Collector collectingAndThen(
Collector downstream, Function finisher) {
return new CollectorImpl<>(
downstream.supplier(),
downstream.accumulator(),
downstream.combiner(),
downstream.finisher().andThen(finisher));
}
public static Collector counting() {
// Using Long::sum here fails in JDT
return reducing(0L, item -> 1L, (a, b) -> (Long) a.longValue() + b.longValue());
}
public static Collector>> groupingBy(
Function super T, ? extends K> classifier) {
// TODO inline this and avoid the finisher extra work of copying from a map to another map
// kept separate for now to unify implementations and reduce testing required
return groupingBy(classifier, toList());
}
public static Collector> groupingBy(
Function super T, ? extends K> classifier, Collector super T, A, D> downstream) {
return groupingBy(classifier, HashMap::new, downstream);
}
public static > Collector groupingBy(
Function super T, ? extends K> classifier,
Supplier mapFactory,
Collector super T, A, D> downstream) {
return groupingBy0(() -> {
// cannot use LinkedHashMap::new because javac cannot infer correct
// return type of method reference
return new LinkedHashMap<>();
}, classifier, mapFactory, downstream);
}
private static > Collector groupingBy0(
Supplier