1 |
|
/* |
2 |
|
* Written by Josh Bloch of Google Inc. and released to the public domain, |
3 |
< |
* as explained at http://creativecommons.org/licenses/publicdomain. |
3 |
> |
* as explained at http://creativecommons.org/publicdomain/zero/1.0/. |
4 |
|
*/ |
5 |
|
|
6 |
|
package jsr166x; // XXX This belongs in java.util!!! XXX |
13 |
|
* usage. They are not thread-safe; in the absence of external |
14 |
|
* synchronization, they do not support concurrent access by multiple threads. |
15 |
|
* Null elements are prohibited. This class is likely to be faster than |
16 |
< |
* {@link Stack} when used as as a stack, and faster than {@link LinkedList} |
16 |
> |
* {@link Stack} when used as a stack, and faster than {@link LinkedList} |
17 |
|
* when used as a queue. |
18 |
|
* |
19 |
|
* <p>Most <tt>ArrayDeque</tt> operations run in amortized constant time. |
86 |
|
// ****** Array allocation and resizing utilities ****** |
87 |
|
|
88 |
|
/** |
89 |
< |
* Allocate empty array to hold the given number of elements. |
89 |
> |
* Allocates empty array to hold the given number of elements. |
90 |
|
* |
91 |
< |
* @param numElements the number of elements to hold. |
91 |
> |
* @param numElements the number of elements to hold |
92 |
|
*/ |
93 |
|
private void allocateElements(int numElements) { |
94 |
|
int initialCapacity = MIN_INITIAL_CAPACITY; |
110 |
|
} |
111 |
|
|
112 |
|
/** |
113 |
< |
* Double the capacity of this deque. Call only when full, i.e., |
113 |
> |
* Doubles the capacity of this deque. Call only when full, i.e., |
114 |
|
* when head and tail have wrapped around to become equal. |
115 |
|
*/ |
116 |
|
private void doubleCapacity() { |
130 |
|
} |
131 |
|
|
132 |
|
/** |
133 |
< |
* Copy the elements from our element array into the specified array, |
133 |
> |
* Copies the elements from our element array into the specified array, |
134 |
|
* in order (from first to last element in the deque). It is assumed |
135 |
|
* that the array is large enough to hold all elements in the deque. |
136 |
|
* |
504 |
|
|
505 |
|
/** |
506 |
|
* Pops an element from the stack represented by this deque. In other |
507 |
< |
* words, removes and returns the the first element of this deque. |
507 |
> |
* words, removes and returns the first element of this deque. |
508 |
|
* |
509 |
|
* <p>This method is equivalent to {@link #removeFirst()}. |
510 |
|
* |
517 |
|
} |
518 |
|
|
519 |
|
/** |
520 |
< |
* Remove the element at the specified position in the elements array, |
520 |
> |
* Removes the element at the specified position in the elements array, |
521 |
|
* adjusting head, tail, and size as necessary. This can result in |
522 |
|
* motion of elements backwards or forwards in the array. |
523 |
|
* |
555 |
|
} |
556 |
|
|
557 |
|
/** |
558 |
< |
* Returns <tt>true</tt> if this collection contains no elements.<p> |
558 |
> |
* Returns <tt>true</tt> if this collection contains no elements. |
559 |
|
* |
560 |
< |
* @return <tt>true</tt> if this collection contains no elements. |
560 |
> |
* @return <tt>true</tt> if this collection contains no elements |
561 |
|
*/ |
562 |
|
public boolean isEmpty() { |
563 |
|
return head == tail; |
667 |
|
do { |
668 |
|
elements[i] = null; |
669 |
|
i = (i + 1) & mask; |
670 |
< |
} while(i != t); |
670 |
> |
} while (i != t); |
671 |
|
} |
672 |
|
} |
673 |
|
|
737 |
|
private static final long serialVersionUID = 2340985798034038923L; |
738 |
|
|
739 |
|
/** |
740 |
< |
* Serialize this deque. |
740 |
> |
* Serializes this deque. |
741 |
|
* |
742 |
|
* @serialData The current size (<tt>int</tt>) of the deque, |
743 |
|
* followed by all of its elements (each an object reference) in |
760 |
|
} |
761 |
|
|
762 |
|
/** |
763 |
< |
* Deserialize this deque. |
763 |
> |
* Deserializes this deque. |
764 |
|
*/ |
765 |
|
private void readObject(ObjectInputStream s) |
766 |
|
throws IOException, ClassNotFoundException { |