java.util.function.LongConsumer Java Examples
The following examples show how to use
java.util.function.LongConsumer.
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: PageUtils.java From presto with Apache License 2.0 | 6 votes |
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); } }
Example #2
Source File: LongPipeline.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
@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); } }; } }; }
Example #3
Source File: PrimitiveIteratorDefaults.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
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)); }
Example #4
Source File: Streams.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@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; }
Example #5
Source File: Streams.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@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); } }
Example #6
Source File: MultiSignalConsumerOp.java From smallrye-mutiny with Apache License 2.0 | 6 votes |
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; }
Example #7
Source File: TeeOpTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "LongStreamTestData", dataProviderClass = LongStreamTestDataProvider.class) public void testLongOps(String name, final TestData.OfLong data) { class RecordingConsumer extends AbstractRecordingConsumer<Long> implements LongConsumer { public void accept(long t) { list.add(t); } } final RecordingConsumer b = new RecordingConsumer(); withData(data) .stream(s -> s.peek(b)) .before(b::before) .after(b::after) .exercise(); }
Example #8
Source File: Spliterators.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@Override public void forEachRemaining(LongConsumer action) { long[] a; int i, hi; // hoist accesses and checks from loop if (action == null) throw new NullPointerException(); if ((a = array).length >= (hi = fence) && (i = index) >= 0 && i < (index = hi)) { do { action.accept(a[i]); } while (++i < hi); } }
Example #9
Source File: LongPipeline.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * 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; } }
Example #10
Source File: Spliterator.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * {@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); } }
Example #11
Source File: AbstractVideoQuotaEnforcer.java From arcusplatform with Apache License 2.0 | 5 votes |
@Override public boolean allowRecording(Place place, boolean stream, PlaceQuota quota, LongConsumer quotaUpdater) { if (stream || quota.isUnderQuota()) { return true; } try { // The possible return values are interpreted as follows: // * null - do not allow the new recording // * empty - allow the new recording without deleting anything // * other - delete the given recordings and allow the new one Iterable<VideoRecordingSize> delete = getRecordingsToDelete(place, quota.getUsed(), quota.getQuota(), quotaUpdater); if (delete == null) { return false; } long recoveredBytes = 0; try { for (VideoRecordingSize recording : delete) { log.info("marking recording for deletion due to quota enforcement: place={}, recording={}", place.getId(), recording); Date scheduledAt = videoDao.deleteRecording(place.getId(), recording.getRecordingId(), recording.isFavorite()); recoveredBytes += recording.getSize(); sendDeleteTimeValueChange(place.getId(), place.getPopulation(), recording.getRecordingId(), scheduledAt); } } finally { quotaUpdater.accept(recoveredBytes); } return true; } catch (Exception ex) { log.info("quota enforcement failed, default decisions {} the new recordings:", defaultDecisionOnFailure ? "allows" : "denies", ex); return defaultDecisionOnFailure; } }
Example #12
Source File: Streams.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@Override public void forEachRemaining(LongConsumer action) { Objects.requireNonNull(action); if (count == -2) { action.accept(first); count = -1; } }
Example #13
Source File: SpinedBuffer.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@Override protected void arrayForEach(long[] array, int from, int to, LongConsumer consumer) { for (int i = from; i < to; i++) consumer.accept(array[i]); }
Example #14
Source File: Spliterators.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * 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(); }
Example #15
Source File: StreamSpliterators.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@Override public boolean tryAdvance(LongConsumer consumer) { Objects.requireNonNull(consumer); boolean hasNext = doAdvance(); if (hasNext) consumer.accept(buffer.get(nextToConsume)); return hasNext; }
Example #16
Source File: StreamSpliterators.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@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)); } }
Example #17
Source File: Random.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
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; }
Example #18
Source File: TeeOpTest.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "LongStreamTestData", dataProviderClass = LongStreamTestDataProvider.class) public void testLongOps(String name, final TestData.OfLong data) { class RecordingConsumer extends AbstractRecordingConsumer<Long> implements LongConsumer { public void accept(long t) { list.add(t); } } final RecordingConsumer b = new RecordingConsumer(); withData(data) .stream(s -> s.peek(b)) .before(b::before) .after(b::after) .exercise(); }
Example #19
Source File: LongPipeline.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
/** * 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; } }
Example #20
Source File: SplittableRandom.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
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; }
Example #21
Source File: ThreadLocalRandom.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
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); } }
Example #22
Source File: ThreadLocalRandom.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
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); } }
Example #23
Source File: Random.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
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; }
Example #24
Source File: Spliterator.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * {@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); } }
Example #25
Source File: Spliterator.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * {@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); } }
Example #26
Source File: SplittableRandom.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
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; }
Example #27
Source File: Node.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
/** * {@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); } }
Example #28
Source File: Node.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
@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(); }
Example #29
Source File: Spliterators.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
/** * 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(); }
Example #30
Source File: PrimitiveIterator.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
/** * {@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); } }