Collector<T, ?, ConcurrentMap<K, List<T>>> groupingByConcurrent(Function<? super T, ? extends K> classifier) { return groupingByConcurrent(classifier, concHashMapNew(), toList());
/** * Returns a {@code Collector} that accumulates the input elements into a * new {@code List}. There are no guarantees on the type, mutability, * serializability, or thread-safety of the {@code List} returned; if more * control over the returned {@code List} is required, use {@link #toCollection(Supplier)}. * * @param <T> the type of the input elements * @return a {@code Collector} which collects all the input elements into a * {@code List}, in encounter order */ public static <T> Collector<T, ?, List<T>> toList() { return new CollectorImpl<>(arrayListNew(), listAdd(), (left, right) -> { left.addAll(right); return left; }, CH_ID); }
Objects.requireNonNull(valueMapper, "valueMapper"); Objects.requireNonNull(mergeFunction, "mergeFunction"); return collectingAndThen( toMap(keyMapper, valueMapper, mergeFunction, hashMapNew()), Collectors.<K, U>unmodMapFinisher());
/** * Returns a {@code Collector} which partitions the input elements according * to a {@code Predicate}, and organizes them into a * {@code Map<Boolean, List<T>>}. * * The returned {@code Map} always contains mappings for both * {@code false} and {@code true} keys. * There are no guarantees on the type, mutability, * serializability, or thread-safety of the {@code Map} or {@code List} * returned. * * <p><b>API Note:</b><br> * If a partition has no elements, its value in the result Map will be * an empty List. * * @param <T> the type of the input elements * @param predicate a predicate used for classifying input elements * @return a {@code Collector} implementing the partitioning operation * * @see #partitioningBy(Predicate, Collector) */ public static <T> Collector<T, ?, Map<Boolean, List<T>>> partitioningBy(Predicate<? super T> predicate) { return partitioningBy(predicate, toList()); }
return groupingBy(classifier, toList());
Set<ESearchType> getRequestedSearchTypes() { Set<ESearchType> requestedSearchTypes = EnumSet.noneOf(ESearchType.class); for (LinkedList<SoldierRequest> classRequests : requestsByClass) { requestedSearchTypes.addAll(stream(classRequests).map(SoldierRequest::getSearchType).collect(Collectors.toList())); } return requestedSearchTypes; }
@Override public final double sum() { /* * In the arrays allocated for the collect operation, index 0 * holds the high-order bits of the running sum, index 1 holds * the low-order bits of the sum computed via compensated * summation, and index 2 holds the simple sum used to compute * the proper result if the stream contains infinite values of * the same sign. */ double[] summation = collect(() -> new double[3], (ll, d) -> { Collectors.sumWithCompensation(ll, d); ll[2] += d; }, (ll, rr) -> { Collectors.sumWithCompensation(ll, rr[0]); Collectors.sumWithCompensation(ll, rr[1]); ll[2] += rr[2]; }); return Collectors.computeFinalSum(summation); }
Objects.requireNonNull(keyMapper, "keyMapper"); Objects.requireNonNull(valueMapper, "valueMapper"); return collectingAndThen( toMap(keyMapper, valueMapper), unmodMapFinisher());
Collector<T, ?, ConcurrentMap<K, D>> groupingByConcurrent(Function<? super T, ? extends K> classifier, Collector<? super T, A, D> downstream) { return groupingByConcurrent(classifier, concHashMapNew(), downstream);
Function<? super T, ? extends U> valueMapper, BinaryOperator<U> mergeFunction) { return toConcurrentMap(keyMapper, valueMapper, mergeFunction, concHashMapNew());
/** * Returns a {@code Collector} which performs a reduction of its * input elements under a specified {@code BinaryOperator} using the * provided identity. * * <p><b>API Note:</b><br> * The {@code reducing()} collectors are most useful when used in a * multi-level reduction, downstream of {@code groupingBy} or * {@code partitioningBy}. To perform a simple reduction on a stream, * use {@link Stream#reduce(Object, BinaryOperator)}} instead. * * @param <T> element type for the input and output of the reduction * @param identity the identity value for the reduction (also, the value * that is returned when there are no input elements) * @param op a {@code BinaryOperator<T>} used to reduce the input elements * @return a {@code Collector} which implements the reduction operation * * @see #reducing(BinaryOperator) * @see #reducing(Object, Function, BinaryOperator) */ public static <T> Collector<T, ?, T> reducing(T identity, BinaryOperator<T> op) { return new CollectorImpl<>( boxSupplier(identity), (a, t) -> { a[0] = op.apply(a[0], t); }, (a, b) -> { a[0] = op.apply(a[0], b[0]); return a; }, a -> a[0], CH_NOID); }
@SuppressWarnings("unchecked") private static <K, V> Supplier<Map<K, V>> concHashMapNew2() { return (Supplier<Map<K, V>>) (Supplier<?>) concHashMapNew(); }
List<OccupierPlace> getPlaces() { List<OccupierPlace> places = new LinkedList<>(); places.addAll(stream(requestsByClass[0]).map(request -> request.place).collect(Collectors.toList())); places.addAll(stream(requestsByClass[0]).map(request -> request.place).collect(Collectors.toList())); return places; } }
/** * Returns a {@code Collector} which partitions the input elements according * to a {@code Predicate}, and organizes them into a * {@code Map<Boolean, List<T>>}. * * The returned {@code Map} always contains mappings for both * {@code false} and {@code true} keys. * There are no guarantees on the type, mutability, * serializability, or thread-safety of the {@code Map} or {@code List} * returned. * * <p><b>API Note:</b><br> * If a partition has no elements, its value in the result Map will be * an empty List. * * @param <T> the type of the input elements * @param predicate a predicate used for classifying input elements * @return a {@code Collector} implementing the partitioning operation * * @see #partitioningBy(Predicate, Collector) */ public static <T> Collector<T, ?, Map<Boolean, List<T>>> partitioningBy(Predicate<? super T> predicate) { return partitioningBy(predicate, toList()); }
return groupingBy(classifier, toList());
@Override public final double sum() { /* * In the arrays allocated for the collect operation, index 0 * holds the high-order bits of the running sum, index 1 holds * the low-order bits of the sum computed via compensated * summation, and index 2 holds the simple sum used to compute * the proper result if the stream contains infinite values of * the same sign. */ double[] summation = collect(() -> new double[3], (ll, d) -> { Collectors.sumWithCompensation(ll, d); ll[2] += d; }, (ll, rr) -> { Collectors.sumWithCompensation(ll, rr[0]); Collectors.sumWithCompensation(ll, rr[1]); ll[2] += rr[2]; }); return Collectors.computeFinalSum(summation); }
Objects.requireNonNull(keyMapper, "keyMapper"); Objects.requireNonNull(valueMapper, "valueMapper"); return collectingAndThen( toMap(keyMapper, valueMapper), unmodMapFinisher());
Collector<T, ?, ConcurrentMap<K, D>> groupingByConcurrent(Function<? super T, ? extends K> classifier, Collector<? super T, A, D> downstream) { return groupingByConcurrent(classifier, concHashMapNew(), downstream);
Function<? super T, ? extends U> valueMapper, BinaryOperator<U> mergeFunction) { return toConcurrentMap(keyMapper, valueMapper, mergeFunction, concHashMapNew());
/** * Returns a {@code Collector} which performs a reduction of its * input elements under a specified {@code BinaryOperator} using the * provided identity. * * <p><b>API Note:</b><br> * The {@code reducing()} collectors are most useful when used in a * multi-level reduction, downstream of {@code groupingBy} or * {@code partitioningBy}. To perform a simple reduction on a stream, * use {@link Stream#reduce(Object, BinaryOperator)}} instead. * * @param <T> element type for the input and output of the reduction * @param identity the identity value for the reduction (also, the value * that is returned when there are no input elements) * @param op a {@code BinaryOperator<T>} used to reduce the input elements * @return a {@code Collector} which implements the reduction operation * * @see #reducing(BinaryOperator) * @see #reducing(Object, Function, BinaryOperator) */ public static <T> Collector<T, ?, T> reducing(T identity, BinaryOperator<T> op) { return new CollectorImpl<>( boxSupplier(identity), (a, t) -> { a[0] = op.apply(a[0], t); }, (a, b) -> { a[0] = op.apply(a[0], b[0]); return a; }, a -> a[0], CH_NOID); }