本文整理匯總了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);
}
}