當前位置: 首頁>>代碼示例>>Java>>正文


Java NavigableSet.headSet方法代碼示例

本文整理匯總了Java中java.util.NavigableSet.headSet方法的典型用法代碼示例。如果您正苦於以下問題:Java NavigableSet.headSet方法的具體用法?Java NavigableSet.headSet怎麽用?Java NavigableSet.headSet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.NavigableSet的用法示例。


在下文中一共展示了NavigableSet.headSet方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: subSet

import java.util.NavigableSet; //導入方法依賴的package包/類
/**
 * Returns a view of the portion of {@code set} whose elements are contained by {@code range}.
 *
 * <p>This method delegates to the appropriate methods of {@link NavigableSet} (namely
 * {@link NavigableSet#subSet(Object, boolean, Object, boolean) subSet()},
 * {@link NavigableSet#tailSet(Object, boolean) tailSet()}, and
 * {@link NavigableSet#headSet(Object, boolean) headSet()}) to actually construct the view.
 * Consult these methods for a full description of the returned view's behavior.
 *
 * <p><b>Warning:</b> {@code Range}s always represent a range of values using the values' natural
 * ordering. {@code NavigableSet} on the other hand can specify a custom ordering via a
 * {@link Comparator}, which can violate the natural ordering. Using this method (or in general
 * using {@code Range}) with unnaturally-ordered sets can lead to unexpected and undefined
 * behavior.
 *
 * @since 20.0
 */
@Beta
@GwtIncompatible // NavigableSet
public static <K extends Comparable<? super K>> NavigableSet<K> subSet(
    NavigableSet<K> set, Range<K> range) {
  if (set.comparator() != null
      && set.comparator() != Ordering.natural()
      && range.hasLowerBound()
      && range.hasUpperBound()) {
    checkArgument(
        set.comparator().compare(range.lowerEndpoint(), range.upperEndpoint()) <= 0,
        "set is using a custom comparator which is inconsistent with the natural ordering.");
  }
  if (range.hasLowerBound() && range.hasUpperBound()) {
    return set.subSet(
        range.lowerEndpoint(),
        range.lowerBoundType() == BoundType.CLOSED,
        range.upperEndpoint(),
        range.upperBoundType() == BoundType.CLOSED);
  } else if (range.hasLowerBound()) {
    return set.tailSet(range.lowerEndpoint(), range.lowerBoundType() == BoundType.CLOSED);
  } else if (range.hasUpperBound()) {
    return set.headSet(range.upperEndpoint(), range.upperBoundType() == BoundType.CLOSED);
  }
  return checkNotNull(set);
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:43,代碼來源:Sets.java

示例2: createSubSet

import java.util.NavigableSet; //導入方法依賴的package包/類
@Override
NavigableSet<E> createSubSet(SortedSet<E> sortedSet, E firstExclusive, E lastExclusive) {
  NavigableSet<E> set = (NavigableSet<E>) sortedSet;
  if (from == Bound.NO_BOUND && to == Bound.INCLUSIVE) {
    return set.headSet(lastInclusive, true);
  } else if (from == Bound.EXCLUSIVE && to == Bound.NO_BOUND) {
    return set.tailSet(firstExclusive, false);
  } else if (from == Bound.EXCLUSIVE && to == Bound.EXCLUSIVE) {
    return set.subSet(firstExclusive, false, lastExclusive, false);
  } else if (from == Bound.EXCLUSIVE && to == Bound.INCLUSIVE) {
    return set.subSet(firstExclusive, false, lastInclusive, true);
  } else if (from == Bound.INCLUSIVE && to == Bound.INCLUSIVE) {
    return set.subSet(firstInclusive, true, lastInclusive, true);
  } else {
    return (NavigableSet<E>) super.createSubSet(set, firstExclusive, lastExclusive);
  }
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:18,代碼來源:NavigableSetTestSuiteBuilder.java

示例3: testheadSetRanges

import java.util.NavigableSet; //導入方法依賴的package包/類
@Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class)
public void testheadSetRanges(String description, NavigableSet navigableSet) {
    NavigableSet subSet = navigableSet.headSet(BigInteger.ONE, true);

    // same subset
    subSet.headSet(BigInteger.ONE, true);

    // slightly smaller
    NavigableSet ns = subSet.headSet(BigInteger.ONE, false);

    // slight exapansion
    assertThrows(() -> {
        ns.headSet(BigInteger.ONE, true);
    },
        IllegalArgumentException.class,
        description + ": Expansion should not be allowed");

    // much smaller
    subSet.headSet(isDescending(subSet) ? BigInteger.TEN : BigInteger.ZERO, true);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:21,代碼來源:EmptyNavigableSet.java

示例4: testheadSetRanges

import java.util.NavigableSet; //導入方法依賴的package包/類
@Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class)
public void testheadSetRanges(String description, NavigableSet navigableSet) {
    NavigableSet subSet = navigableSet.headSet(BigInteger.ONE, true);

    // same subset
    subSet.headSet(BigInteger.ONE, true);

    // slightly smaller
    NavigableSet ns = subSet.headSet(BigInteger.ONE, false);

    // slight expansion
    assertThrowsIAE(() -> {
        ns.headSet(BigInteger.ONE, true);
    },
        description + ": Expansion should not be allowed");

    // much smaller
    subSet.headSet(isDescending(subSet) ? BigInteger.TEN : BigInteger.ZERO, true);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:EmptyNavigableSet.java

示例5: testHeadSetContents

import java.util.NavigableSet; //導入方法依賴的package包/類
/**
 * headSet returns set with keys in requested range
 */
public void testHeadSetContents() {
    NavigableSet set = set5();
    SortedSet sm = set.headSet(four);
    assertTrue(sm.contains(one));
    assertTrue(sm.contains(two));
    assertTrue(sm.contains(three));
    assertFalse(sm.contains(four));
    assertFalse(sm.contains(five));
    Iterator i = sm.iterator();
    Object k;
    k = (Integer)(i.next());
    assertEquals(one, k);
    k = (Integer)(i.next());
    assertEquals(two, k);
    k = (Integer)(i.next());
    assertEquals(three, k);
    assertFalse(i.hasNext());
    sm.clear();
    assertTrue(sm.isEmpty());
    assertEquals(2, set.size());
    assertEquals(four, set.first());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:TreeSubSetTest.java

示例6: testDescendingHeadSetContents

import java.util.NavigableSet; //導入方法依賴的package包/類
/**
 * headSet returns set with keys in requested range
 */
public void testDescendingHeadSetContents() {
    NavigableSet set = dset5();
    SortedSet sm = set.headSet(m4);
    assertTrue(sm.contains(m1));
    assertTrue(sm.contains(m2));
    assertTrue(sm.contains(m3));
    assertFalse(sm.contains(m4));
    assertFalse(sm.contains(m5));
    Iterator i = sm.iterator();
    Object k;
    k = (Integer)(i.next());
    assertEquals(m1, k);
    k = (Integer)(i.next());
    assertEquals(m2, k);
    k = (Integer)(i.next());
    assertEquals(m3, k);
    assertFalse(i.hasNext());
    sm.clear();
    assertTrue(sm.isEmpty());
    assertEquals(2, set.size());
    assertEquals(m4, set.first());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:TreeSubSetTest.java

示例7: memberOfPreviousRow

import java.util.NavigableSet; //導入方法依賴的package包/類
private Member memberOfPreviousRow(NavigableSet<Cell> set,
    final GetClosestRowBeforeTracker state, final Cell firstOnRow) {
  NavigableSet<Cell> head = set.headSet(firstOnRow, false);
  if (head.isEmpty()) return null;
  for (Iterator<Cell> i = head.descendingIterator(); i.hasNext();) {
    Cell found = i.next();
    if (state.isExpired(found)) {
      i.remove();
      continue;
    }
    return new Member(head, found);
  }
  return null;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:15,代碼來源:DefaultMemStore.java

示例8: testHeadSet_E

import java.util.NavigableSet; //導入方法依賴的package包/類
public void testHeadSet_E() {
  NavigableSet<String> set = create();
  SortedSet<String> headSet = set.headSet("a");
  assertTrue(headSet instanceof SynchronizedSortedSet);
  assertSame(set, ((SynchronizedSortedSet<String>) headSet).mutex);
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:7,代碼來源:SynchronizedNavigableSetTest.java

示例9: testHeadSet_E_B

import java.util.NavigableSet; //導入方法依賴的package包/類
public void testHeadSet_E_B() {
  NavigableSet<String> set = create();
  NavigableSet<String> headSet = set.headSet("a", true);
  assertTrue(headSet instanceof SynchronizedNavigableSet);
  assertSame(set, ((SynchronizedNavigableSet<String>) headSet).mutex);
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:7,代碼來源:SynchronizedNavigableSetTest.java


注:本文中的java.util.NavigableSet.headSet方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。