Search in sources :

Example 1 with Longs

use of java8.lang.Longs in project streamsupport by stefan-zobel.

the class LongAccumulatorTest method testDoubleValue.

/**
 * doubleValue returns current value.
 */
public void testDoubleValue() {
    LongAccumulator acc = new LongAccumulator(Longs::max, 0L);
    assertEquals(0.0, acc.doubleValue());
    acc.accumulate(1);
    assertEquals(1.0, acc.doubleValue());
}
Also used : LongAccumulator(java8.util.concurrent.atomic.LongAccumulator) Longs(java8.lang.Longs)

Example 2 with Longs

use of java8.lang.Longs in project streamsupport by stefan-zobel.

the class SplittableRandomTest method testUnsizedLongsCountSeq.

/**
 * A sequential unsized stream of longs generates at least 100 values
 */
public void testUnsizedLongsCountSeq() {
    LongAdder counter = new LongAdder();
    SplittableRandom r = new SplittableRandom();
    long size = 100;
    r.longs().limit(size).forEach(x -> counter.increment());
    assertEquals(size, counter.sum());
}
Also used : LongAdder(java8.util.concurrent.atomic.LongAdder) SplittableRandom(java8.util.SplittableRandom)

Example 3 with Longs

use of java8.lang.Longs in project streamsupport by stefan-zobel.

the class SplittableRandomTest method testLongsCount.

/**
 * A parallel sized stream of longs generates the given number of values
 */
public void testLongsCount() {
    LongAdder counter = new LongAdder();
    SplittableRandom r = new SplittableRandom();
    long size = 0;
    for (int reps = 0; reps < REPS; ++reps) {
        counter.reset();
        r.longs(size).parallel().forEach(x -> counter.increment());
        assertEquals(size, counter.sum());
        size += 524959;
    }
}
Also used : LongAdder(java8.util.concurrent.atomic.LongAdder) SplittableRandom(java8.util.SplittableRandom)

Example 4 with Longs

use of java8.lang.Longs in project streamsupport by stefan-zobel.

the class LongAccumulatorTest method testIntValue.

/**
 * intValue returns current value.
 */
public void testIntValue() {
    LongAccumulator acc = new LongAccumulator(Longs::max, 0L);
    assertEquals(0, acc.intValue());
    acc.accumulate(1);
    assertEquals(1, acc.intValue());
}
Also used : LongAccumulator(java8.util.concurrent.atomic.LongAccumulator) Longs(java8.lang.Longs)

Example 5 with Longs

use of java8.lang.Longs in project streamsupport by stefan-zobel.

the class LongAccumulatorTest method testLongValue.

/**
 * longValue returns current value.
 */
public void testLongValue() {
    LongAccumulator acc = new LongAccumulator(Longs::max, 0L);
    assertEquals(0, acc.longValue());
    acc.accumulate(1);
    assertEquals(1, acc.longValue());
}
Also used : LongAccumulator(java8.util.concurrent.atomic.LongAccumulator) Longs(java8.lang.Longs)

Aggregations

LongAdder (java8.util.concurrent.atomic.LongAdder)12 SplittableRandom (java8.util.SplittableRandom)9 Longs (java8.lang.Longs)8 ThreadLocalRandom (java8.util.concurrent.ThreadLocalRandom)8 LongAccumulator (java8.util.concurrent.atomic.LongAccumulator)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 LongConsumer (java8.util.function.LongConsumer)4 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 Spliterator (java8.util.Spliterator)1 Spliterators (java8.util.Spliterators)1 Consumer (java8.util.function.Consumer)1 Function (java8.util.function.Function)1 DoubleStream (java8.util.stream.DoubleStream)1 DoubleStreamTestScenario (java8.util.stream.DoubleStreamTestScenario)1 IntStream (java8.util.stream.IntStream)1 IntStreamTestScenario (java8.util.stream.IntStreamTestScenario)1