NavigableSet descendingKeySet = keySet.descendingSet();
assertEquals(new Integer(0).toString(), descendingKeySet.pollLast());
}
public void test_DescendingSubMapKeySet_headSet() {
NavigableSet keySet, descendingKeySet;
SortedSet headSet;
String endKey, key;
Iterator iterator;
int index;
keySet = navigableMap_startExcluded_endExcluded.navigableKeySet();
descendingKeySet = keySet.descendingSet();
endKey = new Integer(99).toString();
try {
descendingKeySet.headSet(endKey);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
descendingKeySet.headSet(endKey, false);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
descendingKeySet.headSet(endKey, true);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
endKey = new Integer(100).toString();
headSet = descendingKeySet.headSet(endKey);
iterator = headSet.iterator();
for (index = 108; iterator.hasNext(); index--) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(100, index);
headSet = descendingKeySet.headSet(endKey, false);
iterator = headSet.iterator();
for (index = 108; iterator.hasNext(); index--) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(100, index);
try {
descendingKeySet.headSet(endKey, true);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
endKey = new Integer(101).toString();
headSet = descendingKeySet.headSet(endKey);
iterator = headSet.iterator();
for (index = 108; iterator.hasNext(); index--) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(101, index);
headSet = descendingKeySet.headSet(endKey, false);
iterator = headSet.iterator();
for (index = 108; iterator.hasNext(); index--) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(101, index);
headSet = descendingKeySet.headSet(endKey, true);
iterator = headSet.iterator();
for (index = 108; iterator.hasNext(); index--) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(100, index);
for (int i = 102; i < 109; i++) {
endKey = new Integer(i).toString();
headSet = descendingKeySet.headSet(endKey);
iterator = headSet.iterator();
int j;
for (j = 108; iterator.hasNext(); j--) {
key = (String) iterator.next();
assertEquals(new Integer(j).toString(), key);
}
assertEquals(i, j);
headSet = descendingKeySet.headSet(endKey, false);
iterator = headSet.iterator();
for (j = 108; iterator.hasNext(); j--) {
key = (String) iterator.next();
assertEquals(new Integer(j).toString(), key);
}
assertEquals(i, j);
headSet = descendingKeySet.headSet(endKey, true);
iterator = headSet.iterator();
for (j = 108; iterator.hasNext(); j--) {
key = (String) iterator.next();
assertEquals(new Integer(j).toString(), key);
}
assertEquals(i - 1, j);
}
endKey = new Integer(109).toString();
headSet = descendingKeySet.headSet(endKey);
iterator = headSet.iterator();
for (index = 108; iterator.hasNext(); index--) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(108, index);
headSet = descendingKeySet.headSet(endKey, false);
iterator = headSet.iterator();
for (index = 108; iterator.hasNext(); index--) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(108, index);
try {
descendingKeySet.headSet(endKey, true);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
endKey = new Integer(110).toString();
try {
descendingKeySet.headSet(endKey);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
descendingKeySet.headSet(endKey, true);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
descendingKeySet.headSet(endKey, false);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
keySet = navigableMap_startExcluded_endIncluded.navigableKeySet();
descendingKeySet = keySet.descendingSet();
endKey = new Integer(99).toString();
try {
descendingKeySet.headSet(endKey);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
descendingKeySet.headSet(endKey, false);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
descendingKeySet.headSet(endKey, true);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
endKey = new Integer(100).toString();
headSet = descendingKeySet.headSet(endKey);
iterator = headSet.iterator();
for (index = 109; iterator.hasNext(); index--) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(100, index);
headSet = descendingKeySet.headSet(endKey, false);
iterator = headSet.iterator();
for (index = 109; iterator.hasNext(); index--) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(100, index);
try {
descendingKeySet.headSet(endKey, true);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
endKey = new Integer(101).toString();
headSet = descendingKeySet.headSet(endKey);
iterator = headSet.iterator();
for (index = 109; iterator.hasNext(); index--) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(101, index);
headSet = descendingKeySet.headSet(endKey, false);
iterator = headSet.iterator();
for (index = 109; iterator.hasNext(); index--) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(101, index);
headSet = descendingKeySet.headSet(endKey, true);
iterator = headSet.iterator();
for (index = 109; iterator.hasNext(); index--) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(100, index);
for (int i = 102; i < 109; i++) {
endKey = new Integer(i).toString();
headSet = descendingKeySet.headSet(endKey);
iterator = headSet.iterator();
int j;
for (j = 109; iterator.hasNext(); j--) {
key = (String) iterator.next();
assertEquals(new Integer(j).toString(), key);
}
assertEquals(i, j);
headSet = descendingKeySet.headSet(endKey, false);
iterator = headSet.iterator();
for (j = 109; iterator.hasNext(); j--) {
key = (String) iterator.next();
assertEquals(new Integer(j).toString(), key);
}
assertEquals(i, j);
headSet = descendingKeySet.headSet(endKey, true);
iterator = headSet.iterator();
for (j = 109; iterator.hasNext(); j--) {
key = (String) iterator.next();
assertEquals(new Integer(j).toString(), key);
}
assertEquals(i - 1, j);
}
endKey = new Integer(109).toString();
headSet = descendingKeySet.headSet(endKey);
iterator = headSet.iterator();
for (index = 109; iterator.hasNext(); index--) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(109, index);
headSet = descendingKeySet.headSet(endKey, false);
iterator = headSet.iterator();
for (index = 109; iterator.hasNext(); index--) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(109, index);
headSet = descendingKeySet.headSet(endKey, true);
iterator = headSet.iterator();
for (index = 109; iterator.hasNext(); index--) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(108, index);
endKey = new Integer(110).toString();
try {
descendingKeySet.headSet(endKey);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
descendingKeySet.headSet(endKey, true);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
descendingKeySet.headSet(endKey, false);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
keySet = navigableMap_startIncluded_endExcluded.navigableKeySet();
descendingKeySet = keySet.descendingSet();
endKey = new Integer(99).toString();
try {
descendingKeySet.headSet(endKey);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
descendingKeySet.headSet(endKey, false);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
descendingKeySet.headSet(endKey, true);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
endKey = new Integer(100).toString();
headSet = descendingKeySet.headSet(endKey);
iterator = headSet.iterator();
for (index = 108; iterator.hasNext(); index--) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(100, index);
headSet = descendingKeySet.headSet(endKey, false);
iterator = headSet.iterator();
for (index = 108; iterator.hasNext(); index--) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(100, index);
headSet = descendingKeySet.headSet(endKey, true);
iterator = headSet.iterator();
for (index = 108; iterator.hasNext(); index--) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(99, index);
endKey = new Integer(101).toString();
headSet = descendingKeySet.headSet(endKey);
iterator = headSet.iterator();
for (index = 108; iterator.hasNext(); index--) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(101, index);
headSet = descendingKeySet.headSet(endKey, false);
iterator = headSet.iterator();
for (index = 108; iterator.hasNext(); index--) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(101, index);
headSet = descendingKeySet.headSet(endKey, true);
iterator = headSet.iterator();
for (index = 108; iterator.hasNext(); index--) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(100, index);
for (int i = 102; i < 109; i++) {
endKey = new Integer(i).toString();
headSet = descendingKeySet.headSet(endKey);
iterator = headSet.iterator();
int j;
for (j = 108; iterator.hasNext(); j--) {
key = (String) iterator.next();
assertEquals(new Integer(j).toString(), key);
}
assertEquals(i, j);
headSet = descendingKeySet.headSet(endKey, false);
iterator = headSet.iterator();
for (j = 108; iterator.hasNext(); j--) {
key = (String) iterator.next();
assertEquals(new Integer(j).toString(), key);
}
assertEquals(i, j);
headSet = descendingKeySet.headSet(endKey, true);
iterator = headSet.iterator();
for (j = 108; iterator.hasNext(); j--) {
key = (String) iterator.next();
assertEquals(new Integer(j).toString(), key);
}
assertEquals(i - 1, j);
}
endKey = new Integer(109).toString();
headSet = descendingKeySet.headSet(endKey);
iterator = headSet.iterator();
for (index = 108; iterator.hasNext(); index--) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(108, index);
headSet = descendingKeySet.headSet(endKey, false);
iterator = headSet.iterator();
for (index = 108; iterator.hasNext(); index--) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(108, index);
try {
descendingKeySet.headSet(endKey, true);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
endKey = new Integer(110).toString();
try {
descendingKeySet.headSet(endKey);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
descendingKeySet.headSet(endKey, true);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
descendingKeySet.headSet(endKey, false);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
keySet = navigableMap_startIncluded_endIncluded.navigableKeySet();
descendingKeySet = keySet.descendingSet();
endKey = new Integer(99).toString();
try {
descendingKeySet.headSet(endKey);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
descendingKeySet.headSet(endKey, false);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
descendingKeySet.headSet(endKey, true);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
endKey = new Integer(100).toString();
headSet = descendingKeySet.headSet(endKey);
iterator = headSet.iterator();
for (index = 109; iterator.hasNext(); index--) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(100, index);
headSet = descendingKeySet.headSet(endKey, false);
iterator = headSet.iterator();
for (index = 109; iterator.hasNext(); index--) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(100, index);
headSet = descendingKeySet.headSet(endKey, true);
iterator = headSet.iterator();
for (index = 109; iterator.hasNext(); index--) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(99, index);
endKey = new Integer(101).toString();
headSet = descendingKeySet.headSet(endKey);
iterator = headSet.iterator();
for (index = 109; iterator.hasNext(); index--) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(101, index);
headSet = descendingKeySet.headSet(endKey, false);
iterator = headSet.iterator();
for (index = 109; iterator.hasNext(); index--) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(101, index);
headSet = descendingKeySet.headSet(endKey, true);
iterator = headSet.iterator();
for (index = 109; iterator.hasNext(); index--) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(100, index);
for (int i = 102; i < 109; i++) {
endKey = new Integer(i).toString();
headSet = descendingKeySet.headSet(endKey);
iterator = headSet.iterator();
int j;
for (j = 109; iterator.hasNext(); j--) {
key = (String) iterator.next();
assertEquals(new Integer(j).toString(), key);
}
assertEquals(i, j);
headSet = descendingKeySet.headSet(endKey, false);
iterator = headSet.iterator();
for (j = 109; iterator.hasNext(); j--) {
key = (String) iterator.next();
assertEquals(new Integer(j).toString(), key);
}
assertEquals(i, j);
headSet = descendingKeySet.headSet(endKey, true);
iterator = headSet.iterator();
for (j = 109; iterator.hasNext(); j--) {
key = (String) iterator.next();
assertEquals(new Integer(j).toString(), key);
}
assertEquals(i - 1, j);
}
endKey = new Integer(109).toString();
headSet = descendingKeySet.headSet(endKey);
iterator = headSet.iterator();
for (index = 109; iterator.hasNext(); index--) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(109, index);
headSet = descendingKeySet.headSet(endKey, false);
iterator = headSet.iterator();
for (index = 109; iterator.hasNext(); index--) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(109, index);
headSet = descendingKeySet.headSet(endKey, true);
iterator = headSet.iterator();
for (index = 109; iterator.hasNext(); index--) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(108, index);
endKey = new Integer(110).toString();
try {
descendingKeySet.headSet(endKey);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
descendingKeySet.headSet(endKey, true);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
descendingKeySet.headSet(endKey, false);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
key = new Integer(2).toString();
keySet = tm.headMap(key, true).navigableKeySet();
descendingKeySet = keySet.descendingSet();
iterator = descendingKeySet.iterator();
iterator.next();
endKey = (String) iterator.next();
headSet = descendingKeySet.headSet(endKey);
assertEquals(1, headSet.size());
headSet = descendingKeySet.headSet(endKey, false);
assertEquals(1, headSet.size());
headSet = descendingKeySet.headSet(endKey, true);
assertEquals(2, headSet.size());
key = new Integer(2).toString();
keySet = tm.tailMap(key, true).navigableKeySet();
descendingKeySet = keySet.descendingSet();
iterator = descendingKeySet.iterator();
iterator.next();
endKey = (String) iterator.next();
headSet = descendingKeySet.headSet(endKey);
assertEquals(1, headSet.size());