本文整理汇总了Java中java.util.function.ObjLongConsumer.accept方法的典型用法代码示例。如果您正苦于以下问题:Java ObjLongConsumer.accept方法的具体用法?Java ObjLongConsumer.accept怎么用?Java ObjLongConsumer.accept使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.function.ObjLongConsumer
的用法示例。
在下文中一共展示了ObjLongConsumer.accept方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeLong
import java.util.function.ObjLongConsumer; //导入方法依赖的package包/类
/**
* 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();
}
};
}
示例2: F
import java.util.function.ObjLongConsumer; //导入方法依赖的package包/类
F(ObjLongConsumer<T1> objLongConsumer) {
this((BiFunction<T1, T2, R>) new BiFunction<T1, Long, R>() {
@Override
public R apply(T1 t, Long u) {
objLongConsumer.accept(t, u);
return null;
}
});
}
示例3: collect
import java.util.function.ObjLongConsumer; //导入方法依赖的package包/类
@Override
public <R> R collect(Supplier<R> supplier, ObjLongConsumer<R> accumulator, BiConsumer<R, R> combiner) {
requireNonNull(supplier);
requireNonNull(accumulator);
final R value = supplier.get();
accumulator.accept(value, element);
// the combiner is never used in a non-parallell stream
return value;
}
示例4: assertObjLongConsumer
import java.util.function.ObjLongConsumer; //导入方法依赖的package包/类
private <E extends Exception> void assertObjLongConsumer(ObjLongConsumer<Object> test, Class<E> type) {
assertNotNull(test);
try {
test.accept(null, 0L);
fail();
}
catch (Exception e) {
assertException(type, e, "null:0");
}
}
示例5: andThen
import java.util.function.ObjLongConsumer; //导入方法依赖的package包/类
/**
* Returns a composed {@link ObjLongConsumer2} that performs, in sequence, this consumer followed by the {@code
* after} consumer. If evaluation of either operation throws an exception, it is relayed to the caller of the
* composed operation. If performing this consumer throws an exception, the {@code after} consumer will not be
* performed.
*
* @param after The consumer to apply after this consumer is applied
* @return A composed {@link ObjLongConsumer2} that performs, in sequence, this consumer followed by the {@code
* after} consumer.
* @throws NullPointerException If given argument is {@code null}
*/
@Nonnull
default ObjLongConsumer2<T> andThen(@Nonnull final ObjLongConsumer<? super T> after) {
Objects.requireNonNull(after);
return (t, value) -> {
accept(t, value);
after.accept(t, value);
};
}
示例6: partitioningBy
import java.util.function.ObjLongConsumer; //导入方法依赖的package包/类
/**
* 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);
}
示例7: call
import java.util.function.ObjLongConsumer; //导入方法依赖的package包/类
/**
* Calls the given {@link ObjLongConsumer} with the given arguments and returns its result.
*
* @param <T> The type of the first argument to the consumer
* @param consumer The consumer to be called
* @param t The first argument to the consumer
* @param value The second argument to the consumer
* @throws NullPointerException If given argument is {@code null}
*/
static <T> void call(@Nonnull final ObjLongConsumer<? super T> consumer, T t, long value) {
Objects.requireNonNull(consumer);
consumer.accept(t, value);
}
示例8: mapping
import java.util.function.ObjLongConsumer; //导入方法依赖的package包/类
/**
* 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());
}