author | dl |
Mon, 12 Sep 2016 13:14:49 -0700 | |
changeset 40817 | 4f5fb115676d |
parent 32991 | b27c76b82713 |
child 42319 | 0193886267c3 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
3 |
* |
|
4 |
* This code is free software; you can redistribute it and/or modify it |
|
5 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 6 |
* published by the Free Software Foundation. Oracle designates this |
2 | 7 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 8 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 9 |
* |
10 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
11 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
14 |
* accompanied this code). |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License version |
|
17 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
18 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
19 |
* |
|
5506 | 20 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
21 |
* or visit www.oracle.com if you need additional information or have any |
|
22 |
* questions. |
|
2 | 23 |
*/ |
24 |
||
25 |
/* |
|
26 |
* This file is available under and governed by the GNU General Public |
|
27 |
* License version 2 only, as published by the Free Software Foundation. |
|
28 |
* However, the following notice accompanied the original version of this |
|
29 |
* file: |
|
30 |
* |
|
31 |
* Written by Josh Bloch of Google Inc. and released to the public domain, |
|
9242
ef138d47df58
7034657: Update Creative Commons license URL in legal notices
dl
parents:
5506
diff
changeset
|
32 |
* as explained at http://creativecommons.org/publicdomain/zero/1.0/. |
2 | 33 |
*/ |
34 |
||
35 |
package java.util; |
|
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
36 |
|
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
37 |
import java.io.Serializable; |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
38 |
import java.util.function.Consumer; |
2 | 39 |
|
40 |
/** |
|
41 |
* Resizable-array implementation of the {@link Deque} interface. Array |
|
42 |
* deques have no capacity restrictions; they grow as necessary to support |
|
43 |
* usage. They are not thread-safe; in the absence of external |
|
44 |
* synchronization, they do not support concurrent access by multiple threads. |
|
45 |
* Null elements are prohibited. This class is likely to be faster than |
|
46 |
* {@link Stack} when used as a stack, and faster than {@link LinkedList} |
|
47 |
* when used as a queue. |
|
48 |
* |
|
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
49 |
* <p>Most {@code ArrayDeque} operations run in amortized constant time. |
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
50 |
* Exceptions include |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
51 |
* {@link #remove(Object) remove}, |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
52 |
* {@link #removeFirstOccurrence removeFirstOccurrence}, |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
53 |
* {@link #removeLastOccurrence removeLastOccurrence}, |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
54 |
* {@link #contains contains}, |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
55 |
* {@link #iterator iterator.remove()}, |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
56 |
* and the bulk operations, all of which run in linear time. |
2 | 57 |
* |
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
58 |
* <p>The iterators returned by this class's {@link #iterator() iterator} |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
59 |
* method are <em>fail-fast</em>: If the deque is modified at any time after |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
60 |
* the iterator is created, in any way except through the iterator's own |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
61 |
* {@code remove} method, the iterator will generally throw a {@link |
2 | 62 |
* ConcurrentModificationException}. Thus, in the face of concurrent |
63 |
* modification, the iterator fails quickly and cleanly, rather than risking |
|
64 |
* arbitrary, non-deterministic behavior at an undetermined time in the |
|
65 |
* future. |
|
66 |
* |
|
67 |
* <p>Note that the fail-fast behavior of an iterator cannot be guaranteed |
|
68 |
* as it is, generally speaking, impossible to make any hard guarantees in the |
|
69 |
* presence of unsynchronized concurrent modification. Fail-fast iterators |
|
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
70 |
* throw {@code ConcurrentModificationException} on a best-effort basis. |
2 | 71 |
* Therefore, it would be wrong to write a program that depended on this |
72 |
* exception for its correctness: <i>the fail-fast behavior of iterators |
|
73 |
* should be used only to detect bugs.</i> |
|
74 |
* |
|
75 |
* <p>This class and its iterator implement all of the |
|
76 |
* <em>optional</em> methods of the {@link Collection} and {@link |
|
77 |
* Iterator} interfaces. |
|
78 |
* |
|
79 |
* <p>This class is a member of the |
|
80 |
* <a href="{@docRoot}/../technotes/guides/collections/index.html"> |
|
81 |
* Java Collections Framework</a>. |
|
82 |
* |
|
83 |
* @author Josh Bloch and Doug Lea |
|
40817
4f5fb115676d
8164169: Miscellaneous changes imported from jsr166 CVS 2016-09
dl
parents:
32991
diff
changeset
|
84 |
* @param <E> the type of elements held in this deque |
2 | 85 |
* @since 1.6 |
86 |
*/ |
|
87 |
public class ArrayDeque<E> extends AbstractCollection<E> |
|
88 |
implements Deque<E>, Cloneable, Serializable |
|
89 |
{ |
|
90 |
/** |
|
91 |
* The array in which the elements of the deque are stored. |
|
92 |
* The capacity of the deque is the length of this array, which is |
|
93 |
* always a power of two. The array is never allowed to become |
|
94 |
* full, except transiently within an addX method where it is |
|
95 |
* resized (see doubleCapacity) immediately upon becoming full, |
|
96 |
* thus avoiding head and tail wrapping around to equal each |
|
97 |
* other. We also guarantee that all array cells not holding |
|
98 |
* deque elements are always null. |
|
99 |
*/ |
|
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
100 |
transient Object[] elements; // non-private to simplify nested class access |
2 | 101 |
|
102 |
/** |
|
103 |
* The index of the element at the head of the deque (which is the |
|
104 |
* element that would be removed by remove() or pop()); or an |
|
105 |
* arbitrary number equal to tail if the deque is empty. |
|
106 |
*/ |
|
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
107 |
transient int head; |
2 | 108 |
|
109 |
/** |
|
110 |
* The index at which the next element would be added to the tail |
|
111 |
* of the deque (via addLast(E), add(E), or push(E)). |
|
112 |
*/ |
|
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
113 |
transient int tail; |
2 | 114 |
|
115 |
/** |
|
116 |
* The minimum capacity that we'll use for a newly created deque. |
|
117 |
* Must be a power of 2. |
|
118 |
*/ |
|
119 |
private static final int MIN_INITIAL_CAPACITY = 8; |
|
120 |
||
121 |
// ****** Array allocation and resizing utilities ****** |
|
122 |
||
123 |
/** |
|
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
124 |
* Allocates empty array to hold the given number of elements. |
2 | 125 |
* |
126 |
* @param numElements the number of elements to hold |
|
127 |
*/ |
|
128 |
private void allocateElements(int numElements) { |
|
129 |
int initialCapacity = MIN_INITIAL_CAPACITY; |
|
130 |
// Find the best power of two to hold elements. |
|
131 |
// Tests "<=" because arrays aren't kept full. |
|
132 |
if (numElements >= initialCapacity) { |
|
133 |
initialCapacity = numElements; |
|
134 |
initialCapacity |= (initialCapacity >>> 1); |
|
135 |
initialCapacity |= (initialCapacity >>> 2); |
|
136 |
initialCapacity |= (initialCapacity >>> 4); |
|
137 |
initialCapacity |= (initialCapacity >>> 8); |
|
138 |
initialCapacity |= (initialCapacity >>> 16); |
|
139 |
initialCapacity++; |
|
140 |
||
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
141 |
if (initialCapacity < 0) // Too many elements, must back off |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
142 |
initialCapacity >>>= 1; // Good luck allocating 2^30 elements |
2 | 143 |
} |
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
144 |
elements = new Object[initialCapacity]; |
2 | 145 |
} |
146 |
||
147 |
/** |
|
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
148 |
* Doubles the capacity of this deque. Call only when full, i.e., |
2 | 149 |
* when head and tail have wrapped around to become equal. |
150 |
*/ |
|
151 |
private void doubleCapacity() { |
|
152 |
assert head == tail; |
|
153 |
int p = head; |
|
154 |
int n = elements.length; |
|
155 |
int r = n - p; // number of elements to the right of p |
|
156 |
int newCapacity = n << 1; |
|
157 |
if (newCapacity < 0) |
|
158 |
throw new IllegalStateException("Sorry, deque too big"); |
|
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
159 |
Object[] a = new Object[newCapacity]; |
2 | 160 |
System.arraycopy(elements, p, a, 0, r); |
161 |
System.arraycopy(elements, 0, a, r, p); |
|
13795
73850c397272
7193406: Clean-up JDK Build Warnings in java.util, java.io
dxu
parents:
12448
diff
changeset
|
162 |
elements = a; |
2 | 163 |
head = 0; |
164 |
tail = n; |
|
165 |
} |
|
166 |
||
167 |
/** |
|
168 |
* Constructs an empty array deque with an initial capacity |
|
169 |
* sufficient to hold 16 elements. |
|
170 |
*/ |
|
171 |
public ArrayDeque() { |
|
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
172 |
elements = new Object[16]; |
2 | 173 |
} |
174 |
||
175 |
/** |
|
176 |
* Constructs an empty array deque with an initial capacity |
|
177 |
* sufficient to hold the specified number of elements. |
|
178 |
* |
|
179 |
* @param numElements lower bound on initial capacity of the deque |
|
180 |
*/ |
|
181 |
public ArrayDeque(int numElements) { |
|
182 |
allocateElements(numElements); |
|
183 |
} |
|
184 |
||
185 |
/** |
|
186 |
* Constructs a deque containing the elements of the specified |
|
187 |
* collection, in the order they are returned by the collection's |
|
188 |
* iterator. (The first element returned by the collection's |
|
189 |
* iterator becomes the first element, or <i>front</i> of the |
|
190 |
* deque.) |
|
191 |
* |
|
192 |
* @param c the collection whose elements are to be placed into the deque |
|
193 |
* @throws NullPointerException if the specified collection is null |
|
194 |
*/ |
|
195 |
public ArrayDeque(Collection<? extends E> c) { |
|
196 |
allocateElements(c.size()); |
|
197 |
addAll(c); |
|
198 |
} |
|
199 |
||
200 |
// The main insertion and extraction methods are addFirst, |
|
201 |
// addLast, pollFirst, pollLast. The other methods are defined in |
|
202 |
// terms of these. |
|
203 |
||
204 |
/** |
|
205 |
* Inserts the specified element at the front of this deque. |
|
206 |
* |
|
207 |
* @param e the element to add |
|
208 |
* @throws NullPointerException if the specified element is null |
|
209 |
*/ |
|
210 |
public void addFirst(E e) { |
|
211 |
if (e == null) |
|
212 |
throw new NullPointerException(); |
|
213 |
elements[head = (head - 1) & (elements.length - 1)] = e; |
|
214 |
if (head == tail) |
|
215 |
doubleCapacity(); |
|
216 |
} |
|
217 |
||
218 |
/** |
|
219 |
* Inserts the specified element at the end of this deque. |
|
220 |
* |
|
221 |
* <p>This method is equivalent to {@link #add}. |
|
222 |
* |
|
223 |
* @param e the element to add |
|
224 |
* @throws NullPointerException if the specified element is null |
|
225 |
*/ |
|
226 |
public void addLast(E e) { |
|
227 |
if (e == null) |
|
228 |
throw new NullPointerException(); |
|
229 |
elements[tail] = e; |
|
230 |
if ( (tail = (tail + 1) & (elements.length - 1)) == head) |
|
231 |
doubleCapacity(); |
|
232 |
} |
|
233 |
||
234 |
/** |
|
235 |
* Inserts the specified element at the front of this deque. |
|
236 |
* |
|
237 |
* @param e the element to add |
|
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
238 |
* @return {@code true} (as specified by {@link Deque#offerFirst}) |
2 | 239 |
* @throws NullPointerException if the specified element is null |
240 |
*/ |
|
241 |
public boolean offerFirst(E e) { |
|
242 |
addFirst(e); |
|
243 |
return true; |
|
244 |
} |
|
245 |
||
246 |
/** |
|
247 |
* Inserts the specified element at the end of this deque. |
|
248 |
* |
|
249 |
* @param e the element to add |
|
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
250 |
* @return {@code true} (as specified by {@link Deque#offerLast}) |
2 | 251 |
* @throws NullPointerException if the specified element is null |
252 |
*/ |
|
253 |
public boolean offerLast(E e) { |
|
254 |
addLast(e); |
|
255 |
return true; |
|
256 |
} |
|
257 |
||
258 |
/** |
|
259 |
* @throws NoSuchElementException {@inheritDoc} |
|
260 |
*/ |
|
261 |
public E removeFirst() { |
|
262 |
E x = pollFirst(); |
|
263 |
if (x == null) |
|
264 |
throw new NoSuchElementException(); |
|
265 |
return x; |
|
266 |
} |
|
267 |
||
268 |
/** |
|
269 |
* @throws NoSuchElementException {@inheritDoc} |
|
270 |
*/ |
|
271 |
public E removeLast() { |
|
272 |
E x = pollLast(); |
|
273 |
if (x == null) |
|
274 |
throw new NoSuchElementException(); |
|
275 |
return x; |
|
276 |
} |
|
277 |
||
278 |
public E pollFirst() { |
|
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
279 |
final Object[] elements = this.elements; |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
280 |
final int h = head; |
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
281 |
@SuppressWarnings("unchecked") |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
282 |
E result = (E) elements[h]; |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
283 |
// Element is null if deque empty |
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
284 |
if (result != null) { |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
285 |
elements[h] = null; // Must null out slot |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
286 |
head = (h + 1) & (elements.length - 1); |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
287 |
} |
2 | 288 |
return result; |
289 |
} |
|
290 |
||
291 |
public E pollLast() { |
|
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
292 |
final Object[] elements = this.elements; |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
293 |
final int t = (tail - 1) & (elements.length - 1); |
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
294 |
@SuppressWarnings("unchecked") |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
295 |
E result = (E) elements[t]; |
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
296 |
if (result != null) { |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
297 |
elements[t] = null; |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
298 |
tail = t; |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
299 |
} |
2 | 300 |
return result; |
301 |
} |
|
302 |
||
303 |
/** |
|
304 |
* @throws NoSuchElementException {@inheritDoc} |
|
305 |
*/ |
|
306 |
public E getFirst() { |
|
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
307 |
@SuppressWarnings("unchecked") |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
308 |
E result = (E) elements[head]; |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
309 |
if (result == null) |
2 | 310 |
throw new NoSuchElementException(); |
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
311 |
return result; |
2 | 312 |
} |
313 |
||
314 |
/** |
|
315 |
* @throws NoSuchElementException {@inheritDoc} |
|
316 |
*/ |
|
317 |
public E getLast() { |
|
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
318 |
@SuppressWarnings("unchecked") |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
319 |
E result = (E) elements[(tail - 1) & (elements.length - 1)]; |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
320 |
if (result == null) |
2 | 321 |
throw new NoSuchElementException(); |
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
322 |
return result; |
2 | 323 |
} |
324 |
||
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
325 |
@SuppressWarnings("unchecked") |
2 | 326 |
public E peekFirst() { |
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
327 |
// elements[head] is null if deque empty |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
328 |
return (E) elements[head]; |
2 | 329 |
} |
330 |
||
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
331 |
@SuppressWarnings("unchecked") |
2 | 332 |
public E peekLast() { |
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
333 |
return (E) elements[(tail - 1) & (elements.length - 1)]; |
2 | 334 |
} |
335 |
||
336 |
/** |
|
337 |
* Removes the first occurrence of the specified element in this |
|
338 |
* deque (when traversing the deque from head to tail). |
|
339 |
* If the deque does not contain the element, it is unchanged. |
|
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
340 |
* More formally, removes the first element {@code e} such that |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
341 |
* {@code o.equals(e)} (if such an element exists). |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
342 |
* Returns {@code true} if this deque contained the specified element |
2 | 343 |
* (or equivalently, if this deque changed as a result of the call). |
344 |
* |
|
345 |
* @param o element to be removed from this deque, if present |
|
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
346 |
* @return {@code true} if the deque contained the specified element |
2 | 347 |
*/ |
348 |
public boolean removeFirstOccurrence(Object o) { |
|
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
349 |
if (o != null) { |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
350 |
int mask = elements.length - 1; |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
351 |
int i = head; |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
352 |
for (Object x; (x = elements[i]) != null; i = (i + 1) & mask) { |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
353 |
if (o.equals(x)) { |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
354 |
delete(i); |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
355 |
return true; |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
356 |
} |
2 | 357 |
} |
358 |
} |
|
359 |
return false; |
|
360 |
} |
|
361 |
||
362 |
/** |
|
363 |
* Removes the last occurrence of the specified element in this |
|
364 |
* deque (when traversing the deque from head to tail). |
|
365 |
* If the deque does not contain the element, it is unchanged. |
|
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
366 |
* More formally, removes the last element {@code e} such that |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
367 |
* {@code o.equals(e)} (if such an element exists). |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
368 |
* Returns {@code true} if this deque contained the specified element |
2 | 369 |
* (or equivalently, if this deque changed as a result of the call). |
370 |
* |
|
371 |
* @param o element to be removed from this deque, if present |
|
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
372 |
* @return {@code true} if the deque contained the specified element |
2 | 373 |
*/ |
374 |
public boolean removeLastOccurrence(Object o) { |
|
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
375 |
if (o != null) { |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
376 |
int mask = elements.length - 1; |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
377 |
int i = (tail - 1) & mask; |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
378 |
for (Object x; (x = elements[i]) != null; i = (i - 1) & mask) { |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
379 |
if (o.equals(x)) { |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
380 |
delete(i); |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
381 |
return true; |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
382 |
} |
2 | 383 |
} |
384 |
} |
|
385 |
return false; |
|
386 |
} |
|
387 |
||
388 |
// *** Queue methods *** |
|
389 |
||
390 |
/** |
|
391 |
* Inserts the specified element at the end of this deque. |
|
392 |
* |
|
393 |
* <p>This method is equivalent to {@link #addLast}. |
|
394 |
* |
|
395 |
* @param e the element to add |
|
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
396 |
* @return {@code true} (as specified by {@link Collection#add}) |
2 | 397 |
* @throws NullPointerException if the specified element is null |
398 |
*/ |
|
399 |
public boolean add(E e) { |
|
400 |
addLast(e); |
|
401 |
return true; |
|
402 |
} |
|
403 |
||
404 |
/** |
|
405 |
* Inserts the specified element at the end of this deque. |
|
406 |
* |
|
407 |
* <p>This method is equivalent to {@link #offerLast}. |
|
408 |
* |
|
409 |
* @param e the element to add |
|
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
410 |
* @return {@code true} (as specified by {@link Queue#offer}) |
2 | 411 |
* @throws NullPointerException if the specified element is null |
412 |
*/ |
|
413 |
public boolean offer(E e) { |
|
414 |
return offerLast(e); |
|
415 |
} |
|
416 |
||
417 |
/** |
|
418 |
* Retrieves and removes the head of the queue represented by this deque. |
|
419 |
* |
|
420 |
* This method differs from {@link #poll poll} only in that it throws an |
|
421 |
* exception if this deque is empty. |
|
422 |
* |
|
423 |
* <p>This method is equivalent to {@link #removeFirst}. |
|
424 |
* |
|
425 |
* @return the head of the queue represented by this deque |
|
426 |
* @throws NoSuchElementException {@inheritDoc} |
|
427 |
*/ |
|
428 |
public E remove() { |
|
429 |
return removeFirst(); |
|
430 |
} |
|
431 |
||
432 |
/** |
|
433 |
* Retrieves and removes the head of the queue represented by this deque |
|
434 |
* (in other words, the first element of this deque), or returns |
|
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
435 |
* {@code null} if this deque is empty. |
2 | 436 |
* |
437 |
* <p>This method is equivalent to {@link #pollFirst}. |
|
438 |
* |
|
439 |
* @return the head of the queue represented by this deque, or |
|
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
440 |
* {@code null} if this deque is empty |
2 | 441 |
*/ |
442 |
public E poll() { |
|
443 |
return pollFirst(); |
|
444 |
} |
|
445 |
||
446 |
/** |
|
447 |
* Retrieves, but does not remove, the head of the queue represented by |
|
448 |
* this deque. This method differs from {@link #peek peek} only in |
|
449 |
* that it throws an exception if this deque is empty. |
|
450 |
* |
|
451 |
* <p>This method is equivalent to {@link #getFirst}. |
|
452 |
* |
|
453 |
* @return the head of the queue represented by this deque |
|
454 |
* @throws NoSuchElementException {@inheritDoc} |
|
455 |
*/ |
|
456 |
public E element() { |
|
457 |
return getFirst(); |
|
458 |
} |
|
459 |
||
460 |
/** |
|
461 |
* Retrieves, but does not remove, the head of the queue represented by |
|
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
462 |
* this deque, or returns {@code null} if this deque is empty. |
2 | 463 |
* |
464 |
* <p>This method is equivalent to {@link #peekFirst}. |
|
465 |
* |
|
466 |
* @return the head of the queue represented by this deque, or |
|
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
467 |
* {@code null} if this deque is empty |
2 | 468 |
*/ |
469 |
public E peek() { |
|
470 |
return peekFirst(); |
|
471 |
} |
|
472 |
||
473 |
// *** Stack methods *** |
|
474 |
||
475 |
/** |
|
476 |
* Pushes an element onto the stack represented by this deque. In other |
|
477 |
* words, inserts the element at the front of this deque. |
|
478 |
* |
|
479 |
* <p>This method is equivalent to {@link #addFirst}. |
|
480 |
* |
|
481 |
* @param e the element to push |
|
482 |
* @throws NullPointerException if the specified element is null |
|
483 |
*/ |
|
484 |
public void push(E e) { |
|
485 |
addFirst(e); |
|
486 |
} |
|
487 |
||
488 |
/** |
|
489 |
* Pops an element from the stack represented by this deque. In other |
|
490 |
* words, removes and returns the first element of this deque. |
|
491 |
* |
|
492 |
* <p>This method is equivalent to {@link #removeFirst()}. |
|
493 |
* |
|
494 |
* @return the element at the front of this deque (which is the top |
|
495 |
* of the stack represented by this deque) |
|
496 |
* @throws NoSuchElementException {@inheritDoc} |
|
497 |
*/ |
|
498 |
public E pop() { |
|
499 |
return removeFirst(); |
|
500 |
} |
|
501 |
||
502 |
private void checkInvariants() { |
|
503 |
assert elements[tail] == null; |
|
504 |
assert head == tail ? elements[head] == null : |
|
505 |
(elements[head] != null && |
|
506 |
elements[(tail - 1) & (elements.length - 1)] != null); |
|
507 |
assert elements[(head - 1) & (elements.length - 1)] == null; |
|
508 |
} |
|
509 |
||
510 |
/** |
|
511 |
* Removes the element at the specified position in the elements array, |
|
512 |
* adjusting head and tail as necessary. This can result in motion of |
|
513 |
* elements backwards or forwards in the array. |
|
514 |
* |
|
515 |
* <p>This method is called delete rather than remove to emphasize |
|
516 |
* that its semantics differ from those of {@link List#remove(int)}. |
|
517 |
* |
|
518 |
* @return true if elements moved backwards |
|
519 |
*/ |
|
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
520 |
boolean delete(int i) { |
2 | 521 |
checkInvariants(); |
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
522 |
final Object[] elements = this.elements; |
2 | 523 |
final int mask = elements.length - 1; |
524 |
final int h = head; |
|
525 |
final int t = tail; |
|
526 |
final int front = (i - h) & mask; |
|
527 |
final int back = (t - i) & mask; |
|
528 |
||
529 |
// Invariant: head <= i < tail mod circularity |
|
530 |
if (front >= ((t - h) & mask)) |
|
531 |
throw new ConcurrentModificationException(); |
|
532 |
||
533 |
// Optimize for least element motion |
|
534 |
if (front < back) { |
|
535 |
if (h <= i) { |
|
536 |
System.arraycopy(elements, h, elements, h + 1, front); |
|
537 |
} else { // Wrap around |
|
538 |
System.arraycopy(elements, 0, elements, 1, i); |
|
539 |
elements[0] = elements[mask]; |
|
540 |
System.arraycopy(elements, h, elements, h + 1, mask - h); |
|
541 |
} |
|
542 |
elements[h] = null; |
|
543 |
head = (h + 1) & mask; |
|
544 |
return false; |
|
545 |
} else { |
|
546 |
if (i < t) { // Copy the null tail as well |
|
547 |
System.arraycopy(elements, i + 1, elements, i, back); |
|
548 |
tail = t - 1; |
|
549 |
} else { // Wrap around |
|
550 |
System.arraycopy(elements, i + 1, elements, i, mask - i); |
|
551 |
elements[mask] = elements[0]; |
|
552 |
System.arraycopy(elements, 1, elements, 0, t); |
|
553 |
tail = (t - 1) & mask; |
|
554 |
} |
|
555 |
return true; |
|
556 |
} |
|
557 |
} |
|
558 |
||
559 |
// *** Collection Methods *** |
|
560 |
||
561 |
/** |
|
562 |
* Returns the number of elements in this deque. |
|
563 |
* |
|
564 |
* @return the number of elements in this deque |
|
565 |
*/ |
|
566 |
public int size() { |
|
567 |
return (tail - head) & (elements.length - 1); |
|
568 |
} |
|
569 |
||
570 |
/** |
|
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
571 |
* Returns {@code true} if this deque contains no elements. |
2 | 572 |
* |
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
573 |
* @return {@code true} if this deque contains no elements |
2 | 574 |
*/ |
575 |
public boolean isEmpty() { |
|
576 |
return head == tail; |
|
577 |
} |
|
578 |
||
579 |
/** |
|
580 |
* Returns an iterator over the elements in this deque. The elements |
|
581 |
* will be ordered from first (head) to last (tail). This is the same |
|
582 |
* order that elements would be dequeued (via successive calls to |
|
583 |
* {@link #remove} or popped (via successive calls to {@link #pop}). |
|
584 |
* |
|
585 |
* @return an iterator over the elements in this deque |
|
586 |
*/ |
|
587 |
public Iterator<E> iterator() { |
|
588 |
return new DeqIterator(); |
|
589 |
} |
|
590 |
||
591 |
public Iterator<E> descendingIterator() { |
|
592 |
return new DescendingIterator(); |
|
593 |
} |
|
594 |
||
595 |
private class DeqIterator implements Iterator<E> { |
|
596 |
/** |
|
597 |
* Index of element to be returned by subsequent call to next. |
|
598 |
*/ |
|
599 |
private int cursor = head; |
|
600 |
||
601 |
/** |
|
602 |
* Tail recorded at construction (also in remove), to stop |
|
603 |
* iterator and also to check for comodification. |
|
604 |
*/ |
|
605 |
private int fence = tail; |
|
606 |
||
607 |
/** |
|
608 |
* Index of element returned by most recent call to next. |
|
609 |
* Reset to -1 if element is deleted by a call to remove. |
|
610 |
*/ |
|
611 |
private int lastRet = -1; |
|
612 |
||
613 |
public boolean hasNext() { |
|
614 |
return cursor != fence; |
|
615 |
} |
|
616 |
||
617 |
public E next() { |
|
618 |
if (cursor == fence) |
|
619 |
throw new NoSuchElementException(); |
|
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
620 |
@SuppressWarnings("unchecked") |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
621 |
E result = (E) elements[cursor]; |
2 | 622 |
// This check doesn't catch all possible comodifications, |
623 |
// but does catch the ones that corrupt traversal |
|
624 |
if (tail != fence || result == null) |
|
625 |
throw new ConcurrentModificationException(); |
|
626 |
lastRet = cursor; |
|
627 |
cursor = (cursor + 1) & (elements.length - 1); |
|
628 |
return result; |
|
629 |
} |
|
630 |
||
631 |
public void remove() { |
|
632 |
if (lastRet < 0) |
|
633 |
throw new IllegalStateException(); |
|
634 |
if (delete(lastRet)) { // if left-shifted, undo increment in next() |
|
635 |
cursor = (cursor - 1) & (elements.length - 1); |
|
636 |
fence = tail; |
|
637 |
} |
|
638 |
lastRet = -1; |
|
639 |
} |
|
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
640 |
|
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
641 |
public void forEachRemaining(Consumer<? super E> action) { |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
642 |
Objects.requireNonNull(action); |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
643 |
Object[] a = elements; |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
644 |
int m = a.length - 1, f = fence, i = cursor; |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
645 |
cursor = f; |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
646 |
while (i != f) { |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
647 |
@SuppressWarnings("unchecked") E e = (E)a[i]; |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
648 |
i = (i + 1) & m; |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
649 |
if (e == null) |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
650 |
throw new ConcurrentModificationException(); |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
651 |
action.accept(e); |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
652 |
} |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
653 |
} |
2 | 654 |
} |
655 |
||
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
656 |
/** |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
657 |
* This class is nearly a mirror-image of DeqIterator, using tail |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
658 |
* instead of head for initial cursor, and head instead of tail |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
659 |
* for fence. |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
660 |
*/ |
2 | 661 |
private class DescendingIterator implements Iterator<E> { |
662 |
private int cursor = tail; |
|
663 |
private int fence = head; |
|
664 |
private int lastRet = -1; |
|
665 |
||
666 |
public boolean hasNext() { |
|
667 |
return cursor != fence; |
|
668 |
} |
|
669 |
||
670 |
public E next() { |
|
671 |
if (cursor == fence) |
|
672 |
throw new NoSuchElementException(); |
|
673 |
cursor = (cursor - 1) & (elements.length - 1); |
|
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
674 |
@SuppressWarnings("unchecked") |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
675 |
E result = (E) elements[cursor]; |
2 | 676 |
if (head != fence || result == null) |
677 |
throw new ConcurrentModificationException(); |
|
678 |
lastRet = cursor; |
|
679 |
return result; |
|
680 |
} |
|
681 |
||
682 |
public void remove() { |
|
683 |
if (lastRet < 0) |
|
684 |
throw new IllegalStateException(); |
|
685 |
if (!delete(lastRet)) { |
|
686 |
cursor = (cursor + 1) & (elements.length - 1); |
|
687 |
fence = head; |
|
688 |
} |
|
689 |
lastRet = -1; |
|
690 |
} |
|
691 |
} |
|
692 |
||
693 |
/** |
|
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
694 |
* Returns {@code true} if this deque contains the specified element. |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
695 |
* More formally, returns {@code true} if and only if this deque contains |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
696 |
* at least one element {@code e} such that {@code o.equals(e)}. |
2 | 697 |
* |
698 |
* @param o object to be checked for containment in this deque |
|
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
699 |
* @return {@code true} if this deque contains the specified element |
2 | 700 |
*/ |
701 |
public boolean contains(Object o) { |
|
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
702 |
if (o != null) { |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
703 |
int mask = elements.length - 1; |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
704 |
int i = head; |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
705 |
for (Object x; (x = elements[i]) != null; i = (i + 1) & mask) { |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
706 |
if (o.equals(x)) |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
707 |
return true; |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
708 |
} |
2 | 709 |
} |
710 |
return false; |
|
711 |
} |
|
712 |
||
713 |
/** |
|
714 |
* Removes a single instance of the specified element from this deque. |
|
715 |
* If the deque does not contain the element, it is unchanged. |
|
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
716 |
* More formally, removes the first element {@code e} such that |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
717 |
* {@code o.equals(e)} (if such an element exists). |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
718 |
* Returns {@code true} if this deque contained the specified element |
2 | 719 |
* (or equivalently, if this deque changed as a result of the call). |
720 |
* |
|
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
721 |
* <p>This method is equivalent to {@link #removeFirstOccurrence(Object)}. |
2 | 722 |
* |
723 |
* @param o element to be removed from this deque, if present |
|
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
724 |
* @return {@code true} if this deque contained the specified element |
2 | 725 |
*/ |
726 |
public boolean remove(Object o) { |
|
727 |
return removeFirstOccurrence(o); |
|
728 |
} |
|
729 |
||
730 |
/** |
|
731 |
* Removes all of the elements from this deque. |
|
732 |
* The deque will be empty after this call returns. |
|
733 |
*/ |
|
734 |
public void clear() { |
|
735 |
int h = head; |
|
736 |
int t = tail; |
|
737 |
if (h != t) { // clear all cells |
|
738 |
head = tail = 0; |
|
739 |
int i = h; |
|
740 |
int mask = elements.length - 1; |
|
741 |
do { |
|
742 |
elements[i] = null; |
|
743 |
i = (i + 1) & mask; |
|
744 |
} while (i != t); |
|
745 |
} |
|
746 |
} |
|
747 |
||
748 |
/** |
|
749 |
* Returns an array containing all of the elements in this deque |
|
750 |
* in proper sequence (from first to last element). |
|
751 |
* |
|
752 |
* <p>The returned array will be "safe" in that no references to it are |
|
753 |
* maintained by this deque. (In other words, this method must allocate |
|
754 |
* a new array). The caller is thus free to modify the returned array. |
|
755 |
* |
|
756 |
* <p>This method acts as bridge between array-based and collection-based |
|
757 |
* APIs. |
|
758 |
* |
|
759 |
* @return an array containing all of the elements in this deque |
|
760 |
*/ |
|
761 |
public Object[] toArray() { |
|
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
762 |
final int head = this.head; |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
763 |
final int tail = this.tail; |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
764 |
boolean wrap = (tail < head); |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
765 |
int end = wrap ? tail + elements.length : tail; |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
766 |
Object[] a = Arrays.copyOfRange(elements, head, end); |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
767 |
if (wrap) |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
768 |
System.arraycopy(elements, 0, a, elements.length - head, tail); |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
769 |
return a; |
2 | 770 |
} |
771 |
||
772 |
/** |
|
773 |
* Returns an array containing all of the elements in this deque in |
|
774 |
* proper sequence (from first to last element); the runtime type of the |
|
775 |
* returned array is that of the specified array. If the deque fits in |
|
776 |
* the specified array, it is returned therein. Otherwise, a new array |
|
777 |
* is allocated with the runtime type of the specified array and the |
|
778 |
* size of this deque. |
|
779 |
* |
|
780 |
* <p>If this deque fits in the specified array with room to spare |
|
781 |
* (i.e., the array has more elements than this deque), the element in |
|
782 |
* the array immediately following the end of the deque is set to |
|
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
783 |
* {@code null}. |
2 | 784 |
* |
785 |
* <p>Like the {@link #toArray()} method, this method acts as bridge between |
|
786 |
* array-based and collection-based APIs. Further, this method allows |
|
787 |
* precise control over the runtime type of the output array, and may, |
|
788 |
* under certain circumstances, be used to save allocation costs. |
|
789 |
* |
|
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
790 |
* <p>Suppose {@code x} is a deque known to contain only strings. |
2 | 791 |
* The following code can be used to dump the deque into a newly |
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
792 |
* allocated array of {@code String}: |
2 | 793 |
* |
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
794 |
* <pre> {@code String[] y = x.toArray(new String[0]);}</pre> |
2 | 795 |
* |
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
796 |
* Note that {@code toArray(new Object[0])} is identical in function to |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
797 |
* {@code toArray()}. |
2 | 798 |
* |
799 |
* @param a the array into which the elements of the deque are to |
|
800 |
* be stored, if it is big enough; otherwise, a new array of the |
|
801 |
* same runtime type is allocated for this purpose |
|
802 |
* @return an array containing all of the elements in this deque |
|
803 |
* @throws ArrayStoreException if the runtime type of the specified array |
|
804 |
* is not a supertype of the runtime type of every element in |
|
805 |
* this deque |
|
806 |
* @throws NullPointerException if the specified array is null |
|
807 |
*/ |
|
13795
73850c397272
7193406: Clean-up JDK Build Warnings in java.util, java.io
dxu
parents:
12448
diff
changeset
|
808 |
@SuppressWarnings("unchecked") |
2 | 809 |
public <T> T[] toArray(T[] a) { |
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
810 |
final int head = this.head; |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
811 |
final int tail = this.tail; |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
812 |
boolean wrap = (tail < head); |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
813 |
int size = (tail - head) + (wrap ? elements.length : 0); |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
814 |
int firstLeg = size - (wrap ? tail : 0); |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
815 |
int len = a.length; |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
816 |
if (size > len) { |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
817 |
a = (T[]) Arrays.copyOfRange(elements, head, head + size, |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
818 |
a.getClass()); |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
819 |
} else { |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
820 |
System.arraycopy(elements, head, a, 0, firstLeg); |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
821 |
if (size < len) |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
822 |
a[size] = null; |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
823 |
} |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
824 |
if (wrap) |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
825 |
System.arraycopy(elements, 0, a, firstLeg, tail); |
2 | 826 |
return a; |
827 |
} |
|
828 |
||
829 |
// *** Object methods *** |
|
830 |
||
831 |
/** |
|
832 |
* Returns a copy of this deque. |
|
833 |
* |
|
834 |
* @return a copy of this deque |
|
835 |
*/ |
|
836 |
public ArrayDeque<E> clone() { |
|
837 |
try { |
|
12448 | 838 |
@SuppressWarnings("unchecked") |
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
839 |
ArrayDeque<E> result = (ArrayDeque<E>) super.clone(); |
2 | 840 |
result.elements = Arrays.copyOf(elements, elements.length); |
841 |
return result; |
|
842 |
} catch (CloneNotSupportedException e) { |
|
843 |
throw new AssertionError(); |
|
844 |
} |
|
845 |
} |
|
846 |
||
847 |
private static final long serialVersionUID = 2340985798034038923L; |
|
848 |
||
849 |
/** |
|
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
850 |
* Saves this deque to a stream (that is, serializes it). |
2 | 851 |
* |
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
852 |
* @param s the stream |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
853 |
* @throws java.io.IOException if an I/O error occurs |
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
854 |
* @serialData The current size ({@code int}) of the deque, |
2 | 855 |
* followed by all of its elements (each an object reference) in |
856 |
* first-to-last order. |
|
857 |
*/ |
|
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
858 |
private void writeObject(java.io.ObjectOutputStream s) |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
859 |
throws java.io.IOException { |
2 | 860 |
s.defaultWriteObject(); |
861 |
||
862 |
// Write out size |
|
863 |
s.writeInt(size()); |
|
864 |
||
865 |
// Write out elements in order. |
|
866 |
int mask = elements.length - 1; |
|
867 |
for (int i = head; i != tail; i = (i + 1) & mask) |
|
868 |
s.writeObject(elements[i]); |
|
869 |
} |
|
870 |
||
871 |
/** |
|
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
872 |
* Reconstitutes this deque from a stream (that is, deserializes it). |
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
873 |
* @param s the stream |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
874 |
* @throws ClassNotFoundException if the class of a serialized object |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
875 |
* could not be found |
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
876 |
* @throws java.io.IOException if an I/O error occurs |
2 | 877 |
*/ |
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
878 |
private void readObject(java.io.ObjectInputStream s) |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
879 |
throws java.io.IOException, ClassNotFoundException { |
2 | 880 |
s.defaultReadObject(); |
881 |
||
882 |
// Read in size and allocate array |
|
883 |
int size = s.readInt(); |
|
884 |
allocateElements(size); |
|
885 |
head = 0; |
|
886 |
tail = size; |
|
887 |
||
888 |
// Read in all elements in the proper order. |
|
889 |
for (int i = 0; i < size; i++) |
|
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
890 |
elements[i] = s.readObject(); |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
891 |
} |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
892 |
|
19435
9d7530ff42cb
8014824: Document Spliterator characteristics and binding policy of java util collection impls
psandoz
parents:
17168
diff
changeset
|
893 |
/** |
9d7530ff42cb
8014824: Document Spliterator characteristics and binding policy of java util collection impls
psandoz
parents:
17168
diff
changeset
|
894 |
* Creates a <em><a href="Spliterator.html#binding">late-binding</a></em> |
9d7530ff42cb
8014824: Document Spliterator characteristics and binding policy of java util collection impls
psandoz
parents:
17168
diff
changeset
|
895 |
* and <em>fail-fast</em> {@link Spliterator} over the elements in this |
9d7530ff42cb
8014824: Document Spliterator characteristics and binding policy of java util collection impls
psandoz
parents:
17168
diff
changeset
|
896 |
* deque. |
9d7530ff42cb
8014824: Document Spliterator characteristics and binding policy of java util collection impls
psandoz
parents:
17168
diff
changeset
|
897 |
* |
9d7530ff42cb
8014824: Document Spliterator characteristics and binding policy of java util collection impls
psandoz
parents:
17168
diff
changeset
|
898 |
* <p>The {@code Spliterator} reports {@link Spliterator#SIZED}, |
9d7530ff42cb
8014824: Document Spliterator characteristics and binding policy of java util collection impls
psandoz
parents:
17168
diff
changeset
|
899 |
* {@link Spliterator#SUBSIZED}, {@link Spliterator#ORDERED}, and |
9d7530ff42cb
8014824: Document Spliterator characteristics and binding policy of java util collection impls
psandoz
parents:
17168
diff
changeset
|
900 |
* {@link Spliterator#NONNULL}. Overriding implementations should document |
9d7530ff42cb
8014824: Document Spliterator characteristics and binding policy of java util collection impls
psandoz
parents:
17168
diff
changeset
|
901 |
* the reporting of additional characteristic values. |
9d7530ff42cb
8014824: Document Spliterator characteristics and binding policy of java util collection impls
psandoz
parents:
17168
diff
changeset
|
902 |
* |
9d7530ff42cb
8014824: Document Spliterator characteristics and binding policy of java util collection impls
psandoz
parents:
17168
diff
changeset
|
903 |
* @return a {@code Spliterator} over the elements in this deque |
9d7530ff42cb
8014824: Document Spliterator characteristics and binding policy of java util collection impls
psandoz
parents:
17168
diff
changeset
|
904 |
* @since 1.8 |
9d7530ff42cb
8014824: Document Spliterator characteristics and binding policy of java util collection impls
psandoz
parents:
17168
diff
changeset
|
905 |
*/ |
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
906 |
public Spliterator<E> spliterator() { |
22078
bdec5d53e98c
8030851: Update code in java.util to use newer language features
psandoz
parents:
19435
diff
changeset
|
907 |
return new DeqSpliterator<>(this, -1, -1); |
2 | 908 |
} |
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
909 |
|
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
910 |
static final class DeqSpliterator<E> implements Spliterator<E> { |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
911 |
private final ArrayDeque<E> deq; |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
912 |
private int fence; // -1 until first use |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
913 |
private int index; // current index, modified on traverse/split |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
914 |
|
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
915 |
/** Creates new spliterator covering the given array and range. */ |
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
916 |
DeqSpliterator(ArrayDeque<E> deq, int origin, int fence) { |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
917 |
this.deq = deq; |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
918 |
this.index = origin; |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
919 |
this.fence = fence; |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
920 |
} |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
921 |
|
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
922 |
private int getFence() { // force initialization |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
923 |
int t; |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
924 |
if ((t = fence) < 0) { |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
925 |
t = fence = deq.tail; |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
926 |
index = deq.head; |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
927 |
} |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
928 |
return t; |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
929 |
} |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
930 |
|
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
931 |
public DeqSpliterator<E> trySplit() { |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
932 |
int t = getFence(), h = index, n = deq.elements.length; |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
933 |
if (h != t && ((h + 1) & (n - 1)) != t) { |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
934 |
if (h > t) |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
935 |
t += n; |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
936 |
int m = ((h + t) >>> 1) & (n - 1); |
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
937 |
return new DeqSpliterator<E>(deq, h, index = m); |
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
938 |
} |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
939 |
return null; |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
940 |
} |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
941 |
|
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
942 |
public void forEachRemaining(Consumer<? super E> consumer) { |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
943 |
if (consumer == null) |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
944 |
throw new NullPointerException(); |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
945 |
Object[] a = deq.elements; |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
946 |
int m = a.length - 1, f = getFence(), i = index; |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
947 |
index = f; |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
948 |
while (i != f) { |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
949 |
@SuppressWarnings("unchecked") E e = (E)a[i]; |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
950 |
i = (i + 1) & m; |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
951 |
if (e == null) |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
952 |
throw new ConcurrentModificationException(); |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
953 |
consumer.accept(e); |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
954 |
} |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
955 |
} |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
956 |
|
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
957 |
public boolean tryAdvance(Consumer<? super E> consumer) { |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
958 |
if (consumer == null) |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
959 |
throw new NullPointerException(); |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
960 |
Object[] a = deq.elements; |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
961 |
int m = a.length - 1, f = getFence(), i = index; |
32991
b27c76b82713
8134853: Bulk integration of java.util.concurrent classes
dl
parents:
25859
diff
changeset
|
962 |
if (i != f) { |
17168
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
963 |
@SuppressWarnings("unchecked") E e = (E)a[i]; |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
964 |
index = (i + 1) & m; |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
965 |
if (e == null) |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
966 |
throw new ConcurrentModificationException(); |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
967 |
consumer.accept(e); |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
968 |
return true; |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
969 |
} |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
970 |
return false; |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
971 |
} |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
972 |
|
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
973 |
public long estimateSize() { |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
974 |
int n = getFence() - index; |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
975 |
if (n < 0) |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
976 |
n += deq.elements.length; |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
977 |
return (long) n; |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
978 |
} |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
979 |
|
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
980 |
@Override |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
981 |
public int characteristics() { |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
982 |
return Spliterator.ORDERED | Spliterator.SIZED | |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
983 |
Spliterator.NONNULL | Spliterator.SUBSIZED; |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
984 |
} |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
985 |
} |
b7d3500f2516
8011426: java.util collection Spliterator implementations
psandoz
parents:
13795
diff
changeset
|
986 |
|
2 | 987 |
} |