java.util.function.ObjLongConsumer Java Examples

The following examples show how to use java.util.function.ObjLongConsumer. 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: LongPipeline.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final <R> R collect(Supplier<R> supplier,
                           ObjLongConsumer<R> accumulator,
                           BiConsumer<R, R> combiner) {
    BinaryOperator<R> operator = (left, right) -> {
        combiner.accept(left, right);
        return left;
    };
    return evaluate(ReduceOps.makeLong(supplier, accumulator, operator));
}
 
Example #2
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 #3
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 #4
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 #5
Source File: LongPipeline.java    From desugar_jdk_libs with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final <R> R collect(Supplier<R> supplier,
                           ObjLongConsumer<R> accumulator,
                           BiConsumer<R, R> combiner) {
    BinaryOperator<R> operator = (left, right) -> {
        combiner.accept(left, right);
        return left;
    };
    return evaluate(ReduceOps.makeLong(supplier, accumulator, operator));
}
 
Example #6
Source File: LongPipeline.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final <R> R collect(Supplier<R> supplier,
                           ObjLongConsumer<R> accumulator,
                           BiConsumer<R, R> combiner) {
    Objects.requireNonNull(combiner);
    BinaryOperator<R> operator = (left, right) -> {
        combiner.accept(left, right);
        return left;
    };
    return evaluate(ReduceOps.makeLong(supplier, accumulator, operator));
}
 
Example #7
Source File: LongPipeline.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
@Override
public final <R> R collect(Supplier<R> supplier,
                           ObjLongConsumer<R> accumulator,
                           BiConsumer<R, R> combiner) {
    BinaryOperator<R> operator = (left, right) -> {
        combiner.accept(left, right);
        return left;
    };
    return evaluate(ReduceOps.makeLong(supplier, accumulator, operator));
}
 
Example #8
Source File: LongPipeline.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
@Override
public final <R> R collect(Supplier<R> supplier,
                           ObjLongConsumer<R> accumulator,
                           BiConsumer<R, R> combiner) {
    Objects.requireNonNull(combiner);
    BinaryOperator<R> operator = (left, right) -> {
        combiner.accept(left, right);
        return left;
    };
    return evaluate(ReduceOps.makeLong(supplier, accumulator, operator));
}
 
Example #9
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 #10
Source File: LongPipeline.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final <R> R collect(Supplier<R> supplier,
                           ObjLongConsumer<R> accumulator,
                           BiConsumer<R, R> combiner) {
    Objects.requireNonNull(combiner);
    BinaryOperator<R> operator = (left, right) -> {
        combiner.accept(left, right);
        return left;
    };
    return evaluate(ReduceOps.makeLong(supplier, accumulator, operator));
}
 
Example #11
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 #12
Source File: LongPipeline.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final <R> R collect(Supplier<R> supplier,
                           ObjLongConsumer<R> accumulator,
                           BiConsumer<R, R> combiner) {
    BinaryOperator<R> operator = (left, right) -> {
        combiner.accept(left, right);
        return left;
    };
    return evaluate(ReduceOps.makeLong(supplier, accumulator, operator));
}
 
Example #13
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 #14
Source File: LongPipeline.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
@Override
public final <R> R collect(Supplier<R> supplier,
                           ObjLongConsumer<R> accumulator,
                           BiConsumer<R, R> combiner) {
    BinaryOperator<R> operator = (left, right) -> {
        combiner.accept(left, right);
        return left;
    };
    return evaluate(ReduceOps.makeLong(supplier, accumulator, operator));
}
 
Example #15
Source File: ReduceOps.java    From hottub 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 #16
Source File: LongPipeline.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
@Override
public final <R> R collect(Supplier<R> supplier,
                           ObjLongConsumer<R> accumulator,
                           BiConsumer<R, R> combiner) {
    BinaryOperator<R> operator = (left, right) -> {
        combiner.accept(left, right);
        return left;
    };
    return evaluate(ReduceOps.makeLong(supplier, accumulator, operator));
}
 
Example #17
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 #18
Source File: LongPipeline.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final <R> R collect(Supplier<R> supplier,
                           ObjLongConsumer<R> accumulator,
                           BiConsumer<R, R> combiner) {
    BinaryOperator<R> operator = (left, right) -> {
        combiner.accept(left, right);
        return left;
    };
    return evaluate(ReduceOps.makeLong(supplier, accumulator, operator));
}
 
Example #19
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 #20
Source File: LongPipeline.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final <R> R collect(Supplier<R> supplier,
                           ObjLongConsumer<R> accumulator,
                           BiConsumer<R, R> combiner) {
    BinaryOperator<R> operator = (left, right) -> {
        combiner.accept(left, right);
        return left;
    };
    return evaluate(ReduceOps.makeLong(supplier, accumulator, operator));
}
 
Example #21
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 #22
Source File: LongPipeline.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final <R> R collect(Supplier<R> supplier,
                           ObjLongConsumer<R> accumulator,
                           BiConsumer<R, R> combiner) {
    Objects.requireNonNull(combiner);
    BinaryOperator<R> operator = (left, right) -> {
        combiner.accept(left, right);
        return left;
    };
    return evaluate(ReduceOps.makeLong(supplier, accumulator, operator));
}
 
Example #23
Source File: LongStreamEx.java    From streamex with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @see #collect(LongCollector)
 */
@Override
public <R> R collect(Supplier<R> supplier, ObjLongConsumer<R> accumulator, BiConsumer<R, R> combiner) {
    if (context.fjp != null)
        return context.terminate(() -> stream().collect(supplier, accumulator, combiner));
    return stream().collect(supplier, accumulator, combiner);
}
 
Example #24
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 #25
Source File: LongPipeline.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final <R> R collect(Supplier<R> supplier,
                           ObjLongConsumer<R> accumulator,
                           BiConsumer<R, R> combiner) {
    BinaryOperator<R> operator = (left, right) -> {
        combiner.accept(left, right);
        return left;
    };
    return evaluate(ReduceOps.makeLong(supplier, accumulator, operator));
}
 
Example #26
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 #27
Source File: LongPipeline.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final <R> R collect(Supplier<R> supplier,
                           ObjLongConsumer<R> accumulator,
                           BiConsumer<R, R> combiner) {
    BinaryOperator<R> operator = (left, right) -> {
        combiner.accept(left, right);
        return left;
    };
    return evaluate(ReduceOps.makeLong(supplier, accumulator, operator));
}
 
Example #28
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 #29
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 #30
Source File: LongPipeline.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Override
public final <R> R collect(Supplier<R> supplier,
                           ObjLongConsumer<R> accumulator,
                           BiConsumer<R, R> combiner) {
    BinaryOperator<R> operator = (left, right) -> {
        combiner.accept(left, right);
        return left;
    };
    return evaluate(ReduceOps.makeLong(supplier, accumulator, operator));
}