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

The following examples show how to use java.util.NavigableSet#higher() . 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: IndexSegmentTest.java    From ambry with Apache License 2.0 6 votes vote down vote up
/**
 * Verifies {@link IndexSegment#find(StoreKey)} to make sure that it returns/does not return values.
 * @param referenceIndex the index entries to be used as reference.
 * @param segment the {@link IndexSegment} to test
 * @throws StoreException
 */
private void verifyFind(NavigableMap<MockId, NavigableSet<IndexValue>> referenceIndex, IndexSegment segment)
    throws StoreException {
  for (Map.Entry<MockId, NavigableSet<IndexValue>> entry : referenceIndex.entrySet()) {
    NavigableSet<IndexValue> referenceValues = entry.getValue();
    NavigableSet<IndexValue> values = segment.find(entry.getKey());
    assertNotNull("Values obtained from segment is null", values);
    IndexValue valueFromSegment = values.first();
    for (IndexValue referenceValue : referenceValues) {
      assertEquals("Offset is not equal", referenceValue.getOffset(), valueFromSegment.getOffset());
      assertEquals("Value is not equal", referenceValue.getBytes(), valueFromSegment.getBytes());
      valueFromSegment = values.higher(valueFromSegment);
    }
    assertNull("There should be no more values in the segment", valueFromSegment);
  }
  // try to find a key that does not exist.
  MockId id = generateIds(referenceIndex, 1).get(0);
  assertNull("Should have failed to find non existent key", segment.find(id));
}
 
Example 2
Source File: MembershipView.java    From rapid with Apache License 2.0 6 votes vote down vote up
/**
 * Computes the set of observers for {@code node}.
 * Only call this from a (thread-)safe place!
 *
 * @param node input node
 * @return the set of observers for {@code node}
 * @throws NodeNotInRingException thrown if {@code node} is not in the ring
 */
private List<Endpoint> computeObserversOf(final Endpoint node) {
    Objects.requireNonNull(node);
    if (!rings.get(0).contains(node)) {
        throw new NodeNotInRingException(node);
    }

    if (rings.get(0).size() <= 1) {
        return Collections.emptyList();
    }

    final List<Endpoint> observers = new ArrayList<>();

    for (int k = 0; k < K; k++) {
        final NavigableSet<Endpoint> list = rings.get(k);
        final Endpoint successor = list.higher(node);
        if (successor == null) {
            observers.add(list.first());
        }
        else {
            observers.add(successor);
        }
    }
    return observers;
}
 
Example 3
Source File: ConcurrentSkipListSubSetJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * higher returns next element
 */
public void testHigher() {
    NavigableSet q = set5();
    Object e1 = q.higher(three);
    assertEquals(four, e1);

    Object e2 = q.higher(zero);
    assertEquals(one, e2);

    Object e3 = q.higher(five);
    assertNull(e3);

    Object e4 = q.higher(six);
    assertNull(e4);
}
 
Example 4
Source File: ConcurrentSkipListSubSetTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * higher returns next element
 */
public void testDescendingHigher() {
    NavigableSet q = dset5();
    Object e1 = q.higher(m3);
    assertEquals(m4, e1);

    Object e2 = q.higher(zero);
    assertEquals(m1, e2);

    Object e3 = q.higher(m5);
    assertNull(e3);

    Object e4 = q.higher(m6);
    assertNull(e4);
}
 
Example 5
Source File: ConcurrentSkipListSubSetTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * higher returns next element
 */
public void testHigher() {
    NavigableSet q = set5();
    Object e1 = q.higher(three);
    assertEquals(four, e1);

    Object e2 = q.higher(zero);
    assertEquals(one, e2);

    Object e3 = q.higher(five);
    assertNull(e3);

    Object e4 = q.higher(six);
    assertNull(e4);
}
 
Example 6
Source File: TreeSubSetTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * higher returns next element
 */
public void testDescendingHigher() {
    NavigableSet q = dset5();
    Object e1 = q.higher(m3);
    assertEquals(m4, e1);

    Object e2 = q.higher(zero);
    assertEquals(m1, e2);

    Object e3 = q.higher(m5);
    assertNull(e3);

    Object e4 = q.higher(m6);
    assertNull(e4);
}
 
Example 7
Source File: TreeSubSetTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * higher returns next element
 */
public void testHigher() {
    NavigableSet q = set5();
    Object e1 = q.higher(three);
    assertEquals(four, e1);

    Object e2 = q.higher(zero);
    assertEquals(one, e2);

    Object e3 = q.higher(five);
    assertNull(e3);

    Object e4 = q.higher(six);
    assertNull(e4);
}
 
