1628 |
|
|
1629 |
|
|
1630 |
|
/** |
1631 |
+ |
* Descending iterator iterates through all elements |
1632 |
+ |
*/ |
1633 |
+ |
public void testDescendingIterator() { |
1634 |
+ |
LinkedBlockingDeque q = populatedDeque(SIZE); |
1635 |
+ |
int i = 0; |
1636 |
+ |
Iterator it = q.descendingIterator(); |
1637 |
+ |
while(it.hasNext()) { |
1638 |
+ |
assertTrue(q.contains(it.next())); |
1639 |
+ |
++i; |
1640 |
+ |
} |
1641 |
+ |
assertEquals(i, SIZE); |
1642 |
+ |
assertFalse(it.hasNext()); |
1643 |
+ |
try { |
1644 |
+ |
it.next(); |
1645 |
+ |
} catch(NoSuchElementException success) { |
1646 |
+ |
} |
1647 |
+ |
} |
1648 |
+ |
|
1649 |
+ |
/** |
1650 |
+ |
* Descending iterator ordering is reverse FIFO |
1651 |
+ |
*/ |
1652 |
+ |
public void testDescendingIteratorOrdering() { |
1653 |
+ |
final LinkedBlockingDeque q = new LinkedBlockingDeque(); |
1654 |
+ |
q.add(new Integer(3)); |
1655 |
+ |
q.add(new Integer(2)); |
1656 |
+ |
q.add(new Integer(1)); |
1657 |
+ |
int k = 0; |
1658 |
+ |
for (Iterator it = q.descendingIterator(); it.hasNext();) { |
1659 |
+ |
int i = ((Integer)(it.next())).intValue(); |
1660 |
+ |
assertEquals(++k, i); |
1661 |
+ |
} |
1662 |
+ |
|
1663 |
+ |
assertEquals(3, k); |
1664 |
+ |
} |
1665 |
+ |
|
1666 |
+ |
/** |
1667 |
+ |
* descendingIterator.remove removes current element |
1668 |
+ |
*/ |
1669 |
+ |
public void testDescendingIteratorRemove () { |
1670 |
+ |
final LinkedBlockingDeque q = new LinkedBlockingDeque(); |
1671 |
+ |
q.add(new Integer(3)); |
1672 |
+ |
q.add(new Integer(2)); |
1673 |
+ |
q.add(new Integer(1)); |
1674 |
+ |
Iterator it = q.descendingIterator(); |
1675 |
+ |
it.next(); |
1676 |
+ |
it.remove(); |
1677 |
+ |
it = q.descendingIterator(); |
1678 |
+ |
assertEquals(it.next(), new Integer(2)); |
1679 |
+ |
assertEquals(it.next(), new Integer(3)); |
1680 |
+ |
assertFalse(it.hasNext()); |
1681 |
+ |
} |
1682 |
+ |
|
1683 |
+ |
|
1684 |
+ |
/** |
1685 |
|
* toString contains toStrings of elements |
1686 |
|
*/ |
1687 |
|
public void testToString() { |