--- jsr166/src/jsr166x/ArrayDeque.java 2004/12/26 20:13:15 1.2 +++ jsr166/src/jsr166x/ArrayDeque.java 2012/12/29 23:55:19 1.10 @@ -1,6 +1,6 @@ /* * Written by Josh Bloch of Google Inc. and released to the public domain, - * as explained at http://creativecommons.org/licenses/publicdomain. + * as explained at http://creativecommons.org/publicdomain/zero/1.0/. */ package jsr166x; // XXX This belongs in java.util!!! XXX @@ -13,7 +13,7 @@ import java.io.*; * usage. They are not thread-safe; in the absence of external * synchronization, they do not support concurrent access by multiple threads. * Null elements are prohibited. This class is likely to be faster than - * {@link Stack} when used as as a stack, and faster than {@link LinkedList} + * {@link Stack} when used as a stack, and faster than {@link LinkedList} * when used as a queue. * *

Most ArrayDeque operations run in amortized constant time. @@ -34,7 +34,7 @@ import java.io.*; *

Note that the fail-fast behavior of an iterator cannot be guaranteed * as it is, generally speaking, impossible to make any hard guarantees in the * presence of unsynchronized concurrent modification. Fail-fast iterators - * throw ConcurrentModificationException on a best-effort basis. + * throw ConcurrentModificationException on a best-effort basis. * Therefore, it would be wrong to write a program that depended on this * exception for its correctness: the fail-fast behavior of iterators * should be used only to detect bugs. @@ -86,11 +86,11 @@ public class ArrayDeque extends Abstr // ****** Array allocation and resizing utilities ****** /** - * Allocate empty array to hold the given number of elements. + * Allocates empty array to hold the given number of elements. * - * @param numElements the number of elements to hold. + * @param numElements the number of elements to hold */ - private void allocateElements(int numElements) { + private void allocateElements(int numElements) { int initialCapacity = MIN_INITIAL_CAPACITY; // Find the best power of two to hold elements. // Tests "<=" because arrays aren't kept full. @@ -110,11 +110,11 @@ public class ArrayDeque extends Abstr } /** - * Double the capacity of this deque. Call only when full, i.e., + * Doubles the capacity of this deque. Call only when full, i.e., * when head and tail have wrapped around to become equal. */ private void doubleCapacity() { - assert head == tail; + assert head == tail; int p = head; int n = elements.length; int r = n - p; // number of elements to the right of p @@ -130,7 +130,7 @@ public class ArrayDeque extends Abstr } /** - * Copy the elements from our element array into the specified array, + * Copies the elements from our element array into the specified array, * in order (from first to last element in the deque). It is assumed * that the array is large enough to hold all elements in the deque. * @@ -194,7 +194,7 @@ public class ArrayDeque extends Abstr if (e == null) throw new NullPointerException(); elements[head = (head - 1) & (elements.length - 1)] = e; - if (head == tail) + if (head == tail) doubleCapacity(); } @@ -243,7 +243,7 @@ public class ArrayDeque extends Abstr E result = elements[t]; if (result == null) return null; - elements[t] = null; + elements[t] = null; tail = t; return result; } @@ -504,7 +504,7 @@ public class ArrayDeque extends Abstr /** * Pops an element from the stack represented by this deque. In other - * words, removes and returns the the first element of this deque. + * words, removes and returns the first element of this deque. * *

This method is equivalent to {@link #removeFirst()}. * @@ -517,13 +517,13 @@ public class ArrayDeque extends Abstr } /** - * Remove the element at the specified position in the elements array, + * Removes the element at the specified position in the elements array, * adjusting head, tail, and size as necessary. This can result in * motion of elements backwards or forwards in the array. * *

This method is called delete rather than remove to emphasize the * that that its semantics differ from those of List.remove(int). - * + * * @return true if elements moved backwards */ private boolean delete(int i) { @@ -555,9 +555,9 @@ public class ArrayDeque extends Abstr } /** - * Returns true if this collection contains no elements.

+ * Returns true if this collection contains no elements. * - * @return true if this collection contains no elements. + * @return true if this collection contains no elements */ public boolean isEmpty() { return head == tail; @@ -568,7 +568,7 @@ public class ArrayDeque extends Abstr * will be ordered from first (head) to last (tail). This is the same * order that elements would be dequeued (via successive calls to * {@link #remove} or popped (via successive calls to {@link #pop}). - * + * * @return an Iterator over the elements in this deque */ public Iterator iterator() { @@ -667,7 +667,7 @@ public class ArrayDeque extends Abstr do { elements[i] = null; i = (i + 1) & mask; - } while(i != t); + } while (i != t); } } @@ -676,10 +676,10 @@ public class ArrayDeque extends Abstr * in the correct order. * * @return an array containing all of the elements in this list - * in the correct order + * in the correct order */ public Object[] toArray() { - return copyElements(new Object[size()]); + return copyElements(new Object[size()]); } /** @@ -694,8 +694,8 @@ public class ArrayDeque extends Abstr * immediately following the end of the collection is set to null. * * @param a the array into which the elements of the deque are to - * be stored, if it is big enough; otherwise, a new array of the - * same runtime type is allocated for this purpose + * be stored, if it is big enough; otherwise, a new array of the + * same runtime type is allocated for this purpose * @return an array containing the elements of the deque * @throws ArrayStoreException if the runtime type of a is not a supertype * of the runtime type of every element in this deque @@ -705,7 +705,7 @@ public class ArrayDeque extends Abstr if (a.length < size) a = (T[])java.lang.reflect.Array.newInstance( a.getClass().getComponentType(), size); - copyElements(a); + copyElements(a); if (a.length > size) a[size] = null; return a; @@ -719,14 +719,14 @@ public class ArrayDeque extends Abstr * @return a copy of this deque */ public ArrayDeque clone() { - try { + try { ArrayDeque result = (ArrayDeque) super.clone(); // These two lines are currently faster than cloning the array: result.elements = (E[]) new Object[elements.length]; System.arraycopy(elements, 0, result.elements, 0, elements.length); return result; - } catch (CloneNotSupportedException e) { + } catch (CloneNotSupportedException e) { throw new AssertionError(); } } @@ -737,7 +737,7 @@ public class ArrayDeque extends Abstr private static final long serialVersionUID = 2340985798034038923L; /** - * Serialize this deque. + * Serializes this deque. * * @serialData The current size (int) of the deque, * followed by all of its elements (each an object reference) in @@ -760,7 +760,7 @@ public class ArrayDeque extends Abstr } /** - * Deserialize this deque. + * Deserializes this deque. */ private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException {