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


Java NavigableSet.tailSet方法代码示例

本文整理汇总了Java中java.util.NavigableSet.tailSet方法的典型用法代码示例。如果您正苦于以下问题:Java NavigableSet.tailSet方法的具体用法?Java NavigableSet.tailSet怎么用?Java NavigableSet.tailSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.NavigableSet的用法示例。


在下文中一共展示了NavigableSet.tailSet方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: testTailSetRanges

import java.util.NavigableSet; //导入方法依赖的package包/类
@Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class)
public void testTailSetRanges(String description, NavigableSet navigableSet) {
    NavigableSet subSet = navigableSet.tailSet(BigInteger.ONE, true);

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

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

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

    // much smaller
    subSet.tailSet(isDescending(subSet) ? BigInteger.ZERO : BigInteger.TEN, false);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:EmptyNavigableSet.java

示例4: testTailSet

import java.util.NavigableSet; //导入方法依赖的package包/类
/**
 * Tests the tailSet() method.
 */
@Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class)
public void testTailSet(String description, NavigableSet navigableSet) {
    assertThrows(() -> {
        navigableSet.tailSet(null);
    },
        NullPointerException.class,
        description + ": Must throw NullPointerException for null element");

    assertThrows(() -> {
        navigableSet.tailSet(new Object());
    }, ClassCastException.class);

    NavigableSet ss = navigableSet.tailSet("1", true);

    assertEmptyNavigableSet(ss, description + ": Returned value is not empty navigable set.");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:EmptyNavigableSet.java

示例5: testTailSetRanges

import java.util.NavigableSet; //导入方法依赖的package包/类
@Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class)
public void testTailSetRanges(String description, NavigableSet navigableSet) {
    NavigableSet subSet = navigableSet.tailSet(BigInteger.ONE, true);

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

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

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

    // much smaller
    subSet.tailSet(isDescending(subSet) ? BigInteger.ZERO : BigInteger.TEN, false);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:EmptyNavigableSet.java

示例6: testTailSet

import java.util.NavigableSet; //导入方法依赖的package包/类
/**
 * Tests the tailSet() method.
 */
@Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class)
public void testTailSet(String description, NavigableSet navigableSet) {
    assertThrowsNPE(() -> {
        navigableSet.tailSet(null);
    },
        description + ": Must throw NullPointerException for null element");

    assertThrowsCCE(() -> {
        navigableSet.tailSet(new Object());
    }, description);

    NavigableSet ss = navigableSet.tailSet("1", true);

    assertEmptyNavigableSet(ss, description + ": Returned value is not empty navigable set.");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:EmptyNavigableSet.java

示例7: testTailSetContents

import java.util.NavigableSet; //导入方法依赖的package包/类
/**
 * tailSet returns set with keys in requested range
 */
public void testTailSetContents() {
    NavigableSet set = set5();
    SortedSet sm = set.tailSet(two);
    assertFalse(sm.contains(one));
    assertTrue(sm.contains(two));
    assertTrue(sm.contains(three));
    assertTrue(sm.contains(four));
    assertTrue(sm.contains(five));
    Iterator i = sm.iterator();
    Object k;
    k = (Integer)(i.next());
    assertEquals(two, k);
    k = (Integer)(i.next());
    assertEquals(three, k);
    k = (Integer)(i.next());
    assertEquals(four, k);
    k = (Integer)(i.next());
    assertEquals(five, k);
    assertFalse(i.hasNext());

    SortedSet ssm = sm.tailSet(four);
    assertEquals(four, ssm.first());
    assertEquals(five, ssm.last());
    assertTrue(ssm.remove(four));
    assertEquals(1, ssm.size());
    assertEquals(3, sm.size());
    assertEquals(4, set.size());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:TreeSubSetTest.java

示例8: testDescendingTailSetContents

import java.util.NavigableSet; //导入方法依赖的package包/类
/**
 * tailSet returns set with keys in requested range
 */
public void testDescendingTailSetContents() {
    NavigableSet set = dset5();
    SortedSet sm = set.tailSet(m2);
    assertFalse(sm.contains(m1));
    assertTrue(sm.contains(m2));
    assertTrue(sm.contains(m3));
    assertTrue(sm.contains(m4));
    assertTrue(sm.contains(m5));
    Iterator i = sm.iterator();
    Object k;
    k = (Integer)(i.next());
    assertEquals(m2, k);
    k = (Integer)(i.next());
    assertEquals(m3, k);
    k = (Integer)(i.next());
    assertEquals(m4, k);
    k = (Integer)(i.next());
    assertEquals(m5, k);
    assertFalse(i.hasNext());

    SortedSet ssm = sm.tailSet(m4);
    assertEquals(m4, ssm.first());
    assertEquals(m5, ssm.last());
    assertTrue(ssm.remove(m4));
    assertEquals(1, ssm.size());
    assertEquals(3, sm.size());
    assertEquals(4, set.size());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:TreeSubSetTest.java

示例9: getNextRow

import java.util.NavigableSet; //导入方法依赖的package包/类
private Cell getNextRow(final Cell key,
    final NavigableSet<Cell> set) {
  Cell result = null;
  SortedSet<Cell> tail = key == null? set: set.tailSet(key);
  // Iterate until we fall into the next row; i.e. move off current row
  for (Cell cell: tail) {
    if (comparator.compareRows(cell, key) <= 0)
      continue;
    // Note: Not suppressing deletes or expired cells.  Needs to be handled
    // by higher up functions.
    result = cell;
    break;
  }
  return result;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:16,代码来源:DefaultMemStore.java

示例10: testTailSet_E

import java.util.NavigableSet; //导入方法依赖的package包/类
public void testTailSet_E() {
  NavigableSet<String> set = create();
  SortedSet<String> tailSet = set.tailSet("a");
  assertTrue(tailSet instanceof SynchronizedSortedSet);
  assertSame(set, ((SynchronizedSortedSet<String>) tailSet).mutex);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:7,代码来源:SynchronizedNavigableSetTest.java

示例11: testTailSet_E_B

import java.util.NavigableSet; //导入方法依赖的package包/类
public void testTailSet_E_B() {
  NavigableSet<String> set = create();
  NavigableSet<String> tailSet = set.tailSet("a", true);
  assertTrue(tailSet instanceof SynchronizedNavigableSet);
  assertSame(set, ((SynchronizedNavigableSet<String>) tailSet).mutex);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:7,代码来源:SynchronizedNavigableSetTest.java


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