}
}
public void test_DescendingSubMapEntrySet_headSet() {
Set entrySet, headSet;
NavigableSet descendingSubMapEntrySet;
Iterator iterator, headSetIterator;
Entry entry;
int value;
entrySet = navigableMap_startExcluded_endExcluded.entrySet();
if (entrySet instanceof NavigableSet) {
descendingSubMapEntrySet = ((NavigableSet) entrySet)
.descendingSet();
iterator = descendingSubMapEntrySet.iterator();
while (iterator.hasNext()) {
entry = (Entry) iterator.next();
headSet = descendingSubMapEntrySet.headSet(entry);
headSetIterator = headSet.iterator();
for (value = 108; headSetIterator.hasNext(); value--) {
assertEquals(value, ((Entry) headSetIterator.next())
.getValue());
}
try {
headSetIterator.next();
fail("should throw NoSuchElementException");
} catch (NoSuchElementException e) {
// Expected
}
headSet = descendingSubMapEntrySet.headSet(entry, false);
headSetIterator = headSet.iterator();
for (value = 108; headSetIterator.hasNext(); value--) {
assertEquals(value, ((Entry) headSetIterator.next())
.getValue());
}
try {
headSetIterator.next();
fail("should throw NoSuchElementException");
} catch (NoSuchElementException e) {
// Expected
}
headSet = descendingSubMapEntrySet.headSet(entry, true);
headSetIterator = headSet.iterator();
for (value = 108; headSetIterator.hasNext(); value--) {
assertEquals(value, ((Entry) headSetIterator.next())
.getValue());
}
try {
headSetIterator.next();
fail("should throw NoSuchElementException");
} catch (NoSuchElementException e) {
// Expected
}
}
}
entrySet = navigableMap_startExcluded_endIncluded.entrySet();
if (entrySet instanceof NavigableSet) {
descendingSubMapEntrySet = ((NavigableSet) entrySet)
.descendingSet();
iterator = descendingSubMapEntrySet.iterator();
while (iterator.hasNext()) {
entry = (Entry) iterator.next();
headSet = descendingSubMapEntrySet.headSet(entry);
headSetIterator = headSet.iterator();
for (value = 109; headSetIterator.hasNext(); value--) {
assertEquals(value, ((Entry) headSetIterator.next())
.getValue());
}
try {
headSetIterator.next();
fail("should throw NoSuchElementException");
} catch (NoSuchElementException e) {
// Expected
}
headSet = descendingSubMapEntrySet.headSet(entry, false);
headSetIterator = headSet.iterator();
for (value = 109; headSetIterator.hasNext(); value--) {
assertEquals(value, ((Entry) headSetIterator.next())
.getValue());
}
try {
headSetIterator.next();
fail("should throw NoSuchElementException");
} catch (NoSuchElementException e) {
// Expected
}
headSet = descendingSubMapEntrySet.headSet(entry, true);
headSetIterator = headSet.iterator();
for (value = 109; headSetIterator.hasNext(); value--) {
assertEquals(value, ((Entry) headSetIterator.next())
.getValue());
}
try {
headSetIterator.next();
fail("should throw NoSuchElementException");
} catch (NoSuchElementException e) {
// Expected
}
}
}
entrySet = navigableMap_startIncluded_endExcluded.entrySet();
if (entrySet instanceof NavigableSet) {
descendingSubMapEntrySet = ((NavigableSet) entrySet)
.descendingSet();
iterator = descendingSubMapEntrySet.iterator();
while (iterator.hasNext()) {
entry = (Entry) iterator.next();
headSet = descendingSubMapEntrySet.headSet(entry);
headSetIterator = headSet.iterator();
for (value = 108; headSetIterator.hasNext(); value--) {
assertEquals(value, ((Entry) headSetIterator.next())
.getValue());
}
try {
headSetIterator.next();
fail("should throw NoSuchElementException");
} catch (NoSuchElementException e) {
// Expected
}
headSet = descendingSubMapEntrySet.headSet(entry, false);
headSetIterator = headSet.iterator();
for (value = 108; headSetIterator.hasNext(); value--) {
assertEquals(value, ((Entry) headSetIterator.next())
.getValue());
}
try {
headSetIterator.next();
fail("should throw NoSuchElementException");
} catch (NoSuchElementException e) {
// Expected
}
headSet = descendingSubMapEntrySet.headSet(entry, true);
headSetIterator = headSet.iterator();
for (value = 108; headSetIterator.hasNext(); value--) {
assertEquals(value, ((Entry) headSetIterator.next())
.getValue());
}
try {
headSetIterator.next();
fail("should throw NoSuchElementException");
} catch (NoSuchElementException e) {
// Expected
}
}
}
entrySet = navigableMap_startIncluded_endIncluded.entrySet();
if (entrySet instanceof NavigableSet) {
descendingSubMapEntrySet = ((NavigableSet) entrySet)
.descendingSet();
iterator = descendingSubMapEntrySet.iterator();
while (iterator.hasNext()) {
entry = (Entry) iterator.next();
headSet = descendingSubMapEntrySet.headSet(entry);
headSetIterator = headSet.iterator();
for (value = 109; headSetIterator.hasNext(); value--) {
assertEquals(value, ((Entry) headSetIterator.next())
.getValue());
}
try {
headSetIterator.next();
fail("should throw NoSuchElementException");
} catch (NoSuchElementException e) {
// Expected
}
headSet = descendingSubMapEntrySet.headSet(entry, false);
headSetIterator = headSet.iterator();
for (value = 109; headSetIterator.hasNext(); value--) {
assertEquals(value, ((Entry) headSetIterator.next())
.getValue());
}
try {
headSetIterator.next();
fail("should throw NoSuchElementException");
} catch (NoSuchElementException e) {
// Expected
}
headSet = descendingSubMapEntrySet.headSet(entry, true);
headSetIterator = headSet.iterator();
for (value = 109; headSetIterator.hasNext(); value--) {
assertEquals(value, ((Entry) headSetIterator.next())
.getValue());
}
try {
headSetIterator.next();
fail("should throw NoSuchElementException");
} catch (NoSuchElementException e) {
// Expected
}
}
}
String endKey = new Integer(2).toString();
entrySet = tm.headMap(endKey, true).entrySet();// 0...2
if (entrySet instanceof NavigableSet) {
// [2...0]
descendingSubMapEntrySet = ((NavigableSet) entrySet)
.descendingSet();
iterator = descendingSubMapEntrySet.iterator();
iterator.next();// 2
iterator.next();// 199
entry = (Entry) iterator.next();// 198
headSet = descendingSubMapEntrySet.headSet(entry);
assertEquals(2, headSet.size());// 2 199
headSetIterator = headSet.iterator();
assertEquals(2, ((Entry) headSetIterator.next()).getValue());
assertEquals(199, ((Entry) headSetIterator.next()).getValue());
headSet = descendingSubMapEntrySet.headSet(entry, true);
assertEquals(3, headSet.size());// 2 199
headSetIterator = headSet.iterator();
assertEquals(2, ((Entry) headSetIterator.next()).getValue());
assertEquals(199, ((Entry) headSetIterator.next()).getValue());
assertEquals(198, ((Entry) headSetIterator.next()).getValue());