Example 8
Source File: StringUtils.java    From rtg-tools with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Expand a name if it is an unambiguous prefix of an entry in the given set of names
 * @param names the reference set of names
 * @param prefix the name prefix
 * @return the input name, or an unambiguous expansion of it
 */
public static String expandPrefix(NavigableSet<String> names, String prefix) {
  String name = prefix;
  if (!names.contains(name)) {
    // Try a search for unambiguous prefix
    final String closest = names.ceiling(prefix);
    if (closest != null && closest.startsWith(prefix)) {
      final String higher = names.higher(closest);
      if (higher == null || !higher.startsWith(prefix)) {
        name = closest;
      }
    }
  }
  return name;
}
 
Example 9
Source File: PopulationVariantGenerator.java    From rtg-tools with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static boolean validPos(PopulationVariant var, NavigableSet<PopulationVariant> set) {
  final int candStart = var.getStart();
  final int candEnd = var.getEnd();
  final PopulationVariant floor = set.floor(var);
  final PopulationVariant higher = set.higher(var);
  if (floor != null && var.getSequenceId() == floor.getSequenceId() && floor.getEnd() > candStart) {
    return false;
  }
  if (higher != null && var.getSequenceId() == higher.getSequenceId() && candEnd > higher.getStart()) {
    return false;
  }
  return true;
}
 
Example 10
Source File: ConcurrentSkipListSubSetJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * higher returns next element
 */
public void testDescendingHigher() {
    NavigableSet q = dset5();
    Object e1 = q.higher(m3);
    assertEquals(m4, e1);

    Object e2 = q.higher(zero);
    assertEquals(m1, e2);

    Object e3 = q.higher(m5);
    assertNull(e3);

    Object e4 = q.higher(m6);
    assertNull(e4);
}
 
Example 11
Source File: TreeSubSetTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * higher returns next element
 */
public void testHigher() {
    NavigableSet q = set5();
    Object e1 = q.higher(three);
    assertEquals(four, e1);

    Object e2 = q.higher(zero);
    assertEquals(one, e2);

    Object e3 = q.higher(five);
    assertNull(e3);

    Object e4 = q.higher(six);
    assertNull(e4);
}
 
Example 12
Source File: ConcurrentSkipListSubSetJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * higher returns next element
 */
public void testDescendingHigher() {
    NavigableSet q = dset5();
    Object e1 = q.higher(m3);
    assertEquals(m4, e1);

    Object e2 = q.higher(zero);
    assertEquals(m1, e2);

    Object e3 = q.higher(m5);
    assertNull(e3);

    Object e4 = q.higher(m6);
    assertNull(e4);
}
 
Example 13
Source File: ConcurrentSkipListSubSetJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * higher returns next element
 */
public void testHigher() {
    NavigableSet q = set5();
    Object e1 = q.higher(three);
    assertEquals(four, e1);

    Object e2 = q.higher(zero);
    assertEquals(one, e2);

    Object e3 = q.higher(five);
    assertNull(e3);

    Object e4 = q.higher(six);
    assertNull(e4);
}
 
Example 14
Source File: BTreeMapSubSetTest.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * higher returns next element
 */
public void testHigher() {
    NavigableSet q = set5();
    Object e1 = q.higher(three);
    assertEquals(four, e1);

    Object e2 = q.higher(zero);
    assertEquals(one, e2);

    Object e3 = q.higher(five);
    assertNull(e3);

    Object e4 = q.higher(six);
    assertNull(e4);
}
 
Example 15
Source File: BTreeSet2Test.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * higher returns next element
 */
public void testHigher() {
    NavigableSet q = set5();
    Object e1 = q.higher(three);
    assertEquals(four, e1);

    Object e2 = q.higher(zero);
    assertEquals(one, e2);

    Object e3 = q.higher(five);
    assertNull(e3);

    Object e4 = q.higher(six);
    assertNull(e4);
}
 
Example 16
Source File: ConcurrentSkipListSubSetTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * higher returns next element
 */
public void testDescendingHigher() {
    NavigableSet q = dset5();
    Object e1 = q.higher(m3);
    assertEquals(m4, e1);

    Object e2 = q.higher(zero);
    assertEquals(m1, e2);

    Object e3 = q.higher(m5);
    assertNull(e3);

    Object e4 = q.higher(m6);
    assertNull(e4);
}
 
Example 17
Source File: ConcurrentSkipListSubSetTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * higher returns next element
 */
public void testHigher() {
    NavigableSet q = set5();
    Object e1 = q.higher(three);
    assertEquals(four, e1);

    Object e2 = q.higher(zero);
    assertEquals(one, e2);

    Object e3 = q.higher(five);
    assertNull(e3);

    Object e4 = q.higher(six);
    assertNull(e4);
}
 
