AtomicBiInteger extends AtomicLong { public boolean compareAndSet(long encoded, int hi, int lo) { long update = encode(hi, lo); return compareAndSet(encoded, update); } AtomicBiInteger();  AtomicBiInteger(long encoded);  AtomicBiInteger(int hi, int lo); int getHi(); int getLo(); int getAndSetHi(int hi); int getAndSetLo(int lo); void set(int hi, int lo); boolean compareAndSetHi(int expectHi, int hi); boolean compareAndSetLo(int expectLo, int lo); boolean compareAndSet(long encoded, int hi, int lo); boolean compareAndSet(int expectHi, int hi, int expectLo, int lo); int addAndGetHi(int delta); int addAndGetLo(int delta); void add(int deltaHi, int deltaLo); static int getHi(long encoded); static int getLo(long encoded); static long encode(int hi, int lo); static long encodeHi(long encoded, int hi); static long encodeLo(long encoded, int lo);  }
@Test void testCompareAndSet() { AtomicBiInteger abi = new AtomicBiInteger(); assertEquals(0, abi.getHi()); assertEquals(0, abi.getLo()); assertFalse(abi.compareAndSetHi(1, 42)); assertTrue(abi.compareAndSetHi(0, 42)); assertEquals(42, abi.getHi()); assertEquals(0, abi.getLo()); assertFalse(abi.compareAndSetLo(1, -42)); assertTrue(abi.compareAndSetLo(0, -42)); assertEquals(42, abi.getHi()); assertEquals(-42, abi.getLo()); }