List of usage examples for java.util NavigableSet subSet
SortedSet<E> subSet(E fromElement, E toElement);
Equivalent to subSet(fromElement, true, toElement, false) .
From source file:com.google.gwt.emultest.java.util.TreeSetTest.java
/** * Test method for 'java.util.SortedSet.subSet(Object, Object)' and * 'java.util.NavigableSet.subSet(Object, boolean, Object, boolean)'. * * @see java.util.SortedSet#subSet(Object, Object) * @see java.util.NavigableSet#subSet(Object, boolean, Object, boolean) *///w ww .jav a2s.c o m public void testSubSet() { NavigableSet<E> sortedSet = createNavigableSet(); // test with no entries assertEquals(0, sortedSet.subSet(getKeys()[0], getKeys()[0]).size()); assertEquals(0, sortedSet.subSet(getKeys()[0], false, getKeys()[0], false).size()); assertEquals(0, sortedSet.subSet(getKeys()[0], true, getKeys()[0], false).size()); assertEquals(0, sortedSet.subSet(getKeys()[0], false, getKeys()[0], true).size()); assertEquals(0, sortedSet.subSet(getKeys()[0], true, getKeys()[0], true).size()); // test with a single entry set sortedSet.add(getKeys()[0]); assertEquals(0, sortedSet.subSet(getKeys()[0], getKeys()[0]).size()); // bounded by a "wide" range assertEquals(1, sortedSet.subSet(getLessThanMinimumKey(), getGreaterThanMaximumKey()).size()); assertEquals(1, sortedSet.subSet(getLessThanMinimumKey(), false, getGreaterThanMaximumKey(), false).size()); assertEquals(1, sortedSet.subSet(getLessThanMinimumKey(), true, getGreaterThanMaximumKey(), false).size()); assertEquals(1, sortedSet.subSet(getLessThanMinimumKey(), false, getGreaterThanMaximumKey(), true).size()); assertEquals(1, sortedSet.subSet(getLessThanMinimumKey(), true, getGreaterThanMaximumKey(), true).size()); // test with two entry set sortedSet.add(getKeys()[1]); assertEquals(1, sortedSet.subSet(getKeys()[0], getKeys()[1]).size()); assertEquals(getKeys()[0], sortedSet.subSet(getKeys()[0], getKeys()[1]).toArray()[0]); assertEquals(0, sortedSet.subSet(getKeys()[0], false, getKeys()[1], false).size()); assertEquals(1, sortedSet.subSet(getKeys()[0], false, getKeys()[1], true).size()); assertEquals(getKeys()[1], sortedSet.subSet(getKeys()[0], false, getKeys()[1], true).toArray()[0]); assertEquals(1, sortedSet.subSet(getKeys()[0], true, getKeys()[1], false).size()); assertEquals(getKeys()[0], sortedSet.subSet(getKeys()[0], true, getKeys()[1], false).toArray()[0]); assertEquals(2, sortedSet.subSet(getKeys()[0], true, getKeys()[1], true).size()); assertEquals(getKeys()[0], sortedSet.subSet(getKeys()[0], true, getKeys()[1], true).toArray()[0]); assertEquals(getKeys()[1], sortedSet.subSet(getKeys()[0], true, getKeys()[1], true).toArray()[1]); // bounded by a "wide" range SortedSet<E> subSet = sortedSet.subSet(getLessThanMinimumKey(), getGreaterThanMaximumKey()); assertEquals(2, subSet.size()); assertEquals(2, sortedSet.subSet(getLessThanMinimumKey(), false, getGreaterThanMaximumKey(), false).size()); assertEquals(1, sortedSet.subSet(getKeys()[0], false, getGreaterThanMaximumKey(), false).size()); assertEquals(0, sortedSet.subSet(getKeys()[0], false, getKeys()[1], false).size()); assertEquals(2, sortedSet.subSet(getKeys()[0], true, getGreaterThanMaximumKey(), false).size()); assertEquals(1, sortedSet.subSet(getKeys()[0], true, getKeys()[1], false).size()); assertEquals(2, sortedSet.subSet(getKeys()[0], true, getGreaterThanMaximumKey(), true).size()); assertEquals(2, sortedSet.subSet(getKeys()[0], true, getKeys()[1], true).size()); }