assertEquals(new Integer(1).toString(), iterator.next());
assertEquals(new Integer(0).toString(), iterator.next());
}
public void test_AscendingSubMapKeySet_headSet() {
NavigableSet keySet;
SortedSet headSet;
String endKey, key;
Iterator iterator;
keySet = navigableMap_startExcluded_endExcluded.navigableKeySet();
endKey = new Integer(99).toString();
try {
keySet.headSet(endKey);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
keySet.headSet(endKey, false);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
keySet.headSet(endKey, true);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
endKey = new Integer(100).toString();
assertEquals(0, keySet.headSet(endKey).size());
assertEquals(0, keySet.headSet(endKey, false).size());
try {
keySet.headSet(endKey, true).size();
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
endKey = new Integer(101).toString();
assertEquals(0, keySet.headSet(endKey).size());
assertEquals(0, keySet.headSet(endKey, false).size());
assertEquals(1, keySet.headSet(endKey, true).size());
for (int i = 102; i < 109; i++) {
endKey = new Integer(i).toString();
headSet = keySet.headSet(endKey);
iterator = headSet.iterator();
int j;
for (j = 101; iterator.hasNext(); j++) {
key = (String) iterator.next();
assertEquals(new Integer(j).toString(), key);
}
assertEquals(i, j);
headSet = keySet.headSet(endKey, false);
iterator = headSet.iterator();
for (j = 101; iterator.hasNext(); j++) {
key = (String) iterator.next();
assertEquals(new Integer(j).toString(), key);
}
assertEquals(i, j);
headSet = keySet.headSet(endKey, true);
iterator = headSet.iterator();
for (j = 101; iterator.hasNext(); j++) {
key = (String) iterator.next();
assertEquals(new Integer(j).toString(), key);
}
assertEquals(i + 1, j);
}
endKey = new Integer(109).toString();
headSet = keySet.headSet(endKey);
iterator = headSet.iterator();
int index;
for (index = 101; iterator.hasNext(); index++) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(109, index);
headSet = keySet.headSet(endKey, false);
iterator = headSet.iterator();
for (index = 101; iterator.hasNext(); index++) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(109, index);
try {
keySet.headSet(endKey, true);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
endKey = new Integer(110).toString();
try {
keySet.headSet(endKey);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
keySet.headSet(endKey, true);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
keySet.headSet(endKey, false);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
keySet = navigableMap_startExcluded_endIncluded.navigableKeySet();
endKey = new Integer(99).toString();
try {
keySet.headSet(endKey);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
keySet.headSet(endKey, true);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
keySet.headSet(endKey, false);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
endKey = new Integer(100).toString();
assertEquals(0, keySet.headSet(endKey).size());
assertEquals(0, keySet.headSet(endKey, false).size());
try {
keySet.headSet(endKey, true);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
endKey = new Integer(101).toString();
assertEquals(0, keySet.headSet(endKey).size());
assertEquals(0, keySet.headSet(endKey).size());
assertEquals(1, keySet.headSet(endKey, true).size());
for (int i = 102; i < 109; i++) {
endKey = new Integer(i).toString();
headSet = keySet.headSet(endKey);
iterator = headSet.iterator();
int j;
for (j = 101; iterator.hasNext(); j++) {
key = (String) iterator.next();
assertEquals(new Integer(j).toString(), key);
}
assertEquals(i, j);
headSet = keySet.headSet(endKey, false);
iterator = headSet.iterator();
for (j = 101; iterator.hasNext(); j++) {
key = (String) iterator.next();
assertEquals(new Integer(j).toString(), key);
}
assertEquals(i, j);
headSet = keySet.headSet(endKey, true);
iterator = headSet.iterator();
for (j = 101; iterator.hasNext(); j++) {
key = (String) iterator.next();
assertEquals(new Integer(j).toString(), key);
}
assertEquals(i + 1, j);
}
endKey = new Integer(109).toString();
headSet = keySet.headSet(endKey);
iterator = headSet.iterator();
for (index = 101; iterator.hasNext(); index++) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(109, index);
headSet = keySet.headSet(endKey, false);
iterator = headSet.iterator();
for (index = 101; iterator.hasNext(); index++) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(109, index);
headSet = keySet.headSet(endKey, true);
iterator = headSet.iterator();
for (index = 101; iterator.hasNext(); index++) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(110, index);
endKey = new Integer(110).toString();
try {
keySet.headSet(endKey);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
keySet.headSet(endKey, false);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
keySet.headSet(endKey, true);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
keySet = navigableMap_startIncluded_endExcluded.navigableKeySet();
endKey = new Integer(99).toString();
try {
keySet.headSet(endKey);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
keySet.headSet(endKey, false);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
keySet.headSet(endKey, true);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
endKey = new Integer(100).toString();
assertEquals(0, keySet.headSet(endKey).size());
assertEquals(0, keySet.headSet(endKey, false).size());
assertEquals(1, keySet.headSet(endKey, true).size());
endKey = new Integer(101).toString();
headSet = keySet.headSet(endKey);
iterator = headSet.iterator();
for (index = 100; iterator.hasNext(); index++) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(101, index);
headSet = keySet.headSet(endKey, false);
iterator = headSet.iterator();
for (index = 100; iterator.hasNext(); index++) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(101, index);
headSet = keySet.headSet(endKey, true);
iterator = headSet.iterator();
for (index = 100; iterator.hasNext(); index++) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(102, index);
for (int i = 102; i < 109; i++) {
endKey = new Integer(i).toString();
headSet = keySet.headSet(endKey);
iterator = headSet.iterator();
int j;
for (j = 100; iterator.hasNext(); j++) {
key = (String) iterator.next();
assertEquals(new Integer(j).toString(), key);
}
assertEquals(i, j);
headSet = keySet.headSet(endKey, false);
iterator = headSet.iterator();
for (j = 100; iterator.hasNext(); j++) {
key = (String) iterator.next();
assertEquals(new Integer(j).toString(), key);
}
assertEquals(i, j);
headSet = keySet.headSet(endKey, true);
iterator = headSet.iterator();
for (j = 100; iterator.hasNext(); j++) {
key = (String) iterator.next();
assertEquals(new Integer(j).toString(), key);
}
assertEquals(i + 1, j);
}
endKey = new Integer(109).toString();
headSet = keySet.headSet(endKey);
iterator = headSet.iterator();
for (index = 100; iterator.hasNext(); index++) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(109, index);
headSet = keySet.headSet(endKey, false);
iterator = headSet.iterator();
for (index = 100; iterator.hasNext(); index++) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(109, index);
try {
keySet.headSet(endKey, true);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
endKey = new Integer(110).toString();
try {
keySet.headSet(endKey);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
keySet.headSet(endKey, false);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
keySet.headSet(endKey, true);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
keySet = navigableMap_startIncluded_endIncluded.navigableKeySet();
endKey = new Integer(99).toString();
try {
keySet.headSet(endKey);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
keySet.headSet(endKey, false);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
keySet.headSet(endKey, true);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
endKey = new Integer(100).toString();
assertEquals(0, keySet.headSet(endKey).size());
assertEquals(0, keySet.headSet(endKey, false).size());
assertEquals(1, keySet.headSet(endKey, true).size());
endKey = new Integer(101).toString();
headSet = keySet.headSet(endKey);
iterator = headSet.iterator();
for (index = 100; iterator.hasNext(); index++) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(101, index);
headSet = keySet.headSet(endKey, false);
iterator = headSet.iterator();
for (index = 100; iterator.hasNext(); index++) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(101, index);
headSet = keySet.headSet(endKey, true);
iterator = headSet.iterator();
for (index = 100; iterator.hasNext(); index++) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(102, index);
for (int i = 102; i < 109; i++) {
endKey = new Integer(i).toString();
headSet = keySet.headSet(endKey);
iterator = headSet.iterator();
int j;
for (j = 100; iterator.hasNext(); j++) {
key = (String) iterator.next();
assertEquals(new Integer(j).toString(), key);
}
assertEquals(i, j);
headSet = keySet.headSet(endKey, false);
iterator = headSet.iterator();
for (j = 100; iterator.hasNext(); j++) {
key = (String) iterator.next();
assertEquals(new Integer(j).toString(), key);
}
assertEquals(i, j);
headSet = keySet.headSet(endKey, true);
iterator = headSet.iterator();
for (j = 100; iterator.hasNext(); j++) {
key = (String) iterator.next();
assertEquals(new Integer(j).toString(), key);
}
assertEquals(i + 1, j);
}
endKey = new Integer(109).toString();
headSet = keySet.headSet(endKey);
iterator = headSet.iterator();
for (index = 100; iterator.hasNext(); index++) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(109, index);
headSet = keySet.headSet(endKey, false);
iterator = headSet.iterator();
for (index = 100; iterator.hasNext(); index++) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(109, index);
headSet = keySet.headSet(endKey, true);
iterator = headSet.iterator();
for (index = 100; iterator.hasNext(); index++) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(110, index);
endKey = new Integer(110).toString();
try {
keySet.headSet(endKey);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
keySet.headSet(endKey, false);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
keySet.headSet(endKey, true);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
key = new Integer(1).toString();
keySet = tm.headMap(key, true).navigableKeySet();
iterator = keySet.iterator();
iterator.next();
endKey = (String) iterator.next();
headSet = keySet.headSet(endKey, false);
assertEquals(1, headSet.size());
Iterator headSetIterator = headSet.iterator();
assertEquals(new Integer(0).toString(), headSetIterator.next());
assertFalse(headSetIterator.hasNext());
try {
headSetIterator.next();
fail("should throw NoSuchElementException");
} catch (NoSuchElementException e) {
// Expected
}
try {
keySet.headSet(null, false);
fail("should throw NPE");
} catch (NullPointerException e) {
// Expected
}
headSet = keySet.headSet(endKey, true);
assertEquals(2, headSet.size());
headSetIterator = headSet.iterator();
assertEquals(new Integer(0).toString(), headSetIterator.next());
assertEquals(new Integer(1).toString(), headSetIterator.next());
assertFalse(headSetIterator.hasNext());
try {
headSetIterator.next();
fail("should throw NoSuchElementException");
} catch (NoSuchElementException e) {
// Expected
}
try {
keySet.headSet(null, false);
fail("should throw NPE");
} catch (NullPointerException e) {
// Expected
}
// With Comparator
keySet = ((NavigableMap) subMap_startExcluded_endExcluded_comparator)
.navigableKeySet();
endKey = new Integer(99).toString();
try {
keySet.headSet(endKey);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
keySet.headSet(endKey, false);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
keySet.headSet(endKey, true);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
endKey = new Integer(100).toString();
assertEquals(0, keySet.headSet(endKey).size());
assertEquals(0, keySet.headSet(endKey, false).size());
try {
keySet.headSet(endKey, true).size();
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
endKey = new Integer(101).toString();
assertEquals(0, keySet.headSet(endKey).size());
assertEquals(0, keySet.headSet(endKey, false).size());
assertEquals(1, keySet.headSet(endKey, true).size());
for (int i = 102; i < 109; i++) {
endKey = new Integer(i).toString();
headSet = keySet.headSet(endKey);
iterator = headSet.iterator();
int j;
for (j = 101; iterator.hasNext(); j++) {
key = (String) iterator.next();
assertEquals(new Integer(j).toString(), key);
}
assertEquals(i, j);
headSet = keySet.headSet(endKey, false);
iterator = headSet.iterator();
for (j = 101; iterator.hasNext(); j++) {
key = (String) iterator.next();
assertEquals(new Integer(j).toString(), key);
}
assertEquals(i, j);
headSet = keySet.headSet(endKey, true);
iterator = headSet.iterator();
for (j = 101; iterator.hasNext(); j++) {
key = (String) iterator.next();
assertEquals(new Integer(j).toString(), key);
}
assertEquals(i + 1, j);
}
endKey = new Integer(109).toString();
headSet = keySet.headSet(endKey);
iterator = headSet.iterator();
for (index = 101; iterator.hasNext(); index++) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(109, index);
headSet = keySet.headSet(endKey, false);
iterator = headSet.iterator();
for (index = 101; iterator.hasNext(); index++) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(109, index);
try {
keySet.headSet(endKey, true);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
endKey = new Integer(110).toString();
try {
keySet.headSet(endKey);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
keySet.headSet(endKey, true);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
keySet.headSet(endKey, false);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
keySet = ((NavigableMap) subMap_startExcluded_endIncluded_comparator)
.navigableKeySet();
endKey = new Integer(99).toString();
try {
keySet.headSet(endKey);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
keySet.headSet(endKey, true);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
keySet.headSet(endKey, false);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
endKey = new Integer(100).toString();
assertEquals(0, keySet.headSet(endKey).size());
assertEquals(0, keySet.headSet(endKey, false).size());
try {
keySet.headSet(endKey, true);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
endKey = new Integer(101).toString();
assertEquals(0, keySet.headSet(endKey).size());
assertEquals(0, keySet.headSet(endKey).size());
assertEquals(1, keySet.headSet(endKey, true).size());
for (int i = 102; i < 109; i++) {
endKey = new Integer(i).toString();
headSet = keySet.headSet(endKey);
iterator = headSet.iterator();
int j;
for (j = 101; iterator.hasNext(); j++) {
key = (String) iterator.next();
assertEquals(new Integer(j).toString(), key);
}
assertEquals(i, j);
headSet = keySet.headSet(endKey, false);
iterator = headSet.iterator();
for (j = 101; iterator.hasNext(); j++) {
key = (String) iterator.next();
assertEquals(new Integer(j).toString(), key);
}
assertEquals(i, j);
headSet = keySet.headSet(endKey, true);
iterator = headSet.iterator();
for (j = 101; iterator.hasNext(); j++) {
key = (String) iterator.next();
assertEquals(new Integer(j).toString(), key);
}
assertEquals(i + 1, j);
}
endKey = new Integer(109).toString();
headSet = keySet.headSet(endKey);
iterator = headSet.iterator();
for (index = 101; iterator.hasNext(); index++) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(109, index);
headSet = keySet.headSet(endKey, false);
iterator = headSet.iterator();
for (index = 101; iterator.hasNext(); index++) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(109, index);
headSet = keySet.headSet(endKey, true);
iterator = headSet.iterator();
for (index = 101; iterator.hasNext(); index++) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(110, index);
endKey = new Integer(110).toString();
try {
keySet.headSet(endKey);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
keySet.headSet(endKey, false);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
keySet.headSet(endKey, true);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
keySet = ((NavigableMap) subMap_startIncluded_endExcluded_comparator)
.navigableKeySet();
endKey = new Integer(99).toString();
try {
keySet.headSet(endKey);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
keySet.headSet(endKey, false);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
keySet.headSet(endKey, true);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
endKey = new Integer(100).toString();
assertEquals(0, keySet.headSet(endKey).size());
assertEquals(0, keySet.headSet(endKey, false).size());
assertEquals(1, keySet.headSet(endKey, true).size());
endKey = new Integer(101).toString();
headSet = keySet.headSet(endKey);
iterator = headSet.iterator();
for (index = 100; iterator.hasNext(); index++) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(101, index);
headSet = keySet.headSet(endKey, false);
iterator = headSet.iterator();
for (index = 100; iterator.hasNext(); index++) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(101, index);
headSet = keySet.headSet(endKey, true);
iterator = headSet.iterator();
for (index = 100; iterator.hasNext(); index++) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(102, index);
for (int i = 102; i < 109; i++) {
endKey = new Integer(i).toString();
headSet = keySet.headSet(endKey);
iterator = headSet.iterator();
int j;
for (j = 100; iterator.hasNext(); j++) {
key = (String) iterator.next();
assertEquals(new Integer(j).toString(), key);
}
assertEquals(i, j);
headSet = keySet.headSet(endKey, false);
iterator = headSet.iterator();
for (j = 100; iterator.hasNext(); j++) {
key = (String) iterator.next();
assertEquals(new Integer(j).toString(), key);
}
assertEquals(i, j);
headSet = keySet.headSet(endKey, true);
iterator = headSet.iterator();
for (j = 100; iterator.hasNext(); j++) {
key = (String) iterator.next();
assertEquals(new Integer(j).toString(), key);
}
assertEquals(i + 1, j);
}
endKey = new Integer(109).toString();
headSet = keySet.headSet(endKey);
iterator = headSet.iterator();
for (index = 100; iterator.hasNext(); index++) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(109, index);
headSet = keySet.headSet(endKey, false);
iterator = headSet.iterator();
for (index = 100; iterator.hasNext(); index++) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(109, index);
try {
keySet.headSet(endKey, true);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
endKey = new Integer(110).toString();
try {
keySet.headSet(endKey);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
keySet.headSet(endKey, false);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
keySet.headSet(endKey, true);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
keySet = ((NavigableMap) subMap_startIncluded_endIncluded_comparator)
.navigableKeySet();
endKey = new Integer(99).toString();
try {
keySet.headSet(endKey);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
keySet.headSet(endKey, false);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
keySet.headSet(endKey, true);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
endKey = new Integer(100).toString();
assertEquals(0, keySet.headSet(endKey).size());
assertEquals(0, keySet.headSet(endKey, false).size());
assertEquals(1, keySet.headSet(endKey, true).size());
endKey = new Integer(101).toString();
headSet = keySet.headSet(endKey);
iterator = headSet.iterator();
for (index = 100; iterator.hasNext(); index++) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(101, index);
headSet = keySet.headSet(endKey, false);
iterator = headSet.iterator();
for (index = 100; iterator.hasNext(); index++) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(101, index);
headSet = keySet.headSet(endKey, true);
iterator = headSet.iterator();
for (index = 100; iterator.hasNext(); index++) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(102, index);
for (int i = 102; i < 109; i++) {
endKey = new Integer(i).toString();
headSet = keySet.headSet(endKey);
iterator = headSet.iterator();
int j;
for (j = 100; iterator.hasNext(); j++) {
key = (String) iterator.next();
assertEquals(new Integer(j).toString(), key);
}
assertEquals(i, j);
headSet = keySet.headSet(endKey, false);
iterator = headSet.iterator();
for (j = 100; iterator.hasNext(); j++) {
key = (String) iterator.next();
assertEquals(new Integer(j).toString(), key);
}
assertEquals(i, j);
headSet = keySet.headSet(endKey, true);
iterator = headSet.iterator();
for (j = 100; iterator.hasNext(); j++) {
key = (String) iterator.next();
assertEquals(new Integer(j).toString(), key);
}
assertEquals(i + 1, j);
}
endKey = new Integer(109).toString();
headSet = keySet.headSet(endKey);
iterator = headSet.iterator();
for (index = 100; iterator.hasNext(); index++) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(109, index);
headSet = keySet.headSet(endKey, false);
iterator = headSet.iterator();
for (index = 100; iterator.hasNext(); index++) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(109, index);
headSet = keySet.headSet(endKey, true);
iterator = headSet.iterator();
for (index = 100; iterator.hasNext(); index++) {
key = (String) iterator.next();
assertEquals(new Integer(index).toString(), key);
}
assertEquals(110, index);
endKey = new Integer(110).toString();
try {
keySet.headSet(endKey);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
keySet.headSet(endKey, false);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
try {
keySet.headSet(endKey, true);
fail("should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
key = new Integer(1).toString();
keySet = tm.headMap(key, true).navigableKeySet();
iterator = keySet.iterator();
iterator.next();
endKey = (String) iterator.next();
headSet = keySet.headSet(endKey, false);
assertEquals(1, headSet.size());
headSetIterator = headSet.iterator();
assertEquals(new Integer(0).toString(), headSetIterator.next());
assertFalse(headSetIterator.hasNext());
try {
headSetIterator.next();
fail("should throw NoSuchElementException");
} catch (NoSuchElementException e) {
// Expected
}
try {
keySet.headSet(null, false);
fail("should throw NPE");
} catch (NullPointerException e) {
// Expected
}
headSet = keySet.headSet(endKey, true);
assertEquals(2, headSet.size());
headSetIterator = headSet.iterator();
assertEquals(new Integer(0).toString(), headSetIterator.next());
assertEquals(new Integer(1).toString(), headSetIterator.next());
assertFalse(headSetIterator.hasNext());
try {
headSetIterator.next();
fail("should throw NoSuchElementException");
} catch (NoSuchElementException e) {
// Expected
}
try {
keySet.headSet(null, false);
fail("should throw NPE");
} catch (NullPointerException e) {
// Expected
}