87 |
|
// ****** Array allocation and resizing utilities ****** |
88 |
|
|
89 |
|
/** |
90 |
< |
* Allocate empty array to hold the given number of elements. |
90 |
> |
* Allocates empty array to hold the given number of elements. |
91 |
|
* |
92 |
|
* @param numElements the number of elements to hold |
93 |
|
*/ |
111 |
|
} |
112 |
|
|
113 |
|
/** |
114 |
< |
* Double the capacity of this deque. Call only when full, i.e., |
114 |
> |
* Doubles the capacity of this deque. Call only when full, i.e., |
115 |
|
* when head and tail have wrapped around to become equal. |
116 |
|
*/ |
117 |
|
private void doubleCapacity() { |
261 |
|
|
262 |
|
public E pollFirst() { |
263 |
|
int h = head; |
264 |
< |
@SuppressWarnings("unchecked") E result = (E) elements[h]; |
264 |
> |
@SuppressWarnings("unchecked") |
265 |
> |
E result = (E) elements[h]; |
266 |
|
// Element is null if deque empty |
267 |
|
if (result == null) |
268 |
|
return null; |
273 |
|
|
274 |
|
public E pollLast() { |
275 |
|
int t = (tail - 1) & (elements.length - 1); |
276 |
< |
@SuppressWarnings("unchecked") E result = (E) elements[t]; |
276 |
> |
@SuppressWarnings("unchecked") |
277 |
> |
E result = (E) elements[t]; |
278 |
|
if (result == null) |
279 |
|
return null; |
280 |
|
elements[t] = null; |
286 |
|
* @throws NoSuchElementException {@inheritDoc} |
287 |
|
*/ |
288 |
|
public E getFirst() { |
289 |
< |
@SuppressWarnings("unchecked") E result = (E) elements[head]; |
289 |
> |
@SuppressWarnings("unchecked") |
290 |
> |
E result = (E) elements[head]; |
291 |
|
if (result == null) |
292 |
|
throw new NoSuchElementException(); |
293 |
|
return result; |
603 |
|
public E next() { |
604 |
|
if (cursor == fence) |
605 |
|
throw new NoSuchElementException(); |
606 |
< |
@SuppressWarnings("unchecked") E result = (E) elements[cursor]; |
606 |
> |
@SuppressWarnings("unchecked") |
607 |
> |
E result = (E) elements[cursor]; |
608 |
|
// This check doesn't catch all possible comodifications, |
609 |
|
// but does catch the ones that corrupt traversal |
610 |
|
if (tail != fence || result == null) |
643 |
|
if (cursor == fence) |
644 |
|
throw new NoSuchElementException(); |
645 |
|
cursor = (cursor - 1) & (elements.length - 1); |
646 |
< |
@SuppressWarnings("unchecked") E result = (E) elements[cursor]; |
646 |
> |
@SuppressWarnings("unchecked") |
647 |
> |
E result = (E) elements[cursor]; |
648 |
|
if (head != fence || result == null) |
649 |
|
throw new ConcurrentModificationException(); |
650 |
|
lastRet = cursor; |
797 |
|
ArrayDeque<E> result = (ArrayDeque<E>) super.clone(); |
798 |
|
result.elements = Arrays.copyOf(elements, elements.length); |
799 |
|
return result; |
795 |
– |
|
800 |
|
} catch (CloneNotSupportedException e) { |
801 |
|
throw new AssertionError(); |
802 |
|
} |
803 |
|
} |
804 |
|
|
801 |
– |
/** |
802 |
– |
* Appease the serialization gods. |
803 |
– |
*/ |
805 |
|
private static final long serialVersionUID = 2340985798034038923L; |
806 |
|
|
807 |
|
/** |
808 |
< |
* Serialize this deque. |
808 |
> |
* Saves this deque to a stream (that is, serializes it). |
809 |
|
* |
810 |
|
* @serialData The current size (<tt>int</tt>) of the deque, |
811 |
|
* followed by all of its elements (each an object reference) in |
825 |
|
} |
826 |
|
|
827 |
|
/** |
828 |
< |
* Deserialize this deque. |
828 |
> |
* Reconstitutes this deque from a stream (that is, deserializes it). |
829 |
|
*/ |
830 |
|
private void readObject(java.io.ObjectInputStream s) |
831 |
|
throws java.io.IOException, ClassNotFoundException { |