|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| AtomicIntegerArray | Line # 17 | 39 | 21 | 93.8% |
0.93846154
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (19) | |||
| Result | |||
|
0.2923077
|
AtomicIntegerArrayTest.testToString
AtomicIntegerArrayTest.testToString
|
1 PASS | |
|
0.23076923
|
AtomicIntegerArrayTest.testCountingInMultipleThreads
AtomicIntegerArrayTest.testCountingInMultipleThreads
|
1 PASS | |
|
0.2
|
AtomicIntegerArrayTest.testCompareAndSet
AtomicIntegerArrayTest.testCompareAndSet
|
1 PASS | |
|
0.16923077
|
AtomicIntegerArrayTest.testCompareAndSetInMultipleThreads
AtomicIntegerArrayTest.testCompareAndSetInMultipleThreads
|
1 PASS | |
|
0.16923077
|
AtomicIntegerArrayTest.testWeakCompareAndSet
AtomicIntegerArrayTest.testWeakCompareAndSet
|
1 PASS | |
|
0.15384616
|
AtomicIntegerArrayTest.testConstructor2
AtomicIntegerArrayTest.testConstructor2
|
1 PASS | |
|
0.15384616
|
AtomicIntegerArrayTest.testGetAndAdd
AtomicIntegerArrayTest.testGetAndAdd
|
1 PASS | |
|
0.12307692
|
AtomicIntegerArrayTest.testIncrementAndGet
AtomicIntegerArrayTest.testIncrementAndGet
|
1 PASS | |
|
0.12307692
|
AtomicIntegerArrayTest.testDecrementAndGet
AtomicIntegerArrayTest.testDecrementAndGet
|
1 PASS | |
|
0.12307692
|
AtomicIntegerArrayTest.testGetAndIncrement
AtomicIntegerArrayTest.testGetAndIncrement
|
1 PASS | |
|
0.12307692
|
AtomicIntegerArrayTest.testAddAndGet
AtomicIntegerArrayTest.testAddAndGet
|
1 PASS | |
|
0.12307692
|
AtomicIntegerArrayTest.testGetAndSet
AtomicIntegerArrayTest.testGetAndSet
|
1 PASS | |
|
0.092307694
|
AtomicIntegerArrayTest.testIndexing
AtomicIntegerArrayTest.testIndexing
|
1 PASS | |
|
0.092307694
|
AtomicIntegerArrayTest.testSerialization
AtomicIntegerArrayTest.testSerialization
|
1 PASS | |
|
0.092307694
|
AtomicIntegerArrayTest.testGetAndDecrement
AtomicIntegerArrayTest.testGetAndDecrement
|
1 PASS | |
|
0.092307694
|
AtomicIntegerArrayTest.testGetLazySet
AtomicIntegerArrayTest.testGetLazySet
|
1 PASS | |
|
0.092307694
|
AtomicIntegerArrayTest.testGetSet
AtomicIntegerArrayTest.testGetSet
|
1 PASS | |
|
0.06153846
|
AtomicIntegerArrayTest.testConstructor2NPE
AtomicIntegerArrayTest.testConstructor2NPE
|
1 PASS | |
|
0.06153846
|
AtomicIntegerArrayTest.testConstructor
AtomicIntegerArrayTest.testConstructor
|
1 PASS | |
| 1 | /* | |
| 2 | * Written by Doug Lea with assistance from members of JCP JSR-166 | |
| 3 | * Expert Group and released to the public domain, as explained at | |
| 4 | * http://creativecommons.org/licenses/publicdomain | |
| 5 | */ | |
| 6 | ||
| 7 | package edu.emory.mathcs.backport.java.util.concurrent.atomic; | |
| 8 | ||
| 9 | /** | |
| 10 | * An {@code int} array in which elements may be updated atomically. | |
| 11 | * See the {@link edu.emory.mathcs.backport.java.util.concurrent.atomic} package | |
| 12 | * specification for description of the properties of atomic | |
| 13 | * variables. | |
| 14 | * @since 1.5 | |
| 15 | * @author Doug Lea | |
| 16 | */ | |
| 17 | public class AtomicIntegerArray implements java.io.Serializable { | |
| 18 | private static final long serialVersionUID = 2862133569453604235L; | |
| 19 | ||
| 20 | private final int[] array; | |
| 21 | ||
| 22 | /** | |
| 23 | * Creates a new AtomicIntegerArray of given length. | |
| 24 | * | |
| 25 | * @param length the length of the array | |
| 26 | */ | |
| 27 | 16 |
public AtomicIntegerArray(int length) { |
| 28 | 16 | array = new int[length]; |
| 29 | } | |
| 30 | ||
| 31 | /** | |
| 32 | * Creates a new AtomicIntegerArray with the same length as, and | |
| 33 | * all elements copied from, the given array. | |
| 34 | * | |
| 35 | * @param array the array to copy elements from | |
| 36 | * @throws NullPointerException if array is null | |
| 37 | */ | |
| 38 | 3 |
public AtomicIntegerArray(int[] array) { |
| 39 | 3 | if (array == null) |
| 40 | 1 | throw new NullPointerException(); |
| 41 | 2 | int length = array.length; |
| 42 | 2 | this.array = new int[length]; |
| 43 | 2 | System.arraycopy(array, 0, this.array, 0, array.length); |
| 44 | } | |
| 45 | ||
| 46 | /** | |
| 47 | * Returns the length of the array. | |
| 48 | * | |
| 49 | * @return the length of the array | |
| 50 | */ | |
| 51 | 2168863 |
public final int length() { |
| 52 | 2168879 | return array.length; |
| 53 | } | |
| 54 | ||
| 55 | /** | |
| 56 | * Gets the current value at position {@code i}. | |
| 57 | * | |
| 58 | * @param i the index | |
| 59 | * @return the current value | |
| 60 | */ | |
| 61 | 2066068 |
public final synchronized int get(int i) { |
| 62 | 2066068 | return array[i]; |
| 63 | } | |
| 64 | ||
| 65 | /** | |
| 66 | * Sets the element at position {@code i} to the given value. | |
| 67 | * | |
| 68 | * @param i the index | |
| 69 | * @param newValue the new value | |
| 70 | */ | |
| 71 | 323 |
public final synchronized void set(int i, int newValue) { |
| 72 | 323 | array[i] = newValue; |
| 73 | } | |
| 74 | ||
| 75 | /** | |
| 76 | * Eventually sets the element at position {@code i} to the given value. | |
| 77 | * | |
| 78 | * @param i the index | |
| 79 | * @param newValue the new value | |
| 80 | * @since 1.6 | |
| 81 | */ | |
| 82 | 60 |
public final synchronized void lazySet(int i, int newValue) { |
| 83 | 60 | array[i] = newValue; |
| 84 | } | |
| 85 | ||
| 86 | /** | |
| 87 | * Atomically sets the element at position {@code i} to the given | |
| 88 | * value and returns the old value. | |
| 89 | * | |
| 90 | * @param i the index | |
| 91 | * @param newValue the new value | |
| 92 | * @return the previous value | |
| 93 | */ | |
| 94 | 60 |
public final synchronized int getAndSet(int i, int newValue) { |
| 95 | 60 | int old = array[i]; |
| 96 | 60 | array[i] = newValue; |
| 97 | 60 | return old; |
| 98 | } | |
| 99 | ||
| 100 | /** | |
| 101 | * Atomically sets the element at position {@code i} to the given | |
| 102 | * updated value if the current value {@code ==} the expected value. | |
| 103 | * | |
| 104 | * @param i the index | |
| 105 | * @param expect the expected value | |
| 106 | * @param update the new value | |
| 107 | * @return true if successful. False return indicates that | |
| 108 | * the actual value was not equal to the expected value. | |
| 109 | */ | |
| 110 | 2060216 |
public < |