类java.util.function.LongConsumer源码实例Demo

下面列出了怎么用java.util.function.LongConsumer的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: presto   文件: PageUtils.java
public static void recordMaterializedBytes(Page page, LongConsumer sizeInBytesConsumer)
{
    // account processed bytes from lazy blocks only when they are loaded
    long loadedBlocksSizeInBytes = 0;

    for (int i = 0; i < page.getChannelCount(); ++i) {
        Block block = page.getBlock(i);
        long initialSize = block.getSizeInBytes();
        loadedBlocksSizeInBytes += initialSize;
        listenForLoads(block, new BlockSizeListener(block, sizeInBytesConsumer, initialSize));
    }

    if (loadedBlocksSizeInBytes > 0) {
        sizeInBytesConsumer.accept(loadedBlocksSizeInBytes);
    }
}
 
源代码2 项目: smallrye-mutiny   文件: MultiSignalConsumerOp.java
public MultiSignalConsumerOp(Multi<? extends T> upstream,
        Consumer<? super Subscription> onSubscribe,
        Consumer<? super T> onItem,
        Consumer<? super Throwable> onFailure,
        Runnable onCompletion,
        BiConsumer<Throwable, Boolean> onTermination,
        LongConsumer onRequest,
        Runnable onCancellation) {
    super(upstream);
    this.onSubscribe = onSubscribe;
    this.onItem = onItem;
    this.onFailure = onFailure;
    this.onCompletion = onCompletion;
    this.onRequest = onRequest;
    this.onTermination = onTermination;
    this.onCancellation = onCancellation;
}
 
源代码3 项目: jdk1.8-source-analysis   文件: LongPipeline.java
@Override
public final LongStream peek(LongConsumer action) {
    Objects.requireNonNull(action);
    return new StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                 0) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedLong<Long>(sink) {
                @Override
                public void accept(long t) {
                    action.accept(t);
                    downstream.accept(t);
                }
            };
        }
    };
}
 
源代码4 项目: TencentKona-8   文件: Streams.java
@Override
public void forEachRemaining(LongConsumer consumer) {
    Objects.requireNonNull(consumer);

    long i = from;
    final long hUpTo = upTo;
    int hLast = last;
    from = upTo;
    last = 0;
    while (i < hUpTo) {
        consumer.accept(i++);
    }
    if (hLast > 0) {
        // Last element of closed range
        consumer.accept(i);
    }
}
 
public void testLongForEachRemainingWithNull() {
    PrimitiveIterator.OfLong i = new PrimitiveIterator.OfLong() {
        @Override
        public long nextLong() {
            return 0;
        }

        @Override
        public boolean hasNext() {
            return false;
        }
    };

    executeAndCatch(() -> i.forEachRemaining((LongConsumer) null));
    executeAndCatch(() -> i.forEachRemaining((Consumer<Long>) null));
}
 
源代码6 项目: dragonwell8_jdk   文件: Streams.java
@Override
public boolean tryAdvance(LongConsumer consumer) {
    Objects.requireNonNull(consumer);

    final long i = from;
    if (i < upTo) {
        from++;
        consumer.accept(i);
        return true;
    }
    else if (last > 0) {
        last = 0;
        consumer.accept(i);
        return true;
    }
    return false;
}
 
源代码7 项目: dragonwell8_jdk   文件: PrimitiveIterator.java
/**
 * {@inheritDoc}
 * @implSpec
 * If the action is an instance of {@code LongConsumer} then it is cast
 * to {@code LongConsumer} and passed to {@link #forEachRemaining};
 * otherwise the action is adapted to an instance of
 * {@code LongConsumer}, by boxing the argument of {@code LongConsumer},
 * and then passed to {@link #forEachRemaining}.
 */
@Override
default void forEachRemaining(Consumer<? super Long> action) {
    if (action instanceof LongConsumer) {
        forEachRemaining((LongConsumer) action);
    }
    else {
        // The method reference action::accept is never null
        Objects.requireNonNull(action);
        if (Tripwire.ENABLED)
            Tripwire.trip(getClass(), "{0} calling PrimitiveIterator.OfLong.forEachRemainingLong(action::accept)");
        forEachRemaining((LongConsumer) action::accept);
    }
}
 
