當前位置: 首頁>>代碼示例>>Java>>正文


Java LongConsumer類代碼示例

本文整理匯總了Java中java.util.function.LongConsumer的典型用法代碼示例。如果您正苦於以下問題:Java LongConsumer類的具體用法?Java LongConsumer怎麽用?Java LongConsumer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


LongConsumer類屬於java.util.function包,在下文中一共展示了LongConsumer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: tryAdvance

import java.util.function.LongConsumer; //導入依賴的package包/類
@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;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:18,代碼來源:Streams.java

示例2: peek

import java.util.function.LongConsumer; //導入依賴的package包/類
@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);
                }
            };
        }
    };
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:18,代碼來源:LongPipeline.java

示例3: iterate

import java.util.function.LongConsumer; //導入依賴的package包/類
/**
 * Returns an infinite sequential ordered {@code LongStream} produced by iterative
 * application of a function {@code f} to an initial element {@code seed},
 * producing a {@code Stream} consisting of {@code seed}, {@code f(seed)},
 * {@code f(f(seed))}, etc.
 *
 * <p>The first element (position {@code 0}) in the {@code LongStream} will
 * be the provided {@code seed}.  For {@code n > 0}, the element at position
 * {@code n}, will be the result of applying the function {@code f} to the
 * element at position {@code n - 1}.
 *
 * <p>The action of applying {@code f} for one element
 * <a href="../concurrent/package-summary.html#MemoryVisibility"><i>happens-before</i></a>
 * the action of applying {@code f} for subsequent elements.  For any given
 * element the action may be performed in whatever thread the library
 * chooses.
 *
 * @param seed the initial element
 * @param f a function to be applied to the previous element to produce
 *          a new element
 * @return a new sequential {@code LongStream}
 */
public static LongStream iterate(final long seed, final LongUnaryOperator f) {
    Objects.requireNonNull(f);
    Spliterator.OfLong spliterator = new Spliterators.AbstractLongSpliterator(Long.MAX_VALUE,
           Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL) {
        long prev;
        boolean started;

        @Override
        public boolean tryAdvance(LongConsumer action) {
            Objects.requireNonNull(action);
            long t;
            if (started)
                t = f.applyAsLong(prev);
            else {
                t = seed;
                started = true;
            }
            action.accept(prev = t);
            return true;
        }
    };
    return StreamSupport.longStream(spliterator, false);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:46,代碼來源:LongStream.java

示例4: forEachLong

import java.util.function.LongConsumer; //導入依賴的package包/類
@Override
public Array<T> forEachLong(LongConsumer consumer) {
    final int length = length();
    if (isParallel() && length > 0) {
        final int processors = Runtime.getRuntime().availableProcessors();
        final int splitThreshold = parallel ? Math.max(length() / processors, 10000) : Integer.MAX_VALUE;
        final ForEach action = new ForEach(0, length - 1, splitThreshold, consumer);
        ForkJoinPool.commonPool().invoke(action);
    } else {
        for (int i=0; i<length; ++i) {
            final long value = getLong(i);
            consumer.accept(value);
        }
    }
    return this;
}
 
開發者ID:zavtech,項目名稱:morpheus-core,代碼行數:17,代碼來源:ArrayBase.java

示例5: computeUserRanking

import java.util.function.LongConsumer; //導入依賴的package包/類
@Override
protected final void computeUserRanking(final Set<RunFile> runs, final long userID,
        final LongSet candidateItems, final TreeMap<Double, LongSet> ranking) {

    candidateItems.forEach((LongConsumer) itemID -> {

        final MutableInt n = new MutableInt(0);
        final MutableDouble accum = new MutableDouble(0.0);

        runs.forEach(run -> {
            final double score = run.getScore(userID, itemID, Double.NaN);
            if (!Double.isNaN(score)) {
                n.increment();
                accum.add(score);
            }
        });

        if (n.get() > 0) {
            saveScore(ranking, itemID, computeScore(n.get(), accum.get()));
        }

    });

}
 
開發者ID:dvalcarce,項目名稱:metarecsys,代碼行數:25,代碼來源:Comb.java

示例6: testLongForEachRemainingWithNull

import java.util.function.LongConsumer; //導入依賴的package包/類
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));
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:17,代碼來源:PrimitiveIteratorDefaults.java

