Search in sources :

Example 6 with DoubleAccumulator

use of java8.util.concurrent.atomic.DoubleAccumulator in project streamsupport by stefan-zobel.

the class DoubleAccumulatorTest method testToString.

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

Example 7 with DoubleAccumulator

use of java8.util.concurrent.atomic.DoubleAccumulator 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 8 with DoubleAccumulator

use of java8.util.concurrent.atomic.DoubleAccumulator 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 9 with DoubleAccumulator

use of java8.util.concurrent.atomic.DoubleAccumulator 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)

Aggregations

DoubleAccumulator (java8.util.concurrent.atomic.DoubleAccumulator)9 Doubles (java8.lang.Doubles)8 ExecutorService (java.util.concurrent.ExecutorService)1 Phaser (java8.util.concurrent.Phaser)1