源代码8 项目: TencentKona-8   文件: Random.java
public void forEachRemaining(LongConsumer consumer) {
    if (consumer == null) throw new NullPointerException();
    long i = index, f = fence;
    if (i < f) {
        index = f;
        Random r = rng;
        long o = origin, b = bound;
        do {
            consumer.accept(r.internalNextLong(o, b));
        } while (++i < f);
    }
}
 
源代码9 项目: TencentKona-8   文件: SplittableRandom.java
public void forEachRemaining(LongConsumer consumer) {
    if (consumer == null) throw new NullPointerException();
    long i = index, f = fence;
    if (i < f) {
        index = f;
        SplittableRandom r = rng;
        long o = origin, b = bound;
        do {
            consumer.accept(r.internalNextLong(o, b));
        } while (++i < f);
    }
}
 
源代码10 项目: dragonwell8_jdk   文件: Spliterator.java
/**
 * {@inheritDoc}
 * @implSpec
 * If the action is an instance of {@code LongConsumer} then it is cast
 * to {@code LongConsumer} and passed to
 * {@link #tryAdvance(java.util.function.LongConsumer)}; otherwise
 * the action is adapted to an instance of {@code LongConsumer}, by
 * boxing the argument of {@code LongConsumer}, and then passed to
 * {@link #tryAdvance(java.util.function.LongConsumer)}.
 */
@Override
default boolean tryAdvance(Consumer<? super Long> action) {
    if (action instanceof LongConsumer) {
        return tryAdvance((LongConsumer) action);
    }
    else {
        if (Tripwire.ENABLED)
            Tripwire.trip(getClass(),
                          "{0} calling Spliterator.OfLong.tryAdvance((LongConsumer) action::accept)");
        return tryAdvance((LongConsumer) action::accept);
    }
}
 
源代码11 项目: TencentKona-8   文件: SpinedBuffer.java
@Override
public void forEach(Consumer<? super Long> consumer) {
    if (consumer instanceof LongConsumer) {
        forEach((LongConsumer) consumer);
    }
    else {
        if (Tripwire.ENABLED)
            Tripwire.trip(getClass(), "{0} calling SpinedBuffer.OfLong.forEach(Consumer)");
        spliterator().forEachRemaining(consumer);
    }
}
 
源代码12 项目: dragonwell8_jdk   文件: SplittableRandom.java
public void forEachRemaining(LongConsumer consumer) {
    if (consumer == null) throw new NullPointerException();
    long i = index, f = fence;
    if (i < f) {
        index = f;
        SplittableRandom r = rng;
        long o = origin, b = bound;
        do {
            consumer.accept(r.internalNextLong(o, b));
        } while (++i < f);
    }
}
 
源代码13 项目: jdk1.8-source-analysis   文件: Streams.java
@Override
public boolean tryAdvance(LongConsumer action) {
    Objects.requireNonNull(action);

    if (count == -2) {
        action.accept(first);
        count = -1;
        return true;
    }
    else {
        return false;
    }
}
 
源代码14 项目: TencentKona-8   文件: Spliterator.java
/**
 * {@inheritDoc}
 * @implSpec
 * If the action is an instance of {@code LongConsumer} then it is cast
 * to {@code LongConsumer} and passed to
 * {@link #tryAdvance(java.util.function.LongConsumer)}; otherwise
 * the action is adapted to an instance of {@code LongConsumer}, by
 * boxing the argument of {@code LongConsumer}, and then passed to
 * {@link #tryAdvance(java.util.function.LongConsumer)}.
 */
@Override
default boolean tryAdvance(Consumer<? super Long> action) {
    if (action instanceof LongConsumer) {
        return tryAdvance((LongConsumer) action);
    }
    else {
        if (Tripwire.ENABLED)
            Tripwire.trip(getClass(),
                          "{0} calling Spliterator.OfLong.tryAdvance((LongConsumer) action::accept)");
        return tryAdvance((LongConsumer) action::accept);
    }
}
 
源代码15 项目: jdk1.8-source-analysis   文件: ReferencePipeline.java
@Override
public final LongStream flatMapToLong(Function<? super P_OUT, ? extends LongStream> mapper) {
    Objects.requireNonNull(mapper);
    // We can do better than this, by polling cancellationRequested when stream is infinite
    return new LongPipeline.StatelessOp<P_OUT>(this, StreamShape.REFERENCE,
                                               StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<P_OUT> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedReference<P_OUT, Long>(sink) {
                LongConsumer downstreamAsLong = downstream::accept;
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(P_OUT u) {
                    try (LongStream result = mapper.apply(u)) {
                        // We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it
                        if (result != null)
                            result.sequential().forEach(downstreamAsLong);
                    }
                }
            };
        }
    };
}
 