示例7: testLongForEachRemainingWithNull

import java.util.function.LongConsumer; //導入依賴的package包/類
public void testLongForEachRemainingWithNull() {
    PrimitiveIterator.OfLong i = new PrimitiveIterator.OfLong() {
        @Override
        public long nextLong() {
            return 0;
        }

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

    assertThrowsNPE(() -> i.forEachRemaining((LongConsumer) null));
    assertThrowsNPE(() -> i.forEachRemaining((Consumer<Long>) null));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:PrimitiveIteratorDefaults.java

示例8: forEachRemaining

import java.util.function.LongConsumer; //導入依賴的package包/類
@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);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:18,代碼來源:Streams.java

示例9: testLongOps

import java.util.function.LongConsumer; //導入依賴的package包/類
@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();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:TeeOpTest.java

示例10: tryAdvance

import java.util.function.LongConsumer; //導入依賴的package包/類
@Override
public boolean tryAdvance(LongConsumer action) {
    Objects.requireNonNull(action);

    action.accept(s.getAsLong());
    return true;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:StreamSpliterators.java

示例11: fuseAndPrint

import java.util.function.LongConsumer; //導入依賴的package包/類
/**
 * Fuse the specified combination of runs and print the result.
 *
 * @param fold
 *            the fold
 * @param runs
 *            the runs of the current combination
 * @param allUsers
 *            all the users in the current combination
 * @param outputFile
 *            the path to the output file
 */
protected final void fuseAndPrint(final int fold, final Set<RunFile> runs,
        final LongSet allUsers, final Path outputFile) {

    try (final PrintWriter writer = new PrintWriter(Files.newBufferedWriter(outputFile))) {

        final LongSet all = HashLongSets.newUpdatableSet(maxRank);
        runs.forEach(run -> {
            all.addAll(run.getItems());
        });

        allUsers.forEach((LongConsumer) userID -> {
            final TreeMap<Double, LongSet> ranking = new TreeMap<Double, LongSet>(
                    Collections.reverseOrder());

            final LongSet candidateItems = HashLongSets.newUpdatableSet(maxRank);
            runs.forEach(run -> {
                candidateItems.addAll(run.getRanking(userID).keySet());
            });

            computeUserRanking(runs, userID, candidateItems, ranking);
            printRanking(userID, ranking, writer);
        });

    } catch (final IOException e) {
        throw new RuntimeException(e);
    }

}
 
開發者ID:dvalcarce,項目名稱:metarecsys,代碼行數:41,代碼來源:RankAggregation.java

示例12: forEachRemaining

import java.util.function.LongConsumer; //導入依賴的package包/類
@Override
public void forEachRemaining(LongConsumer action) {
    Objects.requireNonNull(action);

    if (count == -2) {
        action.accept(first);
        count = -1;
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:10,代碼來源:Streams.java

示例13: adapt

import java.util.function.LongConsumer; //導入依賴的package包/類
/**
 * 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;
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:15,代碼來源:LongPipeline.java

示例14: forEach

import java.util.function.LongConsumer; //導入依賴的package包/類
@Override
public void forEach(LongConsumer action) {
    if (!isParallel()) {
        adapt(sourceStageSpliterator()).forEachRemaining(action);
    } else {
        super.forEach(action);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:9,代碼來源:LongPipeline.java

示例15: forEachOrdered

import java.util.function.LongConsumer; //導入依賴的package包/類
@Override
public void forEachOrdered(LongConsumer action) {
    if (!isParallel()) {
        adapt(sourceStageSpliterator()).forEachRemaining(action);
    } else {
        super.forEachOrdered(action);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:9,代碼來源:LongPipeline.java


注:本文中的java.util.function.LongConsumer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。