479 |
|
return removeFirst(); |
480 |
|
} |
481 |
|
|
482 |
+ |
private void checkInvariants() { |
483 |
+ |
assert elements[tail] == null; |
484 |
+ |
assert head == tail ? elements[head] == null : |
485 |
+ |
(elements[head] != null && |
486 |
+ |
elements[(tail - 1) & (elements.length - 1)] != null); |
487 |
+ |
assert elements[(head - 1) & (elements.length - 1)] == null; |
488 |
+ |
} |
489 |
+ |
|
490 |
|
/** |
491 |
|
* Removes the element at the specified position in the elements array, |
492 |
|
* adjusting head and tail as necessary. This can result in motion of |
498 |
|
* @return true if elements moved backwards |
499 |
|
*/ |
500 |
|
private boolean delete(int i) { |
501 |
+ |
checkInvariants(); |
502 |
|
final E[] elements = this.elements; |
503 |
|
final int mask = elements.length - 1; |
504 |
|
final int h = head; |
617 |
|
} |
618 |
|
} |
619 |
|
|
611 |
– |
|
620 |
|
private class DescendingIterator implements Iterator<E> { |
621 |
|
/* |
622 |
|
* This class is nearly a mirror-image of DeqIterator, using |
837 |
|
// Read in all elements in the proper order. |
838 |
|
for (int i = 0; i < size; i++) |
839 |
|
elements[i] = (E)s.readObject(); |
832 |
– |
|
840 |
|
} |
841 |
|
} |