Java Code Examples for java.util.NavigableSet

The following are top voted examples for showing how to use java.util.NavigableSet. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: openjdk-jdk10   File: EmptyNavigableSet.java   View source code 6 votes vote down vote up
@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);
}
 
Example 2
Project: openjdk-jdk10   File: TreeMapTest.java   View source code 6 votes vote down vote up
/**
 * descending iterator of descendingKeySet is ordered
 */
public void testDescendingKeySetDescendingIteratorOrder() {
    TreeMap map = map5();
    NavigableSet s = map.descendingKeySet();
    Iterator i = s.descendingIterator();
    Integer last = (Integer)i.next();
    assertEquals(last, one);
    int count = 1;
    while (i.hasNext()) {
        Integer k = (Integer)i.next();
        assertTrue(last.compareTo(k) < 0);
        last = k;
        ++count;
    }
    assertEquals(5, count);
}
 
Example 3
Project: guava-mock   File: FilteredCollectionsTest.java   View source code 6 votes vote down vote up
public void testNavigableSubSet() {
  for (List<Integer> contents : SAMPLE_INPUTS) {
    for (int i = 0; i < 10; i++) {
      for (int j = i + 1; j < 10; j++) {
        for (boolean fromInclusive : ImmutableList.of(true, false)) {
          for (boolean toInclusive : ImmutableList.of(true, false)) {
            NavigableSet<Integer> filterSubset = filter(
                createUnfiltered(contents).subSet(i, fromInclusive, j, toInclusive), EVEN);
            NavigableSet<Integer> subsetFilter = filter(createUnfiltered(contents), EVEN)
                .subSet(i, fromInclusive, j, toInclusive);
            assertEquals(filterSubset, subsetFilter);
          }
        }
      }
    }
  }
}
 
Example 4
Project: openjdk-jdk10   File: ConcurrentSkipListSubSetTest.java   View source code 6 votes vote down vote up
/**
 * iterator.remove removes current element
 */
public void testIteratorRemove() {
    final NavigableSet q = set0();
    q.add(new Integer(2));
    q.add(new Integer(1));
    q.add(new Integer(3));

    Iterator it = q.iterator();
    it.next();
    it.remove();

    it = q.iterator();
    assertEquals(it.next(), new Integer(2));
    assertEquals(it.next(), new Integer(3));
    assertFalse(it.hasNext());
}
 
Example 5
Project: openjdk-jdk10   File: ConcurrentSkipListSubSetTest.java   View source code 5 votes vote down vote up
/**
 * iterator iterates through all elements
 */
public void testDescendingIterator() {
    NavigableSet q = populatedSet(SIZE);
    int i = 0;
    Iterator it = q.iterator();
    while (it.hasNext()) {
        assertTrue(q.contains(it.next()));
        ++i;
    }
    assertEquals(i, SIZE);
}
 
Example 6
Project: ditb   File: Scan.java   View source code 5 votes vote down vote up
/**
 * Get the column from the specified family with the specified qualifier.
 * <p>
 * Overrides previous calls to addFamily for this family.
 * @param family family name
 * @param qualifier column qualifier
 * @return this
 */
public Scan addColumn(byte [] family, byte [] qualifier) {
  NavigableSet<byte []> set = familyMap.get(family);
  if(set == null) {
    set = new TreeSet<byte []>(Bytes.BYTES_COMPARATOR);
  }
  if (qualifier == null) {
    qualifier = HConstants.EMPTY_BYTE_ARRAY;
  }
  set.add(qualifier);
  familyMap.put(family, set);
  return this;
}
 
Example 7
Project: openjdk-jdk10   File: ConcurrentSkipListSubSetTest.java   View source code 5 votes vote down vote up
/**
 * containsAll(c) is true when c contains a subset of elements
 */
public void testContainsAll() {
    NavigableSet q = populatedSet(SIZE);
    NavigableSet p = set0();
    for (int i = 0; i < SIZE; ++i) {
        assertTrue(q.containsAll(p));
        assertFalse(p.containsAll(q));
        p.add(new Integer(i));
    }
    assertTrue(p.containsAll(q));
}
 
Example 8
Project: guava-mock   File: FilteredCollectionsTest.java   View source code 5 votes vote down vote up
public void testPollFirst() {
  for (List<Integer> contents : SAMPLE_INPUTS) {
    NavigableSet<Integer> filtered = filter(createUnfiltered(contents), EVEN);
    NavigableSet<Integer> unfiltered = createUnfiltered(filtered);

    assertEquals(unfiltered.pollFirst(), filtered.pollFirst());
    assertEquals(unfiltered, filtered);
  }
}
 
