当前位置: 首页>>代码示例>>Java>>正文


Java SortedSet.subSet方法代码示例

本文整理汇总了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) {
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:18,代码来源:ImmutableSortedSetTest.java

示例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());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:25,代码来源:TreeMultisetTest.java

示例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());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:20,代码来源:TreeMultisetTest.java

示例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());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:20,代码来源:TreeMultisetTest.java

示例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());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:20,代码来源:TreeMultisetTest.java

示例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();
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:15,代码来源:DerivedCollectionGenerators.java

示例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) {
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:15,代码来源:ImmutableSortedSetTest.java

示例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);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:7,代码来源:ImmutableSortedSetTest.java


注:本文中的java.util.SortedSet.subSet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。