當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。