本文整理汇总了Java中java.util.SortedSet.subSet方法的典型用法代码示例。如果您正苦于以下问题:Java SortedSet.subSet方法的具体用法?Java SortedSet.subSet怎么用?Java SortedSet.subSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.SortedSet
的用法示例。
在下文中一共展示了SortedSet.subSet方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testExplicit_subSet
import java.util.SortedSet; //导入方法依赖的package包/类
public void testExplicit_subSet() {
SortedSet<String> set = ImmutableSortedSet.orderedBy(STRING_LENGTH).add(
"in", "the", "quick", "jumped", "over", "a").build();
assertTrue(set.subSet("the", "quick") instanceof ImmutableSortedSet);
assertTrue(set.subSet("", "b") instanceof ImmutableSortedSet);
assertThat(set.subSet("the", "quick")).containsExactly("the", "over").inOrder();
assertThat(set.subSet("a", "california"))
.containsExactly("a", "in", "the", "over", "quick", "jumped").inOrder();
assertTrue(set.subSet("", "b").isEmpty());
assertTrue(set.subSet("vermont", "california").isEmpty());
assertTrue(set.subSet("aaa", "zzz").isEmpty());
try {
set.subSet("quick", "the");
fail();
} catch (IllegalArgumentException expected) {
}
}
示例2: testElementSetSubsetRemove
import java.util.SortedSet; //导入方法依赖的package包/类
public void testElementSetSubsetRemove() {
TreeMultiset<String> ms = TreeMultiset.create();
ms.add("a", 1);
ms.add("b", 3);
ms.add("c", 2);
ms.add("d", 1);
ms.add("e", 3);
ms.add("f", 2);
SortedSet<String> elementSet = ms.elementSet();
assertThat(elementSet).containsExactly("a", "b", "c", "d", "e", "f").inOrder();
SortedSet<String> subset = elementSet.subSet("b", "f");
assertThat(subset).containsExactly("b", "c", "d", "e").inOrder();
assertTrue(subset.remove("c"));
assertThat(elementSet).containsExactly("a", "b", "d", "e", "f").inOrder();
assertThat(subset).containsExactly("b", "d", "e").inOrder();
assertEquals(10, ms.size());
assertFalse(subset.remove("a"));
assertThat(elementSet).containsExactly("a", "b", "d", "e", "f").inOrder();
assertThat(subset).containsExactly("b", "d", "e").inOrder();
assertEquals(10, ms.size());
}
示例3: testElementSetSubsetRemoveAll
import java.util.SortedSet; //导入方法依赖的package包/类
public void testElementSetSubsetRemoveAll() {
TreeMultiset<String> ms = TreeMultiset.create();
ms.add("a", 1);
ms.add("b", 3);
ms.add("c", 2);
ms.add("d", 1);
ms.add("e", 3);
ms.add("f", 2);
SortedSet<String> elementSet = ms.elementSet();
assertThat(elementSet).containsExactly("a", "b", "c", "d", "e", "f").inOrder();
SortedSet<String> subset = elementSet.subSet("b", "f");
assertThat(subset).containsExactly("b", "c", "d", "e").inOrder();
assertTrue(subset.removeAll(Arrays.asList("a", "c")));
assertThat(elementSet).containsExactly("a", "b", "d", "e", "f").inOrder();
assertThat(subset).containsExactly("b", "d", "e").inOrder();
assertEquals(10, ms.size());
}
示例4: testElementSetSubsetRetainAll
import java.util.SortedSet; //导入方法依赖的package包/类
public void testElementSetSubsetRetainAll() {
TreeMultiset<String> ms = TreeMultiset.create();
ms.add("a", 1);
ms.add("b", 3);
ms.add("c", 2);
ms.add("d", 1);
ms.add("e", 3);
ms.add("f", 2);
SortedSet<String> elementSet = ms.elementSet();
assertThat(elementSet).containsExactly("a", "b", "c", "d", "e", "f").inOrder();
SortedSet<String> subset = elementSet.subSet("b", "f");
assertThat(subset).containsExactly("b", "c", "d", "e").inOrder();
assertTrue(subset.retainAll(Arrays.asList("a", "c")));
assertThat(elementSet).containsExactly("a", "c", "f").inOrder();
assertThat(subset).containsExactly("c");
assertEquals(5, ms.size());
}
示例5: testElementSetSubsetClear
import java.util.SortedSet; //导入方法依赖的package包/类
public void testElementSetSubsetClear() {
TreeMultiset<String> ms = TreeMultiset.create();
ms.add("a", 1);
ms.add("b", 3);
ms.add("c", 2);
ms.add("d", 1);
ms.add("e", 3);
ms.add("f", 2);
SortedSet<String> elementSet = ms.elementSet();
assertThat(elementSet).containsExactly("a", "b", "c", "d", "e", "f").inOrder();
SortedSet<String> subset = elementSet.subSet("b", "f");
assertThat(subset).containsExactly("b", "c", "d", "e").inOrder();
subset.clear();
assertThat(elementSet).containsExactly("a", "f").inOrder();
assertThat(subset).isEmpty();
assertEquals(3, ms.size());
}
示例6: createSubSet
import java.util.SortedSet; //导入方法依赖的package包/类
/**
* Calls the smallest subSet overload that filters out the extreme values.
*/
SortedSet<E> createSubSet(SortedSet<E> set, E firstExclusive, E lastExclusive) {
if (from == Bound.NO_BOUND && to == Bound.EXCLUSIVE) {
return set.headSet(lastExclusive);
} else if (from == Bound.INCLUSIVE && to == Bound.NO_BOUND) {
return set.tailSet(firstInclusive);
} else if (from == Bound.INCLUSIVE && to == Bound.EXCLUSIVE) {
return set.subSet(firstInclusive, lastExclusive);
} else {
throw new IllegalArgumentException();
}
}
示例7: testOf_subSet
import java.util.SortedSet; //导入方法依赖的package包/类
public void testOf_subSet() {
SortedSet<String> set = of("e", "f", "b", "d", "c");
assertTrue(set.subSet("c", "e") instanceof ImmutableSortedSet);
assertThat(set.subSet("c", "e")).containsExactly("c", "d").inOrder();
assertThat(set.subSet("a", "g")).containsExactly("b", "c", "d", "e", "f").inOrder();
assertSame(of(), set.subSet("a", "b"));
assertSame(of(), set.subSet("g", "h"));
assertSame(of(), set.subSet("c", "c"));
try {
set.subSet("e", "c");
fail();
} catch (IllegalArgumentException expected) {
}
}
示例8: testCopyOf_subSet
import java.util.SortedSet; //导入方法依赖的package包/类
public void testCopyOf_subSet() {
SortedSet<String> set = of("e", "a", "f", "b", "d", "c");
SortedSet<String> subset = set.subSet("c", "e");
SortedSet<String> copy = copyOf(subset);
assertEquals(subset, copy);
}