}
}
}
public void test_DescendingSubMapKeySet_higher() {
NavigableSet keySet, descendingKeySet;
Iterator iterator;
String key, higherKey;
int value, higherValue;
keySet = navigableMap_startExcluded_endExcluded.navigableKeySet();
descendingKeySet = keySet.descendingSet();
iterator = descendingKeySet.iterator();
while (iterator.hasNext()) {
key = (String) iterator.next();
value = Integer.valueOf(key);
higherKey = (String) descendingKeySet.higher(key);
if (value > 101) {
higherValue = Integer.valueOf(higherKey);
assertEquals(value - 1, higherValue);
} else {
assertNull(higherKey);
}
}
key = new Integer(99999).toString();
higherKey = (String) descendingKeySet.higher(key);
assertEquals("108", higherKey);
key = new Integer(-1).toString();
higherKey = (String) descendingKeySet.higher(key);
assertNull(higherKey);
key = new Integer(100).toString();
higherKey = (String) descendingKeySet.higher(key);
assertNull(higherKey);
key = new Integer(0).toString();
higherKey = (String) descendingKeySet.higher(key);
assertNull(higherKey);
key = new Integer(2).toString();
higherKey = (String) descendingKeySet.higher(key);
assertEquals(108, Integer.parseInt(higherKey));
keySet = navigableMap_startExcluded_endIncluded.navigableKeySet();
descendingKeySet = keySet.descendingSet();
iterator = descendingKeySet.iterator();
while (iterator.hasNext()) {
key = (String) iterator.next();
value = Integer.valueOf(key);
higherKey = (String) descendingKeySet.higher(key);
if (value > 101) {
higherValue = Integer.valueOf(higherKey);
assertEquals(value - 1, higherValue);
} else {
assertNull(higherKey);
}
}
key = new Integer(99999).toString();
higherKey = (String) descendingKeySet.higher(key);
assertEquals("109", higherKey);
key = new Integer(-1).toString();
higherKey = (String) descendingKeySet.higher(key);
assertNull(higherKey);
key = new Integer(100).toString();
higherKey = (String) descendingKeySet.higher(key);
assertNull(higherKey);
key = new Integer(2).toString();
higherKey = (String) descendingKeySet.higher(key);
assertEquals(109, Integer.parseInt(higherKey));
keySet = navigableMap_startIncluded_endExcluded.navigableKeySet();
descendingKeySet = keySet.descendingSet();
iterator = descendingKeySet.iterator();
while (iterator.hasNext()) {
key = (String) iterator.next();
value = Integer.valueOf(key);
higherKey = (String) descendingKeySet.higher(key);
if (value > 100) {
higherValue = Integer.valueOf(higherKey);
assertEquals(value - 1, higherValue);
} else {
assertNull(higherKey);
}
}
key = new Integer(99999).toString();
higherKey = (String) descendingKeySet.higher(key);
assertEquals("108", higherKey);
key = new Integer(-1).toString();
higherKey = (String) descendingKeySet.higher(key);
assertNull(higherKey);
key = new Integer(100).toString();
higherKey = (String) descendingKeySet.higher(key);
assertNull(higherKey);
key = new Integer(2).toString();
higherKey = (String) descendingKeySet.higher(key);
assertEquals(108, Integer.parseInt(higherKey));
keySet = navigableMap_startIncluded_endIncluded.navigableKeySet();
descendingKeySet = keySet.descendingSet();
iterator = descendingKeySet.iterator();
while (iterator.hasNext()) {
key = (String) iterator.next();
value = Integer.valueOf(key);
higherKey = (String) descendingKeySet.higher(key);
if (value > 100) {
higherValue = Integer.valueOf(higherKey);
assertEquals(value - 1, higherValue);
} else {
assertNull(higherKey);
}
}
key = new Integer(99999).toString();
higherKey = (String) descendingKeySet.higher(key);
assertEquals("109", higherKey);
key = new Integer(-1).toString();
higherKey = (String) descendingKeySet.higher(key);
assertNull(higherKey);
key = new Integer(100).toString();
higherKey = (String) descendingKeySet.higher(key);
assertNull(higherKey);
key = new Integer(2).toString();
higherKey = (String) descendingKeySet.higher(key);
assertEquals(109, Integer.parseInt(higherKey));
key = new Integer(2).toString();
keySet = tm.headMap(key, true).navigableKeySet();
descendingKeySet = keySet.descendingSet();
iterator = descendingKeySet.iterator();
key = (String) iterator.next();
higherKey = (String) descendingKeySet.higher(key);
assertEquals(new Integer(199).toString(), higherKey);
try {
descendingKeySet.higher(null);
fail("should throw NPE");
} catch (NullPointerException e) {
// Expected
}
key = new Integer(0).toString();
String endKey = key;
keySet = tm.headMap(endKey, true).navigableKeySet();
descendingKeySet = keySet.descendingSet();
assertNull(descendingKeySet.higher(endKey));
key = new Integer(0).toString();
keySet = tm.headMap(endKey, false).navigableKeySet();
descendingKeySet = keySet.descendingSet();
assertNull(descendingKeySet.higher(endKey));
endKey = new Integer(999).toString();
keySet = tm.headMap(endKey, true).navigableKeySet();
descendingKeySet = keySet.descendingSet();
assertEquals(new Integer(998).toString(), descendingKeySet
.higher(endKey));
assertNull(descendingKeySet.higher(key));
endKey = new Integer(999).toString();
keySet = tm.headMap(endKey, false).navigableKeySet();
descendingKeySet = keySet.descendingSet();
assertEquals(new Integer(998).toString(), descendingKeySet
.higher(endKey));
assertNull(descendingKeySet.higher(key));
// With Comparator
keySet = ((NavigableMap) subMap_startExcluded_endExcluded_comparator)
.navigableKeySet();
descendingKeySet = keySet.descendingSet();
iterator = descendingKeySet.iterator();
while (iterator.hasNext()) {
key = (String) iterator.next();
value = Integer.valueOf(key);
higherKey = (String) descendingKeySet.higher(key);
if (value > 101) {
higherValue = Integer.valueOf(higherKey);
assertEquals(value - 1, higherValue);
} else {
assertNull(higherKey);
}
}
key = new Integer(99999).toString();
higherKey = (String) descendingKeySet.higher(key);
assertEquals("108", higherKey);
key = new Integer(-1).toString();
higherKey = (String) descendingKeySet.higher(key);
assertNull(higherKey);
key = new Integer(100).toString();
higherKey = (String) descendingKeySet.higher(key);
assertNull(higherKey);
key = new Integer(0).toString();
higherKey = (String) descendingKeySet.higher(key);
assertNull(higherKey);
key = new Integer(2).toString();
higherKey = (String) descendingKeySet.higher(key);
assertEquals(108, Integer.parseInt(higherKey));
keySet = ((NavigableMap) subMap_startExcluded_endIncluded_comparator)
.navigableKeySet();
descendingKeySet = keySet.descendingSet();
iterator = descendingKeySet.iterator();
while (iterator.hasNext()) {
key = (String) iterator.next();
value = Integer.valueOf(key);
higherKey = (String) descendingKeySet.higher(key);
if (value > 101) {
higherValue = Integer.valueOf(higherKey);
assertEquals(value - 1, higherValue);
} else {
assertNull(higherKey);
}
}
key = new Integer(99999).toString();
higherKey = (String) descendingKeySet.higher(key);
assertEquals("109", higherKey);
key = new Integer(-1).toString();
higherKey = (String) descendingKeySet.higher(key);
assertNull(higherKey);
key = new Integer(100).toString();
higherKey = (String) descendingKeySet.higher(key);
assertNull(higherKey);
key = new Integer(2).toString();
higherKey = (String) descendingKeySet.higher(key);
assertEquals(109, Integer.parseInt(higherKey));
keySet = ((NavigableMap) subMap_startIncluded_endExcluded_comparator)
.navigableKeySet();
descendingKeySet = keySet.descendingSet();
iterator = descendingKeySet.iterator();
while (iterator.hasNext()) {
key = (String) iterator.next();
value = Integer.valueOf(key);
higherKey = (String) descendingKeySet.higher(key);
if (value > 100) {
higherValue = Integer.valueOf(higherKey);
assertEquals(value - 1, higherValue);
} else {
assertNull(higherKey);
}
}
key = new Integer(99999).toString();
higherKey = (String) descendingKeySet.higher(key);
assertEquals("108", higherKey);
key = new Integer(-1).toString();
higherKey = (String) descendingKeySet.higher(key);
assertNull(higherKey);
key = new Integer(100).toString();
higherKey = (String) descendingKeySet.higher(key);
assertNull(higherKey);
key = new Integer(2).toString();
higherKey = (String) descendingKeySet.higher(key);
assertEquals(108, Integer.parseInt(higherKey));
keySet = ((NavigableMap) subMap_startIncluded_endIncluded_comparator)
.navigableKeySet();
descendingKeySet = keySet.descendingSet();
iterator = descendingKeySet.iterator();
while (iterator.hasNext()) {
key = (String) iterator.next();
value = Integer.valueOf(key);
higherKey = (String) descendingKeySet.higher(key);
if (value > 100) {
higherValue = Integer.valueOf(higherKey);
assertEquals(value - 1, higherValue);
} else {
assertNull(higherKey);
}
}
key = new Integer(99999).toString();
higherKey = (String) descendingKeySet.higher(key);
assertEquals("109", higherKey);
key = new Integer(-1).toString();
higherKey = (String) descendingKeySet.higher(key);
assertNull(higherKey);
key = new Integer(100).toString();
higherKey = (String) descendingKeySet.higher(key);
assertNull(higherKey);
key = new Integer(2).toString();
higherKey = (String) descendingKeySet.higher(key);
assertEquals(109, Integer.parseInt(higherKey));
key = new Integer(2).toString();
keySet = tm.headMap(key, true).navigableKeySet();
descendingKeySet = keySet.descendingSet();
iterator = descendingKeySet.iterator();
key = (String) iterator.next();
higherKey = (String) descendingKeySet.higher(key);
assertEquals(new Integer(199).toString(), higherKey);
try {
descendingKeySet.higher(null);
fail("should throw NPE");
} catch (NullPointerException e) {
// Expected
}
key = new Integer(0).toString();
endKey = key;
keySet = tm.headMap(endKey, true).navigableKeySet();
descendingKeySet = keySet.descendingSet();
assertNull(descendingKeySet.higher(endKey));
key = new Integer(0).toString();
keySet = tm.headMap(endKey, false).navigableKeySet();
descendingKeySet = keySet.descendingSet();
assertNull(descendingKeySet.higher(endKey));
endKey = new Integer(999).toString();
keySet = tm.headMap(endKey, true).navigableKeySet();
descendingKeySet = keySet.descendingSet();
assertEquals(new Integer(998).toString(), descendingKeySet
.higher(endKey));
assertNull(descendingKeySet.higher(key));
endKey = new Integer(999).toString();
keySet = tm.headMap(endKey, false).navigableKeySet();
descendingKeySet = keySet.descendingSet();
assertEquals(new Integer(998).toString(), descendingKeySet
.higher(endKey));
assertNull(descendingKeySet.higher(key));
}