源代码16 项目: jdk1.8-source-analysis   文件: LongPipeline.java
/**
 * Adapt a {@code Sink<Long> to an {@code LongConsumer}, ideally simply
 * by casting.
 */
private static LongConsumer adapt(Sink<Long> sink) {
    if (sink instanceof LongConsumer) {
        return (LongConsumer) sink;
    } else {
        if (Tripwire.ENABLED)
            Tripwire.trip(AbstractPipeline.class,
                          "using LongStream.adapt(Sink<Long> s)");
        return sink::accept;
    }
}
 
源代码17 项目: jdk1.8-source-analysis   文件: LongPipeline.java
@Override
public void forEach(LongConsumer action) {
    if (!isParallel()) {
        adapt(sourceStageSpliterator()).forEachRemaining(action);
    } else {
        super.forEach(action);
    }
}
 
源代码18 项目: jdk1.8-source-analysis   文件: LongPipeline.java
@Override
public void forEachOrdered(LongConsumer action) {
    if (!isParallel()) {
        adapt(sourceStageSpliterator()).forEachRemaining(action);
    } else {
        super.forEachOrdered(action);
    }
}
 
源代码19 项目: jdk1.8-source-analysis   文件: SpinedBuffer.java
@Override
protected void arrayForEach(long[] array,
                            int from, int to,
                            LongConsumer consumer) {
    for (int i = from; i < to; i++)
        consumer.accept(array[i]);
}
 
@Override
public boolean tryAdvance(LongConsumer consumer) {
    Objects.requireNonNull(consumer);
    boolean hasNext = doAdvance();
    if (hasNext)
        consumer.accept(buffer.get(nextToConsume));
    return hasNext;
}
 
@Override
public void forEachRemaining(LongConsumer consumer) {
    if (buffer == null && !finished) {
        Objects.requireNonNull(consumer);
        init();

        ph.wrapAndCopyInto((Sink.OfLong) consumer::accept, spliterator);
        finished = true;
    }
    else {
        do { } while (tryAdvance(consumer));
    }
}
 
源代码22 项目: TencentKona-8   文件: Random.java
public boolean tryAdvance(LongConsumer consumer) {
    if (consumer == null) throw new NullPointerException();
    long i = index, f = fence;
    if (i < f) {
        consumer.accept(rng.internalNextLong(origin, bound));
        index = i + 1;
        return true;
    }
    return false;
}
 
源代码23 项目: dragonwell8_jdk   文件: Spliterators.java
/**
 * Creates an {@code PrimitiveIterator.OfLong} from a
 * {@code Spliterator.OfLong}.
 *
 * <p>Traversal of elements should be accomplished through the iterator.
 * The behaviour of traversal is undefined if the spliterator is operated
 * after the iterator is returned.
 *
 * @param spliterator The spliterator
 * @return An iterator
 * @throws NullPointerException if the given spliterator is {@code null}
 */
public static PrimitiveIterator.OfLong iterator(Spliterator.OfLong spliterator) {
    Objects.requireNonNull(spliterator);
    class Adapter implements PrimitiveIterator.OfLong, LongConsumer {
        boolean valueReady = false;
        long nextElement;

        @Override
        public void accept(long t) {
            valueReady = true;
            nextElement = t;
        }

        @Override
        public boolean hasNext() {
            if (!valueReady)
                spliterator.tryAdvance(this);
            return valueReady;
        }

        @Override
        public long nextLong() {
            if (!valueReady && !hasNext())
                throw new NoSuchElementException();
            else {
                valueReady = false;
                return nextElement;
            }
        }
    }

    return new Adapter();
}
 
