Search in sources :

Example 6 with LongAccumulator

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

the class LongAccumulatorTest method testAccumulateAndGet.

/**
 * accumulate accumulates given value to current, and get returns current value
 */
public void testAccumulateAndGet() {
    LongAccumulator acc = new LongAccumulator(Longs::max, 0L);
    acc.accumulate(2);
    assertEquals(2, acc.get());
    acc.accumulate(-4);
    assertEquals(2, acc.get());
    acc.accumulate(4);
    assertEquals(4, acc.get());
}
Also used : LongAccumulator(java8.util.concurrent.atomic.LongAccumulator) Longs(java8.lang.Longs)

Example 7 with LongAccumulator

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

the class LongAccumulatorTest method testToString.

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

Example 8 with LongAccumulator

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

the class LongAccumulatorTest method testReset.

/**
 * reset() causes subsequent get() to return zero
 */
public void testReset() {
    LongAccumulator acc = new LongAccumulator(Longs::max, 0L);
    acc.accumulate(2);
    assertEquals(2, acc.get());
    acc.reset();
    assertEquals(0, acc.get());
}
Also used : LongAccumulator(java8.util.concurrent.atomic.LongAccumulator) Longs(java8.lang.Longs)

Example 9 with LongAccumulator

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

the class LongAccumulatorTest method testFloatValue.

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

Aggregations

LongAccumulator (java8.util.concurrent.atomic.LongAccumulator)9 Longs (java8.lang.Longs)8 ExecutorService (java.util.concurrent.ExecutorService)1 Phaser (java8.util.concurrent.Phaser)1