540 |
|
assertFalse(it.hasNext()); |
541 |
|
} |
542 |
|
|
543 |
+ |
/** |
544 |
+ |
* Descending iterator iterates through all elements |
545 |
+ |
*/ |
546 |
+ |
public void testDescendingIterator() { |
547 |
+ |
ArrayDeque q = populatedDeque(SIZE); |
548 |
+ |
int i = 0; |
549 |
+ |
Iterator it = q.descendingIterator(); |
550 |
+ |
while(it.hasNext()) { |
551 |
+ |
assertTrue(q.contains(it.next())); |
552 |
+ |
++i; |
553 |
+ |
} |
554 |
+ |
assertEquals(i, SIZE); |
555 |
+ |
assertFalse(it.hasNext()); |
556 |
+ |
try { |
557 |
+ |
it.next(); |
558 |
+ |
} catch(NoSuchElementException success) { |
559 |
+ |
} |
560 |
+ |
} |
561 |
+ |
|
562 |
+ |
/** |
563 |
+ |
* Descending iterator ordering is reverse FIFO |
564 |
+ |
*/ |
565 |
+ |
public void testDescendingIteratorOrdering() { |
566 |
+ |
final ArrayDeque q = new ArrayDeque(); |
567 |
+ |
q.add(new Integer(3)); |
568 |
+ |
q.add(new Integer(2)); |
569 |
+ |
q.add(new Integer(1)); |
570 |
+ |
int k = 0; |
571 |
+ |
for (Iterator it = q.descendingIterator(); it.hasNext();) { |
572 |
+ |
int i = ((Integer)(it.next())).intValue(); |
573 |
+ |
assertEquals(++k, i); |
574 |
+ |
} |
575 |
+ |
|
576 |
+ |
assertEquals(3, k); |
577 |
+ |
} |
578 |
+ |
|
579 |
+ |
/** |
580 |
+ |
* descendingIterator.remove removes current element |
581 |
+ |
*/ |
582 |
+ |
public void testDescendingIteratorRemove () { |
583 |
+ |
final ArrayDeque q = new ArrayDeque(); |
584 |
+ |
q.add(new Integer(3)); |
585 |
+ |
q.add(new Integer(2)); |
586 |
+ |
q.add(new Integer(1)); |
587 |
+ |
Iterator it = q.descendingIterator(); |
588 |
+ |
it.next(); |
589 |
+ |
it.remove(); |
590 |
+ |
it = q.descendingIterator(); |
591 |
+ |
assertEquals(it.next(), new Integer(2)); |
592 |
+ |
assertEquals(it.next(), new Integer(3)); |
593 |
+ |
assertFalse(it.hasNext()); |
594 |
+ |
} |
595 |
+ |
|
596 |
|
|
597 |
|
/** |
598 |
|
* toString contains toStrings of elements |