Java Code Examples for java.util.function.ObjLongConsumer#accept()

The following examples show how to use java.util.function.ObjLongConsumer#accept() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReduceOps.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a {@code TerminalOp} that implements a mutable reduce on
 * {@code long} values.
 *
 * @param <R> the type of the result
 * @param supplier a factory to produce a new accumulator of the result type
 * @param accumulator a function to incorporate an int into an
 *        accumulator
 * @param combiner a function to combine an accumulator into another
 * @return a {@code TerminalOp} implementing the reduction
 */
public static <R> TerminalOp<Long, R>
makeLong(Supplier<R> supplier,
         ObjLongConsumer<R> accumulator,
         BinaryOperator<R> combiner) {
    Objects.requireNonNull(supplier);
    Objects.requireNonNull(accumulator);
    Objects.requireNonNull(combiner);
    class ReducingSink extends Box<R>
            implements AccumulatingSink<Long, R, ReducingSink>, Sink.OfLong {
        @Override
        public void begin(long size) {
            state = supplier.get();
        }

        @Override
        public void accept(long t) {
            accumulator.accept(state, t);
        }

        @Override
        public void combine(ReducingSink other) {
            state = combiner.apply(state, other.state);
        }
    }
    return new ReduceOp<Long, R, ReducingSink>(StreamShape.LONG_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
Example 2
Source File: ReduceOps.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a {@code TerminalOp} that implements a mutable reduce on
 * {@code long} values.
 *
 * @param <R> the type of the result
 * @param supplier a factory to produce a new accumulator of the result type
 * @param accumulator a function to incorporate an int into an
 *        accumulator
 * @param combiner a function to combine an accumulator into another
 * @return a {@code TerminalOp} implementing the reduction
 */
public static <R> TerminalOp<Long, R>
makeLong(Supplier<R> supplier,
         ObjLongConsumer<R> accumulator,
         BinaryOperator<R> combiner) {
    Objects.requireNonNull(supplier);
    Objects.requireNonNull(accumulator);
    Objects.requireNonNull(combiner);
    class ReducingSink extends Box<R>
            implements AccumulatingSink<Long, R, ReducingSink>, Sink.OfLong {
        @Override
        public void begin(long size) {
            state = supplier.get();
        }

        @Override
        public void accept(long t) {
            accumulator.accept(state, t);
        }

        @Override
        public void combine(ReducingSink other) {
            state = combiner.apply(state, other.state);
        }
    }
    return new ReduceOp<Long, R, ReducingSink>(StreamShape.LONG_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
Example 3
Source File: ReduceOps.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a {@code TerminalOp} that implements a mutable reduce on
 * {@code long} values.
 *
 * @param <R> the type of the result
 * @param supplier a factory to produce a new accumulator of the result type
 * @param accumulator a function to incorporate an int into an
 *        accumulator
 * @param combiner a function to combine an accumulator into another
 * @return a {@code TerminalOp} implementing the reduction
 */
public static <R> TerminalOp<Long, R>
makeLong(Supplier<R> supplier,
         ObjLongConsumer<R> accumulator,
         BinaryOperator<R> combiner) {
    Objects.requireNonNull(supplier);
    Objects.requireNonNull(accumulator);
    Objects.requireNonNull(combiner);
    class ReducingSink extends Box<R>
            implements AccumulatingSink<Long, R, ReducingSink>, Sink.OfLong {
        @Override
        public void begin(long size) {
            state = supplier.get();
        }

        @Override
        public void accept(long t) {
            accumulator.accept(state, t);
        }

        @Override
        public void combine(ReducingSink other) {
            state = combiner.apply(state, other.state);
        }
    }
    return new ReduceOp<Long, R, ReducingSink>(StreamShape.LONG_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
Example 4
Source File: ReduceOps.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a {@code TerminalOp} that implements a mutable reduce on
 * {@code long} values.
 *
 * @param <R> the type of the result
 * @param supplier a factory to produce a new accumulator of the result type
 * @param accumulator a function to incorporate an int into an
 *        accumulator
 * @param combiner a function to combine an accumulator into another
 * @return a {@code TerminalOp} implementing the reduction
 */
public static <R> TerminalOp<Long, R>
makeLong(Supplier<R> supplier,
         ObjLongConsumer<R> accumulator,
         BinaryOperator<R> combiner) {
    Objects.requireNonNull(supplier);
    Objects.requireNonNull(accumulator);
    Objects.requireNonNull(combiner);
    class ReducingSink extends Box<R>
            implements AccumulatingSink<Long, R, ReducingSink>, Sink.OfLong {
        @Override
        public void begin(long size) {
            state = supplier.get();
        }

        @Override
        public void accept(long t) {
            accumulator.accept(state, t);
        }

        @Override
        public void combine(ReducingSink other) {
            state = combiner.apply(state, other.state);
        }
    }
    return new ReduceOp<Long, R, ReducingSink>(StreamShape.LONG_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
Example 5
Source File: ReduceOps.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a {@code TerminalOp} that implements a mutable reduce on
 * {@code long} values.
 *
 * @param <R> the type of the result
 * @param supplier a factory to produce a new accumulator of the result type
 * @param accumulator a function to incorporate an int into an
 *        accumulator
 * @param combiner a function to combine an accumulator into another
 * @return a {@code TerminalOp} implementing the reduction
 */
public static <R> TerminalOp<Long, R>
makeLong(Supplier<R> supplier,
         ObjLongConsumer<R> accumulator,
         BinaryOperator<R> combiner) {
    Objects.requireNonNull(supplier);
    Objects.requireNonNull(accumulator);
    Objects.requireNonNull(combiner);
    class ReducingSink extends Box<R>
            implements AccumulatingSink<Long, R, ReducingSink>, Sink.OfLong {
        @Override
        public void begin(long size) {
            state = supplier.get();
        }

        @Override
        public void accept(long t) {
            accumulator.accept(state, t);
        }

        @Override
        public void combine(ReducingSink other) {
            state = combiner.apply(state, other.state);
        }
    }
    return new ReduceOp<Long, R, ReducingSink>(StreamShape.LONG_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
Example 6
Source File: ReduceOps.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a {@code TerminalOp} that implements a mutable reduce on
 * {@code long} values.
 *
 * @param <R> the type of the result
 * @param supplier a factory to produce a new accumulator of the result type
 * @param accumulator a function to incorporate an int into an
 *        accumulator
 * @param combiner a function to combine an accumulator into another
 * @return a {@code TerminalOp} implementing the reduction
 */
public static <R> TerminalOp<Long, R>
makeLong(Supplier<R> supplier,
         ObjLongConsumer<R> accumulator,
         BinaryOperator<R> combiner) {
    Objects.requireNonNull(supplier);
    Objects.requireNonNull(accumulator);
    Objects.requireNonNull(combiner);
    class ReducingSink extends Box<R>
            implements AccumulatingSink<Long, R, ReducingSink>, Sink.OfLong {
        @Override
        public void begin(long size) {
            state = supplier.get();
        }

        @Override
        public void accept(long t) {
            accumulator.accept(state, t);
        }

        @Override
        public void combine(ReducingSink other) {
            state = combiner.apply(state, other.state);
        }
    }
    return new ReduceOp<Long, R, ReducingSink>(StreamShape.LONG_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
Example 7
Source File: ManifestOptimizer.java    From dashencrypt with Mozilla Public License 2.0 5 votes vote down vote up
public static void adjustMinMax(AdaptationSetType adaptationSetType, Function<RepresentationType, Long> get, ObjLongConsumer<AdaptationSetType> setMin, ObjLongConsumer<AdaptationSetType> setMax) {
    List<RepresentationType> representations = adaptationSetType.getRepresentation();
    long min = Integer.MAX_VALUE, max = Integer.MIN_VALUE;
    for (RepresentationType representationType : representations) {
        Long n = get.apply(representationType);
        if (n != null) {
            min = Math.min(n, min);
            max = Math.max(n, max);
        }
    }
    if (min != Integer.MAX_VALUE && min != max) {
        setMax.accept(adaptationSetType, max);
        setMin.accept(adaptationSetType, min);
    }
}
 
Example 8
Source File: ReduceOps.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a {@code TerminalOp} that implements a mutable reduce on
 * {@code long} values.
 *
 * @param <R> the type of the result
 * @param supplier a factory to produce a new accumulator of the result type
 * @param accumulator a function to incorporate an int into an
 *        accumulator
 * @param combiner a function to combine an accumulator into another
 * @return a {@code TerminalOp} implementing the reduction
 */
public static <R> TerminalOp<Long, R>
makeLong(Supplier<R> supplier,
         ObjLongConsumer<R> accumulator,
         BinaryOperator<R> combiner) {
    Objects.requireNonNull(supplier);
    Objects.requireNonNull(accumulator);
    Objects.requireNonNull(combiner);
    class ReducingSink extends Box<R>
            implements AccumulatingSink<Long, R, ReducingSink>, Sink.OfLong {
        @Override
        public void begin(long size) {
            state = supplier.get();
        }

        @Override
        public void accept(long t) {
            accumulator.accept(state, t);
        }

        @Override
        public void combine(ReducingSink other) {
            state = combiner.apply(state, other.state);
        }
    }
    return new ReduceOp<Long, R, ReducingSink>(StreamShape.LONG_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
Example 9
Source File: ReduceOps.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a {@code TerminalOp} that implements a mutable reduce on
 * {@code long} values.
 *
 * @param <R> the type of the result
 * @param supplier a factory to produce a new accumulator of the result type
 * @param accumulator a function to incorporate an int into an
 *        accumulator
 * @param combiner a function to combine an accumulator into another
 * @return a {@code TerminalOp} implementing the reduction
 */
public static <R> TerminalOp<Long, R>
makeLong(Supplier<R> supplier,
         ObjLongConsumer<R> accumulator,
         BinaryOperator<R> combiner) {
    Objects.requireNonNull(supplier);
    Objects.requireNonNull(accumulator);
    Objects.requireNonNull(combiner);
    class ReducingSink extends Box<R>
            implements AccumulatingSink<Long, R, ReducingSink>, Sink.OfLong {
        @Override
        public void begin(long size) {
            state = supplier.get();
        }

        @Override
        public void accept(long t) {
            accumulator.accept(state, t);
        }

        @Override
        public void combine(ReducingSink other) {
            state = combiner.apply(state, other.state);
        }
    }
    return new ReduceOp<Long, R, ReducingSink>(StreamShape.LONG_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
Example 10
Source File: ReduceOps.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a {@code TerminalOp} that implements a mutable reduce on
 * {@code long} values.
 *
 * @param <R> the type of the result
 * @param supplier a factory to produce a new accumulator of the result type
 * @param accumulator a function to incorporate an int into an
 *        accumulator
 * @param combiner a function to combine an accumulator into another
 * @return a {@code TerminalOp} implementing the reduction
 */
public static <R> TerminalOp<Long, R>
makeLong(Supplier<R> supplier,
         ObjLongConsumer<R> accumulator,
         BinaryOperator<R> combiner) {
    Objects.requireNonNull(supplier);
    Objects.requireNonNull(accumulator);
    Objects.requireNonNull(combiner);
    class ReducingSink extends Box<R>
            implements AccumulatingSink<Long, R, ReducingSink>, Sink.OfLong {
        @Override
        public void begin(long size) {
            state = supplier.get();
        }

        @Override
        public void accept(long t) {
            accumulator.accept(state, t);
        }

        @Override
        public void combine(ReducingSink other) {
            state = combiner.apply(state, other.state);
        }
    }
    return new ReduceOp<Long, R, ReducingSink>(StreamShape.LONG_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
Example 11
Source File: ReduceOps.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a {@code TerminalOp} that implements a mutable reduce on
 * {@code long} values.
 *
 * @param <R> the type of the result
 * @param supplier a factory to produce a new accumulator of the result type
 * @param accumulator a function to incorporate an int into an
 *        accumulator
 * @param combiner a function to combine an accumulator into another
 * @return a {@code TerminalOp} implementing the reduction
 */
public static <R> TerminalOp<Long, R>
makeLong(Supplier<R> supplier,
         ObjLongConsumer<R> accumulator,
         BinaryOperator<R> combiner) {
    Objects.requireNonNull(supplier);
    Objects.requireNonNull(accumulator);
    Objects.requireNonNull(combiner);
    class ReducingSink extends Box<R>
            implements AccumulatingSink<Long, R, ReducingSink>, Sink.OfLong {
        @Override
        public void begin(long size) {
            state = supplier.get();
        }

        @Override
        public void accept(long t) {
            accumulator.accept(state, t);
        }

        @Override
        public void combine(ReducingSink other) {
            state = combiner.apply(state, other.state);
        }
    }
    return new ReduceOp<Long, R, ReducingSink>(StreamShape.LONG_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
Example 12
Source File: ReduceOps.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a {@code TerminalOp} that implements a mutable reduce on
 * {@code long} values.
 *
 * @param <R> the type of the result
 * @param supplier a factory to produce a new accumulator of the result type
 * @param accumulator a function to incorporate an int into an
 *        accumulator
 * @param combiner a function to combine an accumulator into another
 * @return a {@code TerminalOp} implementing the reduction
 */
public static <R> TerminalOp<Long, R>
makeLong(Supplier<R> supplier,
         ObjLongConsumer<R> accumulator,
         BinaryOperator<R> combiner) {
    Objects.requireNonNull(supplier);
    Objects.requireNonNull(accumulator);
    Objects.requireNonNull(combiner);
    class ReducingSink extends Box<R>
            implements AccumulatingSink<Long, R, ReducingSink>, Sink.OfLong {
        @Override
        public void begin(long size) {
            state = supplier.get();
        }

        @Override
        public void accept(long t) {
            accumulator.accept(state, t);
        }

        @Override
        public void combine(ReducingSink other) {
            state = combiner.apply(state, other.state);
        }
    }
    return new ReduceOp<Long, R, ReducingSink>(StreamShape.LONG_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
Example 13
Source File: ReduceOps.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a {@code TerminalOp} that implements a mutable reduce on
 * {@code long} values.
 *
 * @param <R> the type of the result
 * @param supplier a factory to produce a new accumulator of the result type
 * @param accumulator a function to incorporate an int into an
 *        accumulator
 * @param combiner a function to combine an accumulator into another
 * @return a {@code TerminalOp} implementing the reduction
 */
public static <R> TerminalOp<Long, R>
makeLong(Supplier<R> supplier,
         ObjLongConsumer<R> accumulator,
         BinaryOperator<R> combiner) {
    Objects.requireNonNull(supplier);
    Objects.requireNonNull(accumulator);
    Objects.requireNonNull(combiner);
    class ReducingSink extends Box<R>
            implements AccumulatingSink<Long, R, ReducingSink>, Sink.OfLong {
        @Override
        public void begin(long size) {
            state = supplier.get();
        }

        @Override
        public void accept(long t) {
            accumulator.accept(state, t);
        }

        @Override
        public void combine(ReducingSink other) {
            state = combiner.apply(state, other.state);
        }
    }
    return new ReduceOp<Long, R, ReducingSink>(StreamShape.LONG_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
Example 14
Source File: ReduceOps.java    From desugar_jdk_libs with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a {@code TerminalOp} that implements a mutable reduce on
 * {@code long} values.
 *
 * @param <R> the type of the result
 * @param supplier a factory to produce a new accumulator of the result type
 * @param accumulator a function to incorporate an int into an
 *        accumulator
 * @param combiner a function to combine an accumulator into another
 * @return a {@code TerminalOp} implementing the reduction
 */
public static <R> TerminalOp<Long, R>
makeLong(Supplier<R> supplier,
         ObjLongConsumer<R> accumulator,
         BinaryOperator<R> combiner) {
    Objects.requireNonNull(supplier);
    Objects.requireNonNull(accumulator);
    Objects.requireNonNull(combiner);
    class ReducingSink extends Box<R>
            implements AccumulatingSink<Long, R, ReducingSink>, Sink.OfLong {
        @Override
        public void begin(long size) {
            state = supplier.get();
        }

        @Override
        public void accept(long t) {
            accumulator.accept(state, t);
        }

        @Override
        public void combine(ReducingSink other) {
            state = combiner.apply(state, other.state);
        }
    }
    return new ReduceOp<Long, R, ReducingSink>(StreamShape.LONG_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
Example 15
Source File: ReduceOps.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Constructs a {@code TerminalOp} that implements a mutable reduce on
 * {@code long} values.
 *
 * @param <R> the type of the result
 * @param supplier a factory to produce a new accumulator of the result type
 * @param accumulator a function to incorporate an int into an
 *        accumulator
 * @param combiner a function to combine an accumulator into another
 * @return a {@code TerminalOp} implementing the reduction
 */
public static <R> TerminalOp<Long, R>
makeLong(Supplier<R> supplier,
         ObjLongConsumer<R> accumulator,
         BinaryOperator<R> combiner) {
    Objects.requireNonNull(supplier);
    Objects.requireNonNull(accumulator);
    Objects.requireNonNull(combiner);
    class ReducingSink extends Box<R>
            implements AccumulatingSink<Long, R, ReducingSink>, Sink.OfLong {
        @Override
        public void begin(long size) {
            state = supplier.get();
        }

        @Override
        public void accept(long t) {
            accumulator.accept(state, t);
        }

        @Override
        public void combine(ReducingSink other) {
            state = combiner.apply(state, other.state);
        }
    }
    return new ReduceOp<Long, R, ReducingSink>(StreamShape.LONG_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
Example 16
Source File: ReduceOps.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a {@code TerminalOp} that implements a mutable reduce on
 * {@code long} values.
 *
 * @param <R> the type of the result
 * @param supplier a factory to produce a new accumulator of the result type
 * @param accumulator a function to incorporate an int into an
 *        accumulator
 * @param combiner a function to combine an accumulator into another
 * @return a {@code TerminalOp} implementing the reduction
 */
public static <R> TerminalOp<Long, R>
makeLong(Supplier<R> supplier,
         ObjLongConsumer<R> accumulator,
         BinaryOperator<R> combiner) {
    Objects.requireNonNull(supplier);
    Objects.requireNonNull(accumulator);
    Objects.requireNonNull(combiner);
    class ReducingSink extends Box<R>
            implements AccumulatingSink<Long, R, ReducingSink>, Sink.OfLong {
        @Override
        public void begin(long size) {
            state = supplier.get();
        }

        @Override
        public void accept(long t) {
            accumulator.accept(state, t);
        }

        @Override
        public void combine(ReducingSink other) {
            state = combiner.apply(state, other.state);
        }
    }
    return new ReduceOp<Long, R, ReducingSink>(StreamShape.LONG_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
Example 17
Source File: ReduceOps.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a {@code TerminalOp} that implements a mutable reduce on
 * {@code long} values.
 *
 * @param <R> the type of the result
 * @param supplier a factory to produce a new accumulator of the result type
 * @param accumulator a function to incorporate an int into an
 *        accumulator
 * @param combiner a function to combine an accumulator into another
 * @return a {@code TerminalOp} implementing the reduction
 */
public static <R> TerminalOp<Long, R>
makeLong(Supplier<R> supplier,
         ObjLongConsumer<R> accumulator,
         BinaryOperator<R> combiner) {
    Objects.requireNonNull(supplier);
    Objects.requireNonNull(accumulator);
    Objects.requireNonNull(combiner);
    class ReducingSink extends Box<R>
            implements AccumulatingSink<Long, R, ReducingSink>, Sink.OfLong {
        @Override
        public void begin(long size) {
            state = supplier.get();
        }

        @Override
        public void accept(long t) {
            accumulator.accept(state, t);
        }

        @Override
        public void combine(ReducingSink other) {
            state = combiner.apply(state, other.state);
        }
    }
    return new ReduceOp<Long, R, ReducingSink>(StreamShape.LONG_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
Example 18
Source File: ReduceOps.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a {@code TerminalOp} that implements a mutable reduce on
 * {@code long} values.
 *
 * @param <R> the type of the result
 * @param supplier a factory to produce a new accumulator of the result type
 * @param accumulator a function to incorporate an int into an
 *        accumulator
 * @param combiner a function to combine an accumulator into another
 * @return a {@code TerminalOp} implementing the reduction
 */
public static <R> TerminalOp<Long, R>
makeLong(Supplier<R> supplier,
         ObjLongConsumer<R> accumulator,
         BinaryOperator<R> combiner) {
    Objects.requireNonNull(supplier);
    Objects.requireNonNull(accumulator);
    Objects.requireNonNull(combiner);
    class ReducingSink extends Box<R>
            implements AccumulatingSink<Long, R, ReducingSink>, Sink.OfLong {
        @Override
        public void begin(long size) {
            state = supplier.get();
        }

        @Override
        public void accept(long t) {
            accumulator.accept(state, t);
        }

        @Override
        public void combine(ReducingSink other) {
            state = combiner.apply(state, other.state);
        }
    }
    return new ReduceOp<Long, R, ReducingSink>(StreamShape.LONG_VALUE) {
        @Override
        public ReducingSink makeSink() {
            return new ReducingSink();
        }
    };
}
 
Example 19
Source File: LongCollector.java    From streamex with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a {@code LongCollector} which partitions the input numbers
 * according to a {@code LongPredicate}, reduces the values in each
 * partition according to another {@code IntCollector}, and organizes them
 * into a {@code Map<Boolean, D>} whose values are the result of the
 * downstream reduction.
 *
 * <p>
 * There are no guarantees on the type, mutability, serializability, or
 * thread-safety of the {@code Map} returned.
 *
 * @param <A> the intermediate accumulation type of the downstream collector
 * @param <D> the result type of the downstream reduction
 * @param predicate a predicate used for classifying input elements
 * @param downstream a {@code LongCollector} implementing the downstream
 *        reduction
 * @return a {@code LongCollector} implementing the cascaded partitioning
 *         operation
 */
static <A, D> LongCollector<?, Map<Boolean, D>> partitioningBy(LongPredicate predicate,
        LongCollector<A, D> downstream) {
    ObjLongConsumer<A> downstreamAccumulator = downstream.longAccumulator();
    ObjLongConsumer<BooleanMap<A>> accumulator = (result, t) -> downstreamAccumulator.accept(
        predicate.test(t) ? result.trueValue : result.falseValue, t);
    return BooleanMap.partialCollector(downstream).asLong(accumulator);
}
 
Example 20
Source File: LongCollector.java    From streamex with Apache License 2.0 2 votes vote down vote up
/**
 * Adapts a {@code LongCollector} to another one by applying a mapping
 * function to each input element before accumulation.
 *
 * @param <A> intermediate accumulation type of the downstream collector
 * @param <R> result type of collector
 * @param mapper a function to be applied to the input elements
 * @param downstream a collector which will accept mapped values
 * @return a collector which applies the mapping function to the input
 *         elements and provides the mapped results to the downstream
 *         collector
 */
static <A, R> LongCollector<?, R> mapping(LongUnaryOperator mapper, LongCollector<A, R> downstream) {
    ObjLongConsumer<A> downstreamAccumulator = downstream.longAccumulator();
    return new LongCollectorImpl<>(downstream.supplier(), (r, t) -> downstreamAccumulator.accept(r, mapper
            .applyAsLong(t)), downstream.merger(), downstream.finisher(), downstream.characteristics());
}