Example 9
Project: s-store   File: ForwardingNavigableSet.java   View source code 5 votes vote down vote up
/**
 * A sensible definition of {@link #subSet(Object, boolean, Object, boolean)} in terms of the
 * {@code headSet} and {@code tailSet} methods. In many cases, you may wish to override
 * {@link #subSet(Object, boolean, Object, boolean)} to forward to this implementation.
 */
@Beta
protected NavigableSet<E> standardSubSet(
    E fromElement,
    boolean fromInclusive,
    E toElement,
    boolean toInclusive) {
  return tailSet(fromElement, fromInclusive).headSet(toElement, toInclusive);
}
 
Example 10
Project: Java-9-Cookbook   File: Chapter07Concurrency02.java   View source code 5 votes vote down vote up
private static void demoNavigableSetRemove(NavigableSet<Integer> set) {
    System.out.println("set: " + set);
    try {
        for (int i : set) {
            System.out.println(i);
            System.out.println("Calling set.remove(2)...");
            set.remove(2);
        }
    } catch (Exception ex) {
        System.out.println(ex.getClass().getName());
    }
    System.out.println("set: " + set);
}
 
Example 11
Project: hekate   File: DefaultFailureDetector.java   View source code 5 votes vote down vote up
private void removeMonitors(long limit) {
    Consumer<ClusterAddress> doRemove = node -> {
        if (DEBUG) {
            log.debug("Stopped monitoring [node={}]", node);
        }

        monitors.remove(node);
    };

    NavigableSet<ClusterAddress> allSorted = new TreeSet<>(allNodes);

    // Nodes that are before the local node in the ring.
    List<ClusterAddress> toRemove = allSorted.headSet(localNode, false).stream()
        .filter(monitors::containsKey)
        .limit(limit)
        .collect(toList());

    toRemove.forEach(doRemove);

    long removeMore = limit - toRemove.size();

    if (removeMore > 0) {
        allSorted.tailSet(localNode, false).stream()
            .filter(monitors::containsKey)
            .limit(limit)
            .forEach(doRemove);
    }
}
 
Example 12
Project: microbean-helm   File: TestStreamOrientedChartLoader.java   View source code 5 votes vote down vote up
@Test
public void testToSubchartsDeep() throws IOException {
  final String input = "wordpress/charts/mariadb/charts/frobnicator/templates/foo.yaml";
  final NavigableSet<String> output = StreamOrientedChartLoader.toSubcharts(input);
  assertNotNull(output);
  assertEquals(2, output.size());
  assertEquals("wordpress/charts/mariadb", output.first());
  assertEquals("wordpress/charts/mariadb/charts/frobnicator", output.last());
      
}
 
Example 13
Project: guava-mock   File: SynchronizedNavigableSetTest.java   View source code 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected <E> NavigableSet<E> create() {
  TestSet<E> inner =
      new TestSet<E>(new TreeSet<E>((Comparator<E>) Ordering.natural().nullsFirst()), null);
  NavigableSet<E> outer = Synchronized.navigableSet(inner, null);
  inner.mutex = outer;
  return outer;
}
 
Example 14
Project: sstore-soft   File: Sets.java   View source code 5 votes vote down vote up
@Override
public NavigableSet<E> subSet(
    E fromElement,
    boolean fromInclusive,
    E toElement,
    boolean toInclusive) {
  return unmodifiableNavigableSet(delegate.subSet(
      fromElement,
      fromInclusive,
      toElement,
      toInclusive));
}
 
Example 15
Project: ditb   File: DefaultMemStore.java   View source code 5 votes vote down vote up
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;
}
 
Example 16
Project: openjdk-jdk10   File: TreeSubSetTest.java   View source code 5 votes vote down vote up
/**
 * Add of non-Comparable throws CCE
 */
public void testDescendingAddNonComparable() {
    NavigableSet q = dset0();
    try {
        q.add(new Object());
        q.add(new Object());
        shouldThrow();
    } catch (ClassCastException success) {}
}
 
Example 17
Project: openjdk-jdk10   File: ConcurrentSkipListSubSetTest.java   View source code 5 votes vote down vote up
/**
 * Returns a new set of first 5 negative ints.
 */
private static NavigableSet dset5() {
    ConcurrentSkipListSet q = new ConcurrentSkipListSet();
    assertTrue(q.isEmpty());
    q.add(m1);
    q.add(m2);
    q.add(m3);
    q.add(m4);
    q.add(m5);
    NavigableSet s = q.descendingSet();
    assertEquals(5, s.size());
    return s;
}
 
