本文整理了Java中java.util.SortedSet.subSet()
方法的一些代码示例,展示了SortedSet.subSet()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SortedSet.subSet()
方法的具体详情如下:
包路径:java.util.SortedSet
类名称:SortedSet
方法名:subSet
[英]Returns a SortedSet of the specified portion of this SortedSet which contains elements greater or equal to the start element but less than the end element. The returned SortedSet is backed by this SortedMap so changes to one set are reflected by the other.
[中]返回此SortedSet指定部分的SortedSet,其中包含大于或等于起始元素但小于结束元素的元素。返回的SortedSet由该SortedMap支持,因此对一个集合的更改由另一个集合反映。
代码示例来源:origin: google/guava
/** 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();
}
}
代码示例来源:origin: google/guava
@Override
public SortedSet<E> subSet(E fromElement, E toElement) {
return new FilteredSortedSet<E>(
((SortedSet<E>) unfiltered).subSet(fromElement, toElement), predicate);
}
代码示例来源:origin: google/guava
@Override
public SortedSet<E> subSet(E fromElement, E toElement) {
synchronized (mutex) {
return sortedSet(delegate().subSet(fromElement, toElement), mutex);
}
}
代码示例来源:origin: google/guava
@Override
public SortedSet<E> subSet(E fromElement, E toElement) {
return delegate().subSet(fromElement, toElement);
}
代码示例来源:origin: prestodb/presto
@Override
public SortedSet<E> subSet(E fromElement, E toElement) {
synchronized (mutex) {
return sortedSet(delegate().subSet(fromElement, toElement), mutex);
}
}
代码示例来源:origin: google/guava
@Override
public SortedMap<K, V> subMap(K fromKey, K toKey) {
return asMap(backingSet().subSet(fromKey, toKey), function);
}
代码示例来源:origin: google/guava
public void testSingle_subSet() {
SortedSet<String> set = of("e");
assertTrue(set.subSet("c", "g") instanceof ImmutableSortedSet);
assertThat(set.subSet("c", "g")).contains("e");
assertThat(set.subSet("e", "g")).contains("e");
assertSame(of(), set.subSet("f", "g"));
assertSame(of(), set.subSet("c", "e"));
assertSame(of(), set.subSet("c", "d"));
}
代码示例来源:origin: google/guava
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) {
}
}
代码示例来源:origin: google/guava
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) {
}
}
代码示例来源:origin: google/guava
public void testEmpty_subSet() {
SortedSet<String> set = of();
assertSame(set, set.subSet("c", "f"));
}
代码示例来源:origin: google/guava
public void testSortedKeySet() {
TreeMultimap<String, Integer> multimap = createPopulate();
SortedSet<String> keySet = multimap.keySet();
assertEquals(null, keySet.first());
assertEquals("google", keySet.last());
assertEquals(StringLength.COMPARATOR, keySet.comparator());
assertEquals(Sets.newHashSet(null, "tree"), keySet.headSet("yahoo"));
assertEquals(Sets.newHashSet("google"), keySet.tailSet("yahoo"));
assertEquals(Sets.newHashSet("tree"), keySet.subSet("ask", "yahoo"));
}
代码示例来源:origin: google/guava
@SuppressWarnings("unchecked")
public void testSubSet() {
for (List<Integer> contents : SAMPLE_INPUTS) {
for (int i = 0; i < 10; i++) {
for (int j = i; j < 10; j++) {
assertEquals(
filter((C) createUnfiltered(contents).subSet(i, j), EVEN),
filter(createUnfiltered(contents), EVEN).subSet(i, j));
}
}
}
}
}
代码示例来源:origin: google/guava
public void testRowKeySetSubSet() {
sortedTable = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c', "dog", 2, 'd');
Set<String> set = sortedTable.rowKeySet().subSet("cat", "egg");
assertEquals(Collections.singleton("dog"), set);
set.clear();
assertTrue(set.isEmpty());
assertEquals(ImmutableSet.of("bar", "foo"), sortedTable.rowKeySet());
}
代码示例来源:origin: google/guava
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);
}
代码示例来源:origin: google/guava
@GwtIncompatible // SerializableTester
public void testOf_subSetSerialization() {
SortedSet<String> set = of("e", "f", "b", "d", "c");
SerializableTester.reserializeAndAssert(set.subSet("c", "e"));
}
代码示例来源:origin: google/guava
public void testElementSetSortedSetMethods() {
TreeMultiset<String> ms = TreeMultiset.create();
ms.add("c", 1);
ms.add("a", 3);
ms.add("b", 2);
SortedSet<String> elementSet = ms.elementSet();
assertEquals("a", elementSet.first());
assertEquals("c", elementSet.last());
assertEquals(Ordering.natural(), elementSet.comparator());
assertThat(elementSet.headSet("b")).containsExactly("a");
assertThat(elementSet.tailSet("b")).containsExactly("b", "c").inOrder();
assertThat(elementSet.subSet("a", "c")).containsExactly("a", "b").inOrder();
}
代码示例来源:origin: google/guava
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());
}
代码示例来源:origin: google/guava
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());
}
代码示例来源:origin: google/guava
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());
}
代码示例来源:origin: google/guava
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());
}
内容来源于网络,如有侵权,请联系作者删除!