Clover Coverage Report - Backport Util Concurrent v3.0
Coverage timestamp: Fri May 9 2008 11:05:23 EST
../../../../../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
39   228   21   2.44
10   83   0.54   16
16     1.31  
1    
 
  AtomicLongArray       Line # 16 39 21 93.8% 0.93846154
 
  (19)
 
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 toggle 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 toggle 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 toggle 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 toggle 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 toggle 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 toggle 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 toggle 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 toggle public final synchronized boolean compareAndSet(int i, long expect, long update) {