|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| AtomicLongArray | Line # 16 | 39 | 21 | 93.8% |
0.93846154
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (19) | |||
| Result | |||
|
0.2923077
|
AtomicLongArrayTest.testToString
AtomicLongArrayTest.testToString
|
1 PASS | |
|
0.23076923
|
AtomicLongArrayTest.testCountingInMultipleThreads
AtomicLongArrayTest.testCountingInMultipleThreads
|
1 PASS | |
|
0.2
|
AtomicLongArrayTest.testCompareAndSet
AtomicLongArrayTest.testCompareAndSet
|
1 PASS | |
|
0.16923077
|
AtomicLongArrayTest.testWeakCompareAndSet
AtomicLongArrayTest.testWeakCompareAndSet
|
1 PASS | |
|
0.16923077
|
AtomicLongArrayTest.testCompareAndSetInMultipleThreads
AtomicLongArrayTest.testCompareAndSetInMultipleThreads
|
1 PASS | |
|
0.15384616
|
AtomicLongArrayTest.testConstructor2
AtomicLongArrayTest.testConstructor2
|
1 PASS | |
|
0.15384616
|
AtomicLongArrayTest.testGetAndAdd
AtomicLongArrayTest.testGetAndAdd
|
1 PASS | |
|
0.12307692
|
AtomicLongArrayTest.testAddAndGet
AtomicLongArrayTest.testAddAndGet
|
1 PASS | |
|
0.12307692
|
AtomicLongArrayTest.testDecrementAndGet
AtomicLongArrayTest.testDecrementAndGet
|
1 PASS | |
|
0.12307692
|
AtomicLongArrayTest.testGetAndIncrement
AtomicLongArrayTest.testGetAndIncrement
|
1 PASS | |
|
0.12307692
|
AtomicLongArrayTest.testIncrementAndGet
AtomicLongArrayTest.testIncrementAndGet
|
1 PASS | |
|
0.12307692
|
AtomicLongArrayTest.testGetAndSet
AtomicLongArrayTest.testGetAndSet
|
1 PASS | |
|
0.092307694
|
AtomicLongArrayTest.testSerialization
AtomicLongArrayTest.testSerialization
|
1 PASS | |
|
0.092307694
|
AtomicLongArrayTest.testGetLazySet
AtomicLongArrayTest.testGetLazySet
|
1 PASS | |
|
0.092307694
|
AtomicLongArrayTest.testIndexing
AtomicLongArrayTest.testIndexing
|
1 PASS | |
|
0.092307694
|
AtomicLongArrayTest.testGetAndDecrement
AtomicLongArrayTest.testGetAndDecrement
|
1 PASS | |
|
0.092307694
|
AtomicLongArrayTest.testGetSet
AtomicLongArrayTest.testGetSet
|
1 PASS | |
|
0.06153846
|
AtomicLongArrayTest.testConstructor
AtomicLongArrayTest.testConstructor
|
1 PASS | |
|
0.06153846
|
AtomicLongArrayTest.testConstructor2NPE
AtomicLongArrayTest.testConstructor2NPE
|
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 | * A {@code long} array in which elements may be updated atomically. | |
| 11 | * See the {@link edu.emory.mathcs.backport.java.util.concurrent.atomic} package specification | |
| 12 | * for description of the properties of atomic variables. | |
| 13 | * @since 1.5 | |
| 14 | * @author Doug Lea | |
| 15 | */ | |
| 16 | public class AtomicLongArray implements java.io.Serializable { | |
| 17 | private static final long serialVersionUID = -2308431214976778248L; | |
| 18 | ||
| 19 | private final long[] array; | |
| 20 | ||
| 21 | /** | |
| 22 | * Creates a new AtomicLongArray of given length. | |
| 23 | * | |
| 24 | * @param length the length of the array | |
| 25 | */ | |
| 26 | 16 |
public AtomicLongArray(int length) { |
| 27 | 16 | array = new long[length]; |
| 28 | } | |
| 29 | ||
| 30 | /** | |
| 31 | * Creates a new AtomicLongArray with the same length as, and | |
| 32 | * all elements copied from, the given array. | |
| 33 | * | |
| 34 | * @param array the array to copy elements from | |
| 35 | * @throws NullPointerException if array is null | |
| 36 | */ | |
| 37 | 3 |
public AtomicLongArray(long[] array) { |
| 38 | 3 | if (array == null) |
| 39 | 1 | throw new NullPointerException(); |
| 40 | 2 | int length = array.length; |
| 41 | 2 | this.array = new long[length]; |
| 42 | 2 | System.arraycopy(array, 0, this.array, 0, array.length); |
| 43 | } | |
| 44 | ||
| 45 | /** | |
| 46 | * Returns the length of the array. | |
| 47 | * | |
| 48 | * @return the length of the array | |
| 49 | */ | |
| 50 | 2177909 |
public final int length() { |
| 51 | 2177908 | return array.length; |
| 52 | } | |
| 53 | ||
| 54 | /** | |
| 55 | * Gets the current value at position {@code i}. | |
| 56 | * | |
| 57 | * @param i the index | |
| 58 | * @return the current value | |
| 59 | */ | |
| 60 | 2074668 |
public final synchronized long get(int i) { |
| 61 | 2074668 | return array[i]; |
| 62 | } | |
| 63 | ||
| 64 | /** | |
| 65 | * Sets the element at position {@code i} to the given value. | |
| 66 | * | |
| 67 | * @param i the index | |
| 68 | * @param newValue the new value | |
| 69 | */ | |
| 70 | 323 |
public final synchronized void set(int i, long newValue) { |
| 71 | 323 | array[i] = newValue; |
| 72 | } | |
| 73 | ||
| 74 | /** | |
| 75 | * Eventually sets the element at position {@code i} to the given value. | |
| 76 | * | |
| 77 | * @param i the index | |
| 78 | * @param newValue the new value | |
| 79 | * @since 1.6 | |
| 80 | */ | |
| 81 | 60 |
public final synchronized void lazySet(int i, long newValue) { |
| 82 | 60 | array[i] = newValue; |
| 83 | } | |
| 84 | ||
| 85 | ||
| 86 | /** | |
| 87 | * Atomically sets the element at position {@code i} to the given value | |
| 88 | * 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 long getAndSet(int i, long newValue) { |
| 95 | 60 | long old = array[i]; |
| 96 | 60 | array[i] = newValue; |
| 97 | 60 | return old; |
| 98 | } | |
| 99 | ||
| 100 | /** | |
| 101 | * Atomically sets the value to the given updated value | |
| 102 | * 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 | 2064344 |
public final synchronized boolean compareAndSet(int i, long expect, long update) { |