源代码24 项目: jdk1.8-source-analysis   文件: Node.java
@Override
default Node.OfLong truncate(long from, long to, IntFunction<Long[]> generator) {
    if (from == 0 && to == count())
        return this;
    long size = to - from;
    Spliterator.OfLong spliterator = spliterator();
    Node.Builder.OfLong nodeBuilder = Nodes.longBuilder(size);
    nodeBuilder.begin(size);
    for (int i = 0; i < from && spliterator.tryAdvance((LongConsumer) e -> { }); i++) { }
    for (int i = 0; (i < size) && spliterator.tryAdvance((LongConsumer) nodeBuilder); i++) { }
    nodeBuilder.end();
    return nodeBuilder.build();
}
 
源代码25 项目: dragonwell8_jdk   文件: Node.java
/**
 * {@inheritDoc}
 *
 * @param consumer A {@code Consumer} that is to be invoked with each
 *        element in this {@code Node}.  If this is an
 *        {@code LongConsumer}, it is cast to {@code LongConsumer} so
 *        the elements may be processed without boxing.
 */
@Override
default void forEach(Consumer<? super Long> consumer) {
    if (consumer instanceof LongConsumer) {
        forEach((LongConsumer) consumer);
    }
    else {
        if (Tripwire.ENABLED)
            Tripwire.trip(getClass(), "{0} calling Node.OfLong.forEachRemaining(Consumer)");
        spliterator().forEachRemaining(consumer);
    }
}
 
源代码26 项目: TencentKona-8   文件: SplittableRandom.java
public boolean tryAdvance(LongConsumer consumer) {
    if (consumer == null) throw new NullPointerException();
    long i = index, f = fence;
    if (i < f) {
        consumer.accept(rng.internalNextLong(origin, bound));
        index = i + 1;
        return true;
    }
    return false;
}
 
源代码27 项目: jdk1.8-source-analysis   文件: Spliterator.java
/**
 * {@inheritDoc}
 * @implSpec
 * If the action is an instance of {@code LongConsumer} then it is cast
 * to {@code LongConsumer} and passed to
 * {@link #tryAdvance(java.util.function.LongConsumer)}; otherwise
 * the action is adapted to an instance of {@code LongConsumer}, by
 * boxing the argument of {@code LongConsumer}, and then passed to
 * {@link #tryAdvance(java.util.function.LongConsumer)}.
 */
@Override
default boolean tryAdvance(Consumer<? super Long> action) {
    if (action instanceof LongConsumer) {
        return tryAdvance((LongConsumer) action);
    }
    else {
        if (Tripwire.ENABLED)
            Tripwire.trip(getClass(),
                          "{0} calling Spliterator.OfLong.tryAdvance((LongConsumer) action::accept)");
        return tryAdvance((LongConsumer) action::accept);
    }
}
 
源代码28 项目: jdk1.8-source-analysis   文件: Spliterator.java
/**
 * {@inheritDoc}
 * @implSpec
 * If the action is an instance of {@code LongConsumer} then it is cast
 * to {@code LongConsumer} and passed to
 * {@link #forEachRemaining(java.util.function.LongConsumer)}; otherwise
 * the action is adapted to an instance of {@code LongConsumer}, by
 * boxing the argument of {@code LongConsumer}, and then passed to
 * {@link #forEachRemaining(java.util.function.LongConsumer)}.
 */
@Override
default void forEachRemaining(Consumer<? super Long> action) {
    if (action instanceof LongConsumer) {
        forEachRemaining((LongConsumer) action);
    }
    else {
        if (Tripwire.ENABLED)
            Tripwire.trip(getClass(),
                          "{0} calling Spliterator.OfLong.forEachRemaining((LongConsumer) action::accept)");
        forEachRemaining((LongConsumer) action::accept);
    }
}
 
源代码29 项目: jdk1.8-source-analysis   文件: Random.java
public boolean tryAdvance(LongConsumer consumer) {
    if (consumer == null) throw new NullPointerException();
    long i = index, f = fence;
    if (i < f) {
        consumer.accept(rng.internalNextLong(origin, bound));
        index = i + 1;
        return true;
    }
    return false;
}
 
源代码30 项目: dragonwell8_jdk   文件: ThreadLocalRandom.java
public void forEachRemaining(LongConsumer consumer) {
    if (consumer == null) throw new NullPointerException();
    long i = index, f = fence;
    if (i < f) {
        index = f;
        long o = origin, b = bound;
        ThreadLocalRandom rng = ThreadLocalRandom.current();
        do {
            consumer.accept(rng.internalNextLong(o, b));
        } while (++i < f);
    }
}
 
 类所在包
 类方法
 同包方法