本文整理汇总了Java中java.util.concurrent.atomic.DoubleAccumulator类的典型用法代码示例。如果您正苦于以下问题:Java DoubleAccumulator类的具体用法?Java DoubleAccumulator怎么用?Java DoubleAccumulator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DoubleAccumulator类属于java.util.concurrent.atomic包,在下文中一共展示了DoubleAccumulator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAccumulateAndGetMT
import java.util.concurrent.atomic.DoubleAccumulator; //导入依赖的package包/类
/**
* accumulates by multiple threads produce correct result
*/
public void testAccumulateAndGetMT() {
final int incs = 1000000;
final int nthreads = 4;
final ExecutorService pool = Executors.newCachedThreadPool();
DoubleAccumulator a = new DoubleAccumulator(Double::max, 0.0);
Phaser phaser = new Phaser(nthreads + 1);
for (int i = 0; i < nthreads; ++i)
pool.execute(new AccTask(a, phaser, incs));
phaser.arriveAndAwaitAdvance();
phaser.arriveAndAwaitAdvance();
double expected = incs - 1;
double result = a.get();
assertEquals(expected, result);
pool.shutdown();
}
示例2: run
import java.util.concurrent.atomic.DoubleAccumulator; //导入依赖的package包/类
public void run() {
DoubleAccumulator offset = new DoubleAccumulator((a,b) -> {return a + b;}, 0.0);
shotQueue.removeIf(s -> {
offset.accumulate(s.decay());
return s.ticksLeft == 0;
});
this.offset = offset;
if (shotQueue.isEmpty()) {
throw new RuntimeException("All done for now for this player");
}
}
示例3: testDoubleAccumulator
import java.util.concurrent.atomic.DoubleAccumulator; //导入依赖的package包/类
static void testDoubleAccumulator() {
DoubleBinaryOperator plus = (DoubleBinaryOperator & Serializable) (x, y) -> x + y;
DoubleAccumulator a = new DoubleAccumulator(plus, 13.9d);
a.accumulate(17.5d);
DoubleAccumulator result = echo(a);
if (result.get() != a.get())
throw new RuntimeException("Unexpected value");
a.reset();
result.reset();
if (result.get() != a.get())
throw new RuntimeException("Unexpected value after reset");
checkSerialClassName(a, "java.util.concurrent.atomic.DoubleAccumulator$SerializationProxy");
}
示例4: testConstructor
import java.util.concurrent.atomic.DoubleAccumulator; //导入依赖的package包/类
/**
* new instance initialized to supplied identity
*/
public void testConstructor() {
for (double identity : new double[] {
Double.NEGATIVE_INFINITY,
Double.POSITIVE_INFINITY,
Double.MIN_VALUE,
Double.MAX_VALUE,
0.0,
})
assertEquals(identity,
new DoubleAccumulator(Double::max, identity).get());
}
示例5: testAccumulateAndGet
import java.util.concurrent.atomic.DoubleAccumulator; //导入依赖的package包/类
/**
* accumulate accumulates given value to current, and get returns current value
*/
public void testAccumulateAndGet() {
DoubleAccumulator acc = new DoubleAccumulator(Double::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());
}
示例6: testReset
import java.util.concurrent.atomic.DoubleAccumulator; //导入依赖的package包/类
/**
* reset() causes subsequent get() to return zero
*/
public void testReset() {
DoubleAccumulator acc = new DoubleAccumulator(Double::max, 0.0);
acc.accumulate(2.0);
assertEquals(2.0, acc.get());
acc.reset();
assertEquals(0.0, acc.get());
}
示例7: testGetThenReset
import java.util.concurrent.atomic.DoubleAccumulator; //导入依赖的package包/类
/**
* getThenReset() returns current value; subsequent get() returns zero
*/
public void testGetThenReset() {
DoubleAccumulator acc = new DoubleAccumulator(Double::max, 0.0);
acc.accumulate(2.0);
assertEquals(2.0, acc.get());
assertEquals(2.0, acc.getThenReset());
assertEquals(0.0, acc.get());
}
示例8: testToString
import java.util.concurrent.atomic.DoubleAccumulator; //导入依赖的package包/类
/**
* toString returns current value.
*/
public void testToString() {
DoubleAccumulator acc = new DoubleAccumulator(Double::max, 0.0);
assertEquals("0.0", acc.toString());
acc.accumulate(1.0);
assertEquals(Double.toString(1.0), acc.toString());
}
示例9: testIntValue
import java.util.concurrent.atomic.DoubleAccumulator; //导入依赖的package包/类
/**
* intValue returns current value.
*/
public void testIntValue() {
DoubleAccumulator acc = new DoubleAccumulator(Double::max, 0.0);
assertEquals(0, acc.intValue());
acc.accumulate(1.0);
assertEquals(1, acc.intValue());
}
示例10: testLongValue
import java.util.concurrent.atomic.DoubleAccumulator; //导入依赖的package包/类
/**
* longValue returns current value.
*/
public void testLongValue() {
DoubleAccumulator acc = new DoubleAccumulator(Double::max, 0.0);
assertEquals(0, acc.longValue());
acc.accumulate(1.0);
assertEquals(1, acc.longValue());
}
示例11: testFloatValue
import java.util.concurrent.atomic.DoubleAccumulator; //导入依赖的package包/类
/**
* floatValue returns current value.
*/
public void testFloatValue() {
DoubleAccumulator acc = new DoubleAccumulator(Double::max, 0.0);
assertEquals(0.0f, acc.floatValue());
acc.accumulate(1.0);
assertEquals(1.0f, acc.floatValue());
}
示例12: testDoubleValue
import java.util.concurrent.atomic.DoubleAccumulator; //导入依赖的package包/类
/**
* doubleValue returns current value.
*/
public void testDoubleValue() {
DoubleAccumulator acc = new DoubleAccumulator(Double::max, 0.0);
assertEquals(0.0, acc.doubleValue());
acc.accumulate(1.0);
assertEquals(1.0, acc.doubleValue());
}
示例13: testAccumulateAndGet
import java.util.concurrent.atomic.DoubleAccumulator; //导入依赖的package包/类
/**
* accumulate accumulates given value to current, and get returns current value
*/
public void testAccumulateAndGet() {
DoubleAccumulator ai = new DoubleAccumulator(Double::max, 0.0);
ai.accumulate(2.0);
assertEquals(2.0, ai.get());
ai.accumulate(-4.0);
assertEquals(2.0, ai.get());
ai.accumulate(4.0);
assertEquals(4.0, ai.get());
}
示例14: testReset
import java.util.concurrent.atomic.DoubleAccumulator; //导入依赖的package包/类
/**
* reset() causes subsequent get() to return zero
*/
public void testReset() {
DoubleAccumulator ai = new DoubleAccumulator(Double::max, 0.0);
ai.accumulate(2.0);
assertEquals(2.0, ai.get());
ai.reset();
assertEquals(0.0, ai.get());
}
示例15: testGetThenReset
import java.util.concurrent.atomic.DoubleAccumulator; //导入依赖的package包/类
/**
* getThenReset() returns current value; subsequent get() returns zero
*/
public void testGetThenReset() {
DoubleAccumulator ai = new DoubleAccumulator(Double::max, 0.0);
ai.accumulate(2.0);
assertEquals(2.0, ai.get());
assertEquals(2.0, ai.getThenReset());
assertEquals(0.0, ai.get());
}