keySet = tm.headMap(key, false).navigableKeySet();
assertNotNull(keySet.lower(key));
}
public void test_AscendingSubMapKeySet_higher() {
NavigableSet keySet;
Iterator iterator;
String key, lowerKey;
int value, lowerValue;
keySet = navigableMap_startExcluded_endExcluded.navigableKeySet();
iterator = keySet.iterator();
while (iterator.hasNext()) {
key = (String) iterator.next();
value = Integer.valueOf(key);
lowerKey = (String) keySet.higher(key);
if (value < 108) {
lowerValue = Integer.valueOf(lowerKey);
assertEquals(value + 1, lowerValue);
} else {
assertNull(lowerKey);
}
}
keySet = navigableMap_startExcluded_endIncluded.navigableKeySet();
iterator = keySet.iterator();
while (iterator.hasNext()) {
key = (String) iterator.next();
value = Integer.valueOf(key);
lowerKey = (String) keySet.higher(key);
if (value < 109) {
lowerValue = Integer.valueOf(lowerKey);
assertEquals(value + 1, lowerValue);
} else {
assertNull(lowerKey);
}
}
keySet = navigableMap_startIncluded_endExcluded.navigableKeySet();
iterator = keySet.iterator();
while (iterator.hasNext()) {
key = (String) iterator.next();
value = Integer.valueOf(key);
lowerKey = (String) keySet.higher(key);
if (value < 108) {
lowerValue = Integer.valueOf(lowerKey);
assertEquals(value + 1, lowerValue);
} else {
assertNull(lowerKey);
}
}
keySet = navigableMap_startIncluded_endIncluded.navigableKeySet();
iterator = keySet.iterator();
while (iterator.hasNext()) {
key = (String) iterator.next();
value = Integer.valueOf(key);
lowerKey = (String) keySet.higher(key);
if (value < 109) {
lowerValue = Integer.valueOf(lowerKey);
assertEquals(value + 1, lowerValue);
} else {
assertNull(lowerKey);
}
}
key = new Integer(2).toString();
keySet = tm.headMap(key, true).navigableKeySet();
iterator = keySet.iterator();
iterator.next();// 0
iterator.next();// 1
lowerKey = (String) keySet.higher(iterator.next());
String expectedLowerKey = (String) iterator.next();
assertEquals(expectedLowerKey, lowerKey);
try {
keySet.higher(null);
fail("should throw NPE");
} catch (NullPointerException e) {
// Expected
}
key = new Integer(0).toString();
keySet = tm.headMap(key, true).navigableKeySet();
assertNull(keySet.higher(key));
key = new Integer(0).toString();
keySet = tm.headMap(key, false).navigableKeySet();
assertNull(keySet.higher(key));
key = new Integer(999).toString();
keySet = tm.headMap(key, true).navigableKeySet();
assertNull(keySet.higher(key));
key = new Integer(999).toString();
keySet = tm.headMap(key, false).navigableKeySet();
assertNull(keySet.higher(key));
}