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    
 
  AtomicIntegerArray       Line # 17 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    * 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 toggle 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 toggle 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 toggle 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 toggle 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 toggle 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 toggle 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 toggle 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 toggle public <