Java Code Examples for java.util.NavigableSet#tailSet()

The following examples show how to use java.util.NavigableSet#tailSet() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EmptyNavigableSet.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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.");
}
 
Example 2
Source File: Tabulator.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected SpanInfo<Column> getColumnCellSpan(NavigableSet<Column> columns, Column column, Row row, Cell cell)
{
	int span = 1;
	Column lastCol = column;
	for (Column tailCol : columns.tailSet(column, false))
	{
		Cell tailCell = row.getCell(tailCol);
		if (tailCell == null || !cell.accept(spanCheck, tailCell))
		{
			break;
		}
		++span;
		lastCol = tailCol;
	}
	return new SpanInfo<Column>(span, lastCol);
}
 
Example 3
Source File: EmptyNavigableSet.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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.");
}
 
Example 4
Source File: EmptyNavigableSet.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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.");
}
 
Example 5
Source File: InMemoryQueueDAO.java    From emodb with Apache License 2.0 6 votes vote down vote up
@Override
public Iterator<ByteBuffer> scanRecords(UUID dataId, @Nullable ByteBuffer from, @Nullable ByteBuffer to,
                                        int batchSize, int limit) {
    NavigableSet<ByteBuffer> segments = _records.get(dataId);
    if (segments == null) {
        return Iterators.emptyIterator();
    }

    if (from != null) {
        segments = segments.tailSet(from, true);
    }
    if (to != null) {
        segments = segments.headSet(to, false);
    }
    return ImmutableList.copyOf(Iterators.limit(segments.iterator(), limit)).iterator();
}
 
Example 6
Source File: EmptyNavigableSet.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@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);
}
 
Example 7
Source File: EmptyNavigableSet.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
@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);
}
 
Example 8
Source File: Sets.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * 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);
}
 
Example 9
Source File: EmptyNavigableSet.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@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);
}
 
Example 10
Source File: Sets.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * 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);
}
 
Example 11
Source File: Sets.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * 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);
}
 
Example 12
Source File: EmptyNavigableSet.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@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);
}
 
Example 13
Source File: TreeSubSetTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * 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());
}
 
Example 14
Source File: ConcurrentSkipListSubSetTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * 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());
}
 
Example 15
Source File: TreeSubSetTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * 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());
}
 
Example 16
Source File: ContainerStateManager.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
/**
 * Return a container matching the attributes specified.
 *
 * @param size         - Space needed in the Container.
 * @param owner        - Owner of the container - A specific nameservice.
 * @param pipelineID   - ID of the pipeline
 * @param containerIDs - Set of containerIDs to choose from
 * @return ContainerInfo, null if there is no match found.
 */
ContainerInfo getMatchingContainer(final long size, String owner,
    PipelineID pipelineID, NavigableSet<ContainerID> containerIDs) {
  if (containerIDs.isEmpty()) {
    return null;
  }

  // Get the last used container and find container above the last used
  // container ID.
  final ContainerState key = new ContainerState(owner, pipelineID);
  final ContainerID lastID =
      lastUsedMap.getOrDefault(key, containerIDs.first());

  // There is a small issue here. The first time, we will skip the first
  // container. But in most cases it will not matter.
  NavigableSet<ContainerID> resultSet = containerIDs.tailSet(lastID, false);
  if (resultSet.size() == 0) {
    resultSet = containerIDs;
  }

  ContainerInfo selectedContainer =
      findContainerWithSpace(size, resultSet, owner, pipelineID);
  if (selectedContainer == null) {

    // If we did not find any space in the tailSet, we need to look for
    // space in the headset, we need to pass true to deal with the
    // situation that we have a lone container that has space. That is we
    // ignored the last used container under the assumption we can find
    // other containers with space, but if have a single container that is
    // not true. Hence we need to include the last used container as the
    // last element in the sorted set.

    resultSet = containerIDs.headSet(lastID, true);
    selectedContainer =
        findContainerWithSpace(size, resultSet, owner, pipelineID);
  }

  return selectedContainer;
}
 
Example 17
Source File: BTreeMapSubSetTest.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * 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());
}
 
Example 18
Source File: ConcurrentSkipListSubSetTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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());
}
 
Example 19
Source File: ConcurrentSkipListSubSetJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * 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());
}
 
Example 20
Source File: InMemoryBackend.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
private static Iterable<@NonNull ITmfStateInterval> searchforEndTime(NavigableSet<@NonNull ITmfStateInterval> tree, int quark, long time) {
    ITmfStateInterval dummyInterval = new TmfStateInterval(-1, time, quark, (Object) null);
    return tree.tailSet(dummyInterval);
}