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; |
304 |
|
return result; |
305 |
|
} |
306 |
|
|
307 |
+ |
@SuppressWarnings("unchecked") |
308 |
|
public E peekFirst() { |
305 |
– |
@SuppressWarnings("unchecked") E result = (E) elements[head]; |
309 |
|
// elements[head] is null if deque empty |
310 |
< |
return result; |
310 |
> |
return (E) elements[head]; |
311 |
|
} |
312 |
|
|
313 |
+ |
@SuppressWarnings("unchecked") |
314 |
|
public E peekLast() { |
315 |
< |
@SuppressWarnings("unchecked") |
312 |
< |
E result = (E) elements[(tail - 1) & (elements.length - 1)]; |
313 |
< |
return result; |
315 |
> |
return (E) elements[(tail - 1) & (elements.length - 1)]; |
316 |
|
} |
317 |
|
|
318 |
|
/** |
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; |
796 |
– |
|
800 |
|
} catch (CloneNotSupportedException e) { |
801 |
|
throw new AssertionError(); |
802 |
|
} |
803 |
|
} |
804 |
|
|
802 |
– |
/** |
803 |
– |
* Appease the serialization gods. |
804 |
– |
*/ |
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 { |