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. |
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 |
|
* |
667 |
|
do { |
668 |
|
elements[i] = null; |
669 |
|
i = (i + 1) & mask; |
670 |
< |
} while(i != t); |
670 |
> |
} while (i != t); |
671 |
|
} |
672 |
|
} |
673 |
|
|
676 |
|
* in the correct order. |
677 |
|
* |
678 |
|
* @return an array containing all of the elements in this list |
679 |
< |
* in the correct order |
679 |
> |
* in the correct order |
680 |
|
*/ |
681 |
|
public Object[] toArray() { |
682 |
< |
return copyElements(new Object[size()]); |
682 |
> |
return copyElements(new Object[size()]); |
683 |
|
} |
684 |
|
|
685 |
|
/** |
694 |
|
* immediately following the end of the collection is set to <tt>null</tt>. |
695 |
|
* |
696 |
|
* @param a the array into which the elements of the deque are to |
697 |
< |
* be stored, if it is big enough; otherwise, a new array of the |
698 |
< |
* same runtime type is allocated for this purpose |
697 |
> |
* be stored, if it is big enough; otherwise, a new array of the |
698 |
> |
* same runtime type is allocated for this purpose |
699 |
|
* @return an array containing the elements of the deque |
700 |
|
* @throws ArrayStoreException if the runtime type of a is not a supertype |
701 |
|
* of the runtime type of every element in this deque |
705 |
|
if (a.length < size) |
706 |
|
a = (T[])java.lang.reflect.Array.newInstance( |
707 |
|
a.getClass().getComponentType(), size); |
708 |
< |
copyElements(a); |
708 |
> |
copyElements(a); |
709 |
|
if (a.length > size) |
710 |
|
a[size] = null; |
711 |
|
return a; |