}
}
public void test_DescendingSubMapEntrySet_subSet() {
Set entrySet, subSet;
NavigableSet descendingSubMapEntrySet;
Entry startEntry, endEntry;
Iterator subSetIterator;
entrySet = navigableMap_startExcluded_endExcluded.entrySet();
if (entrySet instanceof NavigableSet) {
descendingSubMapEntrySet = ((NavigableSet) entrySet)
.descendingSet();
Iterator iteratorStart = descendingSubMapEntrySet.iterator();
while (iteratorStart.hasNext()) {
startEntry = (Entry) iteratorStart.next();
Iterator iteratorEnd = descendingSubMapEntrySet.iterator();
while (iteratorEnd.hasNext()) {
endEntry = (Entry) iteratorEnd.next();
int startIndex = (Integer) startEntry.getValue();
int endIndex = (Integer) endEntry.getValue();
if (startIndex < endIndex) {
try {
descendingSubMapEntrySet.subSet(startEntry,
endEntry);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
descendingSubMapEntrySet.subSet(startEntry, false,
endEntry, false);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
descendingSubMapEntrySet.subSet(startEntry, false,
endEntry, true);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
descendingSubMapEntrySet.subSet(startEntry, true,
endEntry, false);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
descendingSubMapEntrySet.subSet(startEntry, true,
endEntry, true);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
} else {
subSet = descendingSubMapEntrySet.subSet(startEntry,
endEntry);
subSetIterator = subSet.iterator();
for (int index = startIndex; subSetIterator.hasNext(); index--) {
assertEquals(index, ((Entry) subSetIterator.next())
.getValue());
}
subSet = descendingSubMapEntrySet.subSet(startEntry,
false, endEntry, false);
subSetIterator = subSet.iterator();
for (int index = startIndex - 1; subSetIterator
.hasNext(); index--) {
assertEquals(index, ((Entry) subSetIterator.next())
.getValue());
}
subSet = descendingSubMapEntrySet.subSet(startEntry,
false, endEntry, true);
subSetIterator = subSet.iterator();
for (int index = startIndex - 1; subSetIterator
.hasNext(); index--) {
assertEquals(index, ((Entry) subSetIterator.next())
.getValue());
}
subSet = descendingSubMapEntrySet.subSet(startEntry,
true, endEntry, false);
subSetIterator = subSet.iterator();
for (int index = startIndex; subSetIterator.hasNext(); index--) {
assertEquals(index, ((Entry) subSetIterator.next())
.getValue());
}
subSet = descendingSubMapEntrySet.subSet(startEntry,
true, endEntry, true);
subSetIterator = subSet.iterator();
for (int index = startIndex; subSetIterator.hasNext(); index--) {
assertEquals(index, ((Entry) subSetIterator.next())
.getValue());
}
}
}
}
}
String endKey = new Integer(2).toString();
entrySet = tm.headMap(endKey, true).entrySet();
if (entrySet instanceof NavigableSet) {
// [2...0]
descendingSubMapEntrySet = ((NavigableSet) entrySet)
.descendingSet();
Iterator iterator = descendingSubMapEntrySet.iterator();
startEntry = (Entry) iterator.next();
iterator.next();
endEntry = (Entry) iterator.next();
subSet = descendingSubMapEntrySet.subSet(startEntry, endEntry);
assertEquals(2, subSet.size());
subSet = descendingSubMapEntrySet.subSet(startEntry, false,
endEntry, false);
assertEquals(1, subSet.size());
subSetIterator = subSet.iterator();
assertEquals(199, ((Entry) subSetIterator.next()).getValue());
subSet = descendingSubMapEntrySet.subSet(startEntry, false,
endEntry, true);
assertEquals(2, subSet.size());
subSetIterator = subSet.iterator();
assertEquals(199, ((Entry) subSetIterator.next()).getValue());
assertEquals(198, ((Entry) subSetIterator.next()).getValue());
subSet = descendingSubMapEntrySet.subSet(startEntry, true,
endEntry, false);
assertEquals(2, subSet.size());
subSetIterator = subSet.iterator();
assertEquals(2, ((Entry) subSetIterator.next()).getValue());
assertEquals(199, ((Entry) subSetIterator.next()).getValue());
subSet = descendingSubMapEntrySet.subSet(startEntry, true,
endEntry, true);
assertEquals(3, subSet.size());
subSetIterator = subSet.iterator();
assertEquals(2, ((Entry) subSetIterator.next()).getValue());
assertEquals(199, ((Entry) subSetIterator.next()).getValue());
assertEquals(198, ((Entry) subSetIterator.next()).getValue());
}
// With Comnparator
entrySet = subMap_startExcluded_endExcluded_comparator.entrySet();
if (entrySet instanceof NavigableSet) {
descendingSubMapEntrySet = ((NavigableSet) entrySet)
.descendingSet();
Iterator iteratorStart = descendingSubMapEntrySet.iterator();
while (iteratorStart.hasNext()) {
startEntry = (Entry) iteratorStart.next();
Iterator iteratorEnd = descendingSubMapEntrySet.iterator();
while (iteratorEnd.hasNext()) {
endEntry = (Entry) iteratorEnd.next();
int startIndex = (Integer) startEntry.getValue();
int endIndex = (Integer) endEntry.getValue();
if (startIndex < endIndex) {
try {
descendingSubMapEntrySet.subSet(startEntry,
endEntry);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
descendingSubMapEntrySet.subSet(startEntry, false,
endEntry, false);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
descendingSubMapEntrySet.subSet(startEntry, false,
endEntry, true);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
descendingSubMapEntrySet.subSet(startEntry, true,
endEntry, false);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
descendingSubMapEntrySet.subSet(startEntry, true,
endEntry, true);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
} else {
subSet = descendingSubMapEntrySet.subSet(startEntry,
endEntry);
subSetIterator = subSet.iterator();
for (int index = startIndex; subSetIterator.hasNext(); index--) {
assertEquals(index, ((Entry) subSetIterator.next())
.getValue());
}
subSet = descendingSubMapEntrySet.subSet(startEntry,
false, endEntry, false);
subSetIterator = subSet.iterator();
for (int index = startIndex - 1; subSetIterator
.hasNext(); index--) {
assertEquals(index, ((Entry) subSetIterator.next())
.getValue());
}
subSet = descendingSubMapEntrySet.subSet(startEntry,
false, endEntry, true);
subSetIterator = subSet.iterator();
for (int index = startIndex - 1; subSetIterator
.hasNext(); index--) {
assertEquals(index, ((Entry) subSetIterator.next())
.getValue());
}
subSet = descendingSubMapEntrySet.subSet(startEntry,
true, endEntry, false);
subSetIterator = subSet.iterator();
for (int index = startIndex; subSetIterator.hasNext(); index--) {
assertEquals(index, ((Entry) subSetIterator.next())
.getValue());
}
subSet = descendingSubMapEntrySet.subSet(startEntry,
true, endEntry, true);
subSetIterator = subSet.iterator();
for (int index = startIndex; subSetIterator.hasNext(); index--) {
assertEquals(index, ((Entry) subSetIterator.next())
.getValue());