Example 18
Project: openjdk-jdk10   File: TreeSubSetTest.java   View source code 5 votes vote down vote up
/**
 * toString contains toStrings of elements
 */
public void testDescendingToString() {
    NavigableSet q = populatedSet(SIZE);
    String s = q.toString();
    for (int i = 0; i < SIZE; ++i) {
        assertTrue(s.contains(String.valueOf(i)));
    }
}
 
Example 19
Project: s-store   File: Sets.java   View source code 5 votes vote down vote up
@Override
public NavigableSet<E> subSet(
    E fromElement,
    boolean fromInclusive,
    E toElement,
    boolean toInclusive) {
  return forward.subSet(toElement, toInclusive, fromElement, fromInclusive).descendingSet();
}
 
Example 20
Project: Exoplayer2Radio   File: SimpleCache.java   View source code 5 votes vote down vote up
@Override
public synchronized NavigableSet<CacheSpan> addListener(String key, Listener listener) {
  ArrayList<Listener> listenersForKey = listeners.get(key);
  if (listenersForKey == null) {
    listenersForKey = new ArrayList<>();
    listeners.put(key, listenersForKey);
  }
  listenersForKey.add(listener);
  return getCachedSpans(key);
}
 
Example 21
Project: openjdk-jdk10   File: TreeSubSetTest.java   View source code 5 votes vote down vote up
/**
 * ceiling returns next element
 */
public void testDescendingCeiling() {
    NavigableSet q = dset5();
    Object e1 = q.ceiling(m3);
    assertEquals(m3, e1);

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

    Object e3 = q.ceiling(m5);
    assertEquals(m5, e3);

    Object e4 = q.ceiling(m6);
    assertNull(e4);
}
 
Example 22
Project: googles-monorepo-demo   File: ForwardingNavigableSetTest.java   View source code 5 votes vote down vote up
private static <T> NavigableSet<T> wrap(final NavigableSet<T> delegate) {
  return new ForwardingNavigableSet<T>() {
    @Override protected NavigableSet<T> delegate() {
      return delegate;
    }
  };
}
 
Example 23
Project: sstore-soft   File: Synchronized.java   View source code 5 votes vote down vote up
@Override public NavigableSet<E> descendingSet() {
  synchronized (mutex) {
    if (descendingSet == null) {
      NavigableSet<E> dS =
          Synchronized.navigableSet(delegate().descendingSet(), mutex);
      descendingSet = dS;
      return dS;
    }
    return descendingSet;
  }
}
 
Example 24
Project: ditb   File: BlockCacheUtil.java   View source code 5 votes vote down vote up
/**
 * @param filename
 * @param blocks
 * @return A JSON String of <code>filename</code> and counts of <code>blocks</code>
 * @throws JsonGenerationException
 * @throws JsonMappingException
 * @throws IOException
 */
public static String toJSON(final String filename, final NavigableSet<CachedBlock> blocks)
throws JsonGenerationException, JsonMappingException, IOException {
  CachedBlockCountsPerFile counts = new CachedBlockCountsPerFile(filename);
  for (CachedBlock cb: blocks) {
    counts.count++;
    counts.size += cb.getSize();
    BlockType bt = cb.getBlockType();
    if (bt != null && bt.isData()) {
      counts.countData++;
      counts.sizeData += cb.getSize();
    }
  }
  return MAPPER.writeValueAsString(counts);
}
 
Example 25
Project: openjdk-jdk10   File: ConcurrentSkipListSubSetTest.java   View source code 5 votes vote down vote up
/**
 * clear removes all elements
 */
public void testClear() {
    NavigableSet q = populatedSet(SIZE);
    q.clear();
    assertTrue(q.isEmpty());
    assertEquals(0, q.size());
    q.add(new Integer(1));
    assertFalse(q.isEmpty());
    q.clear();
    assertTrue(q.isEmpty());
}
 
Example 26
Project: openjdk-jdk10   File: ConcurrentSkipListSubSetTest.java   View source code 5 votes vote down vote up
/**
 * add(null) throws NPE
 */
