Search in sources :

Example 26 with Doubles

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

the class DoubleAccumulatorTest method testLongValue.

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

Example 27 with Doubles

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

the class DoubleAccumulatorTest method testAccumulateAndGet.

/**
 * accumulate accumulates given value to current, and get returns current value
 */
public void testAccumulateAndGet() {
    DoubleAccumulator acc = new DoubleAccumulator(Doubles::max, 0.0);
    acc.accumulate(2.0);
    assertEquals(2.0, acc.get());
    acc.accumulate(-4.0);
    assertEquals(2.0, acc.get());
    acc.accumulate(4.0);
    assertEquals(4.0, acc.get());
}
Also used : Doubles(java8.lang.Doubles) DoubleAccumulator(java8.util.concurrent.atomic.DoubleAccumulator)

Example 28 with Doubles

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

the class DoubleAccumulatorTest method testDoubleValue.

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

Example 29 with Doubles

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

the class ThreadLocalRandom8Test method testUnsizedDoublesCount.

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

Example 30 with Doubles

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

the class ThreadLocalRandom8Test method testUnsizedDoublesCountSeq.

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

Aggregations

SplittableRandom (java8.util.SplittableRandom)13 ThreadLocalRandom (java8.util.concurrent.ThreadLocalRandom)12 LongAdder (java8.util.concurrent.atomic.LongAdder)12 Doubles (java8.lang.Doubles)8 DoubleAccumulator (java8.util.concurrent.atomic.DoubleAccumulator)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 DoubleConsumer (java8.util.function.DoubleConsumer)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