本文整理汇总了Java中java.util.concurrent.atomic.DoubleAdder.add方法的典型用法代码示例。如果您正苦于以下问题:Java DoubleAdder.add方法的具体用法?Java DoubleAdder.add怎么用?Java DoubleAdder.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.atomic.DoubleAdder
的用法示例。
在下文中一共展示了DoubleAdder.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: DoubleConsumer
import java.util.concurrent.atomic.DoubleAdder; //导入方法依赖的package包/类
@Test
public void DoubleConsumer()
{
DoubleAdder adder = new DoubleAdder();
// TODO - Convert the anonymous inner class to a lambda
DoubleConsumer consumer = new DoubleConsumer()
{
@Override
public void accept(double value)
{
adder.add(value);
}
};
DoubleStream.of(1.0, 2.0, 3.0, 4.0, 5.0).forEach(consumer);
Assert.assertEquals(15.0, adder.doubleValue(), 0.0);
}
示例2: test_long_add
import java.util.concurrent.atomic.DoubleAdder; //导入方法依赖的package包/类
public void test_long_add() throws Exception {
DoubleAdder adder = new DoubleAdder();
adder.add(3);
String json = JSON.toJSONString(adder);
assertEquals("{\"value\":3.0}", json);
}
示例3: run
import java.util.concurrent.atomic.DoubleAdder; //导入方法依赖的package包/类
public void run() {
phaser.arriveAndAwaitAdvance();
phaser.arriveAndAwaitAdvance();
DoubleAdder a = adder;
for (int i = 0; i < incs; ++i)
a.add(1.0);
result = a.sum();
phaser.arrive();
}
示例4: testDoubleAdder
import java.util.concurrent.atomic.DoubleAdder; //导入方法依赖的package包/类
static void testDoubleAdder() {
DoubleAdder a = new DoubleAdder();
a.add(20.1d);
DoubleAdder result = echo(a);
if (result.doubleValue() != a.doubleValue())
throw new RuntimeException("Unexpected doubleValue");
checkSerialClassName(a, "java.util.concurrent.atomic.DoubleAdder$SerializationProxy");
}
示例5: testAddAndSum
import java.util.concurrent.atomic.DoubleAdder; //导入方法依赖的package包/类
/**
* add adds given value to current, and sum returns current value
*/
public void testAddAndSum() {
DoubleAdder ai = new DoubleAdder();
ai.add(2.0);
assertEquals(2.0, ai.sum());
ai.add(-4.0);
assertEquals(-2.0, ai.sum());
}
示例6: testReset
import java.util.concurrent.atomic.DoubleAdder; //导入方法依赖的package包/类
/**
* reset() causes subsequent sum() to return zero
*/
public void testReset() {
DoubleAdder ai = new DoubleAdder();
ai.add(2.0);
assertEquals(2.0, ai.sum());
ai.reset();
assertEquals(0.0, ai.sum());
}
示例7: testSumThenReset
import java.util.concurrent.atomic.DoubleAdder; //导入方法依赖的package包/类
/**
* sumThenReset() returns sum; subsequent sum() returns zero
*/
public void testSumThenReset() {
DoubleAdder ai = new DoubleAdder();
ai.add(2.0);
assertEquals(2.0, ai.sum());
assertEquals(2.0, ai.sumThenReset());
assertEquals(0.0, ai.sum());
}
示例8: testSerialization
import java.util.concurrent.atomic.DoubleAdder; //导入方法依赖的package包/类
/**
* a deserialized/reserialized adder holds same value
*/
public void testSerialization() throws Exception {
DoubleAdder x = new DoubleAdder();
DoubleAdder y = serialClone(x);
assertNotSame(x, y);
x.add(-22.0);
DoubleAdder z = serialClone(x);
assertEquals(-22.0, x.sum());
assertEquals(0.0, y.sum());
assertEquals(-22.0, z.sum());
}
示例9: testToString
import java.util.concurrent.atomic.DoubleAdder; //导入方法依赖的package包/类
/**
* toString returns current value.
*/
public void testToString() {
DoubleAdder ai = new DoubleAdder();
assertEquals(Double.toString(0.0), ai.toString());
ai.add(1.0);
assertEquals(Double.toString(1.0), ai.toString());
}
示例10: testIntValue
import java.util.concurrent.atomic.DoubleAdder; //导入方法依赖的package包/类
/**
* intValue returns current value.
*/
public void testIntValue() {
DoubleAdder ai = new DoubleAdder();
assertEquals(0, ai.intValue());
ai.add(1.0);
assertEquals(1, ai.intValue());
}
示例11: testLongValue
import java.util.concurrent.atomic.DoubleAdder; //导入方法依赖的package包/类
/**
* longValue returns current value.
*/
public void testLongValue() {
DoubleAdder ai = new DoubleAdder();
assertEquals(0, ai.longValue());
ai.add(1.0);
assertEquals(1, ai.longValue());
}
示例12: testFloatValue
import java.util.concurrent.atomic.DoubleAdder; //导入方法依赖的package包/类
/**
* floatValue returns current value.
*/
public void testFloatValue() {
DoubleAdder ai = new DoubleAdder();
assertEquals(0.0f, ai.floatValue());
ai.add(1.0);
assertEquals(1.0f, ai.floatValue());
}
示例13: testDoubleValue
import java.util.concurrent.atomic.DoubleAdder; //导入方法依赖的package包/类
/**
* doubleValue returns current value.
*/
public void testDoubleValue() {
DoubleAdder ai = new DoubleAdder();
assertEquals(0.0, ai.doubleValue());
ai.add(1.0);
assertEquals(1.0, ai.doubleValue());
}
示例14: run
import java.util.concurrent.atomic.DoubleAdder; //导入方法依赖的package包/类
public void run() {
try {
barrier.await();
DoubleAdder a = adder;
for (int i = 0; i < incs; ++i)
a.add(1.0);
result = a.sum();
barrier.await();
} catch (Throwable t) { throw new Error(t); }
}
示例15: testSerialization
import java.util.concurrent.atomic.DoubleAdder; //导入方法依赖的package包/类
/**
* a deserialized serialized adder holds same value
*/
public void testSerialization() throws Exception {
DoubleAdder x = new DoubleAdder();
DoubleAdder y = serialClone(x);
assertNotSame(x, y);
x.add(-22.0);
DoubleAdder z = serialClone(x);
assertEquals(-22.0, x.sum());
assertEquals(0.0, y.sum());
assertEquals(-22.0, z.sum());
}