public void testAddNull() {
    NavigableSet q = set0();
    try {
        q.add(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
Example 27
Project: ditb   File: Scan.java   View source code 4 votes vote down vote up
/**
 * Compile the details beyond the scope of getFingerprint (row, columns,
 * timestamps, etc.) into a Map along with the fingerprinted information.
 * Useful for debugging, logging, and administration tools.
 * @param maxCols a limit on the number of columns output prior to truncation
 * @return Map
 */
@Override
public Map<String, Object> toMap(int maxCols) {
  // start with the fingerpring map and build on top of it
  Map<String, Object> map = getFingerprint();
  // map from families to column list replaces fingerprint's list of families
  Map<String, List<String>> familyColumns =
    new HashMap<String, List<String>>();
  map.put("families", familyColumns);
  // add scalar information first
  map.put("startRow", Bytes.toStringBinary(this.startRow));
  map.put("stopRow", Bytes.toStringBinary(this.stopRow));
  map.put("maxVersions", this.maxVersions);
  map.put("batch", this.batch);
  map.put("caching", this.caching);
  map.put("maxResultSize", this.maxResultSize);
  map.put("cacheBlocks", this.cacheBlocks);
  map.put("loadColumnFamiliesOnDemand", this.loadColumnFamiliesOnDemand);
  List<Long> timeRange = new ArrayList<Long>();
  timeRange.add(this.tr.getMin());
  timeRange.add(this.tr.getMax());
  map.put("timeRange", timeRange);
  int colCount = 0;
  // iterate through affected families and list out up to maxCols columns
  for (Map.Entry<byte [], NavigableSet<byte[]>> entry :
    this.familyMap.entrySet()) {
    List<String> columns = new ArrayList<String>();
    familyColumns.put(Bytes.toStringBinary(entry.getKey()), columns);
    if(entry.getValue() == null) {
      colCount++;
      --maxCols;
      columns.add("ALL");
    } else {
      colCount += entry.getValue().size();
      if (maxCols <= 0) {
        continue;
      }
      for (byte [] column : entry.getValue()) {
        if (--maxCols <= 0) {
          continue;
        }
        columns.add(Bytes.toStringBinary(column));
      }
    }
  }
  map.put("totalColumns", colCount);
  if (this.filter != null) {
    map.put("filter", this.filter.toString());
  }
  // add the id if set
  if (getId() != null) {
    map.put("id", getId());
  }
  return map;
}
 
Example 28
Project: OpenJSharp   File: ConcurrentSkipListMap.java   View source code 4 votes vote down vote up
public NavigableSet<K> navigableKeySet() {
    KeySet<K> ks = keySet;
    return (ks != null) ? ks : (keySet = new KeySet<K>(this));
}
 
Example 29
Project: guava-mock   File: Sets.java   View source code 4 votes vote down vote up
DescendingSet(NavigableSet<E> forward) {
  this.forward = forward;
}
 
Example 30
Project: googles-monorepo-demo   File: Sets.java   View source code 4 votes vote down vote up
@Override
public NavigableSet<E> descendingSet() {
  return forward;
}
 
Example 31
Project: guava-mock   File: ForwardingNavigableMapTest.java   View source code 4 votes vote down vote up
@Override
public NavigableSet<K> navigableKeySet() {
  return new StandardNavigableKeySet();
}
 
Example 32
Project: HCFCore   File: AbstractNavigableSetDecorator.java   View source code 4 votes vote down vote up
@Override
public NavigableSet<E> headSet(E toElement, boolean inclusive) {
    return decorated().headSet(toElement, inclusive);
}
 
Example 33
Project: GitHub   File: OrderAttributeValue.java   View source code 4 votes vote down vote up
@Value.ReverseOrder
public abstract NavigableSet<String> reverse();
 
Example 34
Project: GitHub   File: JdkColl.java   View source code 4 votes vote down vote up
@Value.ReverseOrder
NavigableSet<Integer> navs();
 
Example 35
Project: googles-monorepo-demo   File: SynchronizedNavigableSetTest.java   View source code 4 votes vote down vote up
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);
}
 
Example 36
Project: guava-mock   File: Synchronized.java   View source code 4 votes vote down vote up
SynchronizedNavigableSet(NavigableSet<E> delegate, @Nullable Object mutex) {
  super(delegate, mutex);
}
 
Example 37
Project: sstore-soft   File: ForwardingNavigableSet.java   View source code 4 votes vote down vote up
@Override
public NavigableSet<E> descendingSet() {
  return delegate().descendingSet();
}
 
Example 38
Project: s-store   File: AbstractMapBasedMultimap.java   View source code 4 votes vote down vote up
@Override
public NavigableSet<K> keySet() {
  return (NavigableSet<K>) super.keySet();
}
 
Example 39
Project: guava-mock   File: FilteredCollectionsTest.java   View source code 4 votes vote down vote up
@Override
NavigableSet<Integer> filter(
    NavigableSet<Integer> elements, Predicate<? super Integer> predicate) {
  return Sets.filter(elements, predicate);
}
 
Example 40
Project: s-store   File: Sets.java   View source code 4 votes vote down vote up
@Override
public NavigableSet<E> descendingSet() {
  return Sets.filter(unfiltered().descendingSet(), predicate);
}