本文整理汇总了Java中java.util.concurrent.atomic.AtomicIntegerArray.set方法的典型用法代码示例。如果您正苦于以下问题:Java AtomicIntegerArray.set方法的具体用法?Java AtomicIntegerArray.set怎么用?Java AtomicIntegerArray.set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.atomic.AtomicIntegerArray
的用法示例。
在下文中一共展示了AtomicIntegerArray.set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testIncrementAndGet
import java.util.concurrent.atomic.AtomicIntegerArray; //导入方法依赖的package包/类
/**
* incrementAndGet increments and returns current value
*/
public void testIncrementAndGet() {
AtomicIntegerArray aa = new AtomicIntegerArray(SIZE);
for (int i = 0; i < SIZE; i++) {
aa.set(i, 1);
assertEquals(2, aa.incrementAndGet(i));
assertEquals(2, aa.get(i));
aa.set(i, -2);
assertEquals(-1, aa.incrementAndGet(i));
assertEquals(0, aa.incrementAndGet(i));
assertEquals(1, aa.incrementAndGet(i));
assertEquals(1, aa.get(i));
}
}
示例2: testAddAndGet
import java.util.concurrent.atomic.AtomicIntegerArray; //导入方法依赖的package包/类
/**
* addAndGet adds given value to current, and returns current value
*/
public void testAddAndGet() {
AtomicIntegerArray aa = new AtomicIntegerArray(SIZE);
for (int i = 0; i < SIZE; i++) {
aa.set(i, 1);
assertEquals(3, aa.addAndGet(i, 2));
assertEquals(3, aa.get(i));
assertEquals(-1, aa.addAndGet(i, -4));
assertEquals(-1, aa.get(i));
}
}
示例3: testIntArrayGetAndAccumulate
import java.util.concurrent.atomic.AtomicIntegerArray; //导入方法依赖的package包/类
/**
* AtomicIntegerArray getAndAccumulate returns previous value and updates
* with supplied function.
*/
public void testIntArrayGetAndAccumulate() {
AtomicIntegerArray a = new AtomicIntegerArray(1);
a.set(0, 1);
assertEquals(1, a.getAndAccumulate(0, 2, Integer::sum));
assertEquals(3, a.getAndAccumulate(0, 3, Integer::sum));
assertEquals(6, a.get(0));
}
示例4: testCompareAndExchangeAcquire
import java.util.concurrent.atomic.AtomicIntegerArray; //导入方法依赖的package包/类
/**
* compareAndExchangeAcquire succeeds in changing value if equal to
* expected else fails
*/
public void testCompareAndExchangeAcquire() {
AtomicIntegerArray aa = new AtomicIntegerArray(SIZE);
for (int i = 0; i < SIZE; i++) {
aa.set(i, 1);
assertEquals(1, aa.compareAndExchangeAcquire(i, 1, 2));
assertEquals(2, aa.compareAndExchangeAcquire(i, 2, -4));
assertEquals(-4, aa.get(i));
assertEquals(-4, aa.compareAndExchangeAcquire(i,-5, 7));
assertEquals(-4, aa.get(i));
assertEquals(-4, aa.compareAndExchangeAcquire(i, -4, 7));
assertEquals(7, aa.get(i));
}
}
示例5: testGetOpaqueSet
import java.util.concurrent.atomic.AtomicIntegerArray; //导入方法依赖的package包/类
/**
* getOpaque returns the last value set
*/
public void testGetOpaqueSet() {
AtomicIntegerArray aa = new AtomicIntegerArray(SIZE);
for (int i = 0; i < SIZE; i++) {
aa.set(i, 1);
assertEquals(1, aa.getOpaque(i));
aa.set(i, 2);
assertEquals(2, aa.getOpaque(i));
aa.set(i, -3);
assertEquals(-3, aa.getOpaque(i));
}
}
示例6: testGetPlainSet
import java.util.concurrent.atomic.AtomicIntegerArray; //导入方法依赖的package包/类
/**
* getPlain returns the last value set
*/
public void testGetPlainSet() {
AtomicIntegerArray aa = new AtomicIntegerArray(SIZE);
for (int i = 0; i < SIZE; i++) {
aa.set(i, 1);
assertEquals(1, aa.getPlain(i));
aa.set(i, 2);
assertEquals(2, aa.getPlain(i));
aa.set(i, -3);
assertEquals(-3, aa.getPlain(i));
}
}
示例7: testSerialization
import java.util.concurrent.atomic.AtomicIntegerArray; //导入方法依赖的package包/类
/**
* a deserialized/reserialized array holds same values in same order
*/
public void testSerialization() throws Exception {
AtomicIntegerArray x = new AtomicIntegerArray(SIZE);
for (int i = 0; i < SIZE; i++)
x.set(i, -i);
AtomicIntegerArray y = serialClone(x);
assertNotSame(x, y);
assertEquals(x.length(), y.length());
for (int i = 0; i < SIZE; i++) {
assertEquals(x.get(i), y.get(i));
}
}
示例8: test_2ci_neg
import java.util.concurrent.atomic.AtomicIntegerArray; //导入方法依赖的package包/类
static void test_2ci_neg(AtomicIntegerArray a, AtomicIntegerArray b) {
for (int i = ARRLEN-1; i >= 0; i-=1) {
a.set(i, -123);
b.set(i, -103);
}
}
示例9: test_cp_unalndst
import java.util.concurrent.atomic.AtomicIntegerArray; //导入方法依赖的package包/类
static void test_cp_unalndst(AtomicIntegerArray a, AtomicIntegerArray b) {
for (int i = 0; i < ARRLEN-UNALIGN_OFF; i+=1) {
a.set((i+UNALIGN_OFF), b.get(i));
}
}
示例10: test_ci_scl
import java.util.concurrent.atomic.AtomicIntegerArray; //导入方法依赖的package包/类
static void test_ci_scl(AtomicIntegerArray a, int old) {
for (int i = 0; i*SCALE < ARRLEN; i+=1) {
a.set((i*SCALE), -123);
}
}
示例11: test_2ci_scl
import java.util.concurrent.atomic.AtomicIntegerArray; //导入方法依赖的package包/类
static void test_2ci_scl(AtomicIntegerArray a, AtomicIntegerArray b) {
for (int i = 0; i*SCALE < ARRLEN; i+=1) {
a.set((i*SCALE), -123);
b.set((i*SCALE), -103);
}
}
示例12: test_2vi_scl
import java.util.concurrent.atomic.AtomicIntegerArray; //导入方法依赖的package包/类
static void test_2vi_scl(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) {
for (int i = 0; i*SCALE < ARRLEN; i+=1) {
a.set((i*SCALE), c);
b.set((i*SCALE), d);
}
}
示例13: test_cp_inv
import java.util.concurrent.atomic.AtomicIntegerArray; //导入方法依赖的package包/类
static void test_cp_inv(AtomicIntegerArray a, AtomicIntegerArray b, int k) {
for (int i = 0; i < ARRLEN-k; i+=1) {
a.set((i+k), b.get(i+k));
}
}
示例14: test_2ci_aln
import java.util.concurrent.atomic.AtomicIntegerArray; //导入方法依赖的package包/类
static void test_2ci_aln(AtomicIntegerArray a, AtomicIntegerArray b) {
for (int i = 0; i < ARRLEN-ALIGN_OFF; i+=1) {
a.set((i+ALIGN_OFF), -123);
b.set(i, -103);
}
}
示例15: test_2vi_off
import java.util.concurrent.atomic.AtomicIntegerArray; //导入方法依赖的package包/类
static void test_2vi_off(AtomicIntegerArray a, AtomicIntegerArray b, int c, int d) {
for (int i = 0; i < ARRLEN-OFFSET; i+=1) {
a.set((i+OFFSET), c);
b.set((i+OFFSET), d);
}
}