Example 18
Source File: TreeSubSetTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * higher returns next element
 */
public void testDescendingHigher() {
    NavigableSet q = dset5();
    Object e1 = q.higher(m3);
    assertEquals(m4, e1);

    Object e2 = q.higher(zero);
    assertEquals(m1, e2);

    Object e3 = q.higher(m5);
    assertNull(e3);

    Object e4 = q.higher(m6);
    assertNull(e4);
}
 
Example 19
Source File: CuratedLogIndexState.java    From ambry with Apache License 2.0 4 votes vote down vote up
/**
 * Verifies that the state in {@link PersistentIndex} is the same as the one in {@link #referenceIndex}.
 * @param isLogSegmented {@code true} if segmented. {@code false} otherwise.
 * @throws StoreException
 */
private void verifyState(boolean isLogSegmented) throws StoreException {
  verifyRealIndexSanity();
  assertEquals("Incorrect log segment count", isLogSegmented ? 3 : 1, index.getLogSegmentCount());
  NavigableMap<Offset, IndexSegment> realIndex = index.getIndexSegments();
  assertEquals("Number of index segments does not match expected", referenceIndex.size(), realIndex.size());
  Map.Entry<Offset, IndexSegment> realIndexEntry = realIndex.firstEntry();
  for (Map.Entry<Offset, TreeMap<MockId, TreeSet<IndexValue>>> referenceIndexEntry : referenceIndex.entrySet()) {
    assertEquals("Offset of index segment does not match expected", referenceIndexEntry.getKey(),
        realIndexEntry.getKey());
    TreeMap<MockId, TreeSet<IndexValue>> referenceIndexSegment = referenceIndexEntry.getValue();
    IndexSegment realIndexSegment = realIndexEntry.getValue();
    for (Map.Entry<MockId, TreeSet<IndexValue>> referenceIndexSegmentEntry : referenceIndexSegment.entrySet()) {
      MockId id = referenceIndexSegmentEntry.getKey();
      NavigableSet<IndexValue> referenceValues = referenceIndexSegmentEntry.getValue();
      NavigableSet<IndexValue> values = realIndexSegment.find(id);
      assertNotNull("No values returned from real index segment for " + id, values);
      assertTrue("No values returned from real index segment for " + id, values.size() > 0);
      IndexValue value = values.first();
      for (IndexValue referenceValue : referenceValues) {
        assertEquals("Offset does not match", referenceValue.getOffset(), value.getOffset());
        assertEquals("ExpiresAtMs does not match", referenceValue.getExpiresAtMs(), value.getExpiresAtMs());
        assertEquals("Size does not match", referenceValue.getSize(), value.getSize());
        assertEquals("Account ID does not match", referenceValue.getAccountId(), value.getAccountId());
        assertEquals("Container ID does not match", referenceValue.getContainerId(), value.getContainerId());
        assertEquals(
            "Original message offset does not match " + id.toString() + " " + referenceValue + " " + value.toString(),
            referenceValue.getOriginalMessageOffset(), value.getOriginalMessageOffset());
        assertEquals("Flags do not match " + id.toString() + " " + referenceValue.toString() + " " + value.toString(),
            referenceValue.getFlags(), value.getFlags());
        if (index.hardDeleter.enabled.get() && !deletedKeys.contains(referenceIndexSegmentEntry.getKey())) {
          assertEquals("Operation time does not match", referenceValue.getOperationTimeInMs(),
              value.getOperationTimeInMs());
          assertEquals("Value from IndexSegment does not match expected", referenceValue.getBytes(),
              value.getBytes());
        }
        value = values.higher(value);
      }
      assertNull("There are more values in the real index", value);
    }
    realIndexEntry = realIndex.higherEntry(realIndexEntry.getKey());
  }
  assertNull("There should no more index segments left", realIndexEntry);
  // all the elements in the last segment should be in the journal
  assertNotNull("There is no offset in the log that corresponds to the last index segment start offset",
      logOrder.get(referenceIndex.lastKey()));
  Map.Entry<Offset, Pair<MockId, LogEntry>> logEntry = logOrder.floorEntry(referenceIndex.lastKey());
  List<JournalEntry> entries = index.journal.getEntriesSince(referenceIndex.lastKey(), true);
  for (JournalEntry entry : entries) {
    assertNotNull("There are no more entries in the reference log but there are entries in the journal", logEntry);
    assertEquals("Offset in journal not as expected", logEntry.getKey(), entry.getOffset());
    assertEquals("Key in journal not as expected", logEntry.getValue().getFirst(), entry.getKey());
    logEntry = logOrder.higherEntry(logEntry.getKey());
  }
  assertNull("There should be no more entries in the reference log", logEntry);
}