Java Code Examples for java.util.NavigableSet

The following examples show how to use java.util.NavigableSet. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: hadoop-ozone   Source File: SCMContainerManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns the container ID's matching with specified owner.
 * @param pipeline
 * @param owner
 * @return NavigableSet<ContainerID>
 */
private NavigableSet<ContainerID> getContainersForOwner(
    Pipeline pipeline, String owner) throws IOException {
  NavigableSet<ContainerID> containerIDs =
      pipelineManager.getContainersInPipeline(pipeline.getId());
  Iterator<ContainerID> containerIDIterator = containerIDs.iterator();
  while (containerIDIterator.hasNext()) {
    ContainerID cid = containerIDIterator.next();
    try {
      if (!getContainer(cid).getOwner().equals(owner)) {
        containerIDIterator.remove();
      }
    } catch (ContainerNotFoundException e) {
      LOG.error("Could not find container info for container id={} {}", cid,
          e);
      containerIDIterator.remove();
    }
  }
  return containerIDs;
}
 
Example 2
@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);
}
 
Example 3
@java.lang.SuppressWarnings("all")
@javax.annotation.Generated("lombok")
public SingularNavigableSet2<T> build() {
	java.util.NavigableSet<java.lang.Object> rawTypes = new java.util.TreeSet<java.lang.Object>();
	if (this.rawTypes != null) rawTypes.addAll(this.rawTypes);
	rawTypes = java.util.Collections.unmodifiableNavigableSet(rawTypes);
	java.util.NavigableSet<Integer> integers = new java.util.TreeSet<Integer>();
	if (this.integers != null) integers.addAll(this.integers);
	integers = java.util.Collections.unmodifiableNavigableSet(integers);
	java.util.NavigableSet<T> generics = new java.util.TreeSet<T>();
	if (this.generics != null) generics.addAll(this.generics);
	generics = java.util.Collections.unmodifiableNavigableSet(generics);
	java.util.NavigableSet<Number> extendsGenerics = new java.util.TreeSet<Number>();
	if (this.extendsGenerics != null) extendsGenerics.addAll(this.extendsGenerics);
	extendsGenerics = java.util.Collections.unmodifiableNavigableSet(extendsGenerics);
	return new SingularNavigableSet2<T>(rawTypes, integers, generics, extendsGenerics);
}
 
Example 4
public void testSubSetContents2() {
    NavigableSet set = set5();
    SortedSet sm = set.subSet(two, three);
    assertEquals(1, sm.size());
    assertEquals(two, sm.first());
    assertEquals(two, sm.last());
    assertFalse(sm.contains(one));
    assertTrue(sm.contains(two));
    assertFalse(sm.contains(three));
    assertFalse(sm.contains(four));
    assertFalse(sm.contains(five));
    Iterator i = sm.iterator();
    Object k;
    k = (Integer)(i.next());
    assertEquals(two, k);
    assertFalse(i.hasNext());
    Iterator j = sm.iterator();
    j.next();
    j.remove();
    assertFalse(set.contains(two));
    assertEquals(4, set.size());
    assertEquals(0, sm.size());
    assertTrue(sm.isEmpty());
    assertFalse(sm.remove(three));
    assertEquals(4, set.size());
}
 
Example 5
Source Project: kylin   Source File: ExecutableDao.java    License: Apache License 2.0 6 votes vote down vote up
public List<String> getJobIds() throws PersistentException {
    try {
        NavigableSet<String> resources = store.listResources(ResourceStore.EXECUTE_RESOURCE_ROOT);
        if (resources == null) {
            return Collections.emptyList();
        }
        ArrayList<String> result = Lists.newArrayListWithExpectedSize(resources.size());
        for (String path : resources) {
            result.add(path.substring(path.lastIndexOf("/") + 1));
        }
        return result;
    } catch (IOException e) {
        logger.error("error get all Jobs:", e);
        throw new PersistentException(e);
    }
}
 
Example 6
Source Project: ambry   Source File: IndexSegmentTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Gets some IDs for ttl update. Picks the first half of ids from {@code referenceIndex} and also randomly generates
 * {@code outOfSegmentIdCount} ids.
 * @param referenceIndex the index entries to pick for ttl update from.
 * @param outOfSegmentIdCount the number of ids to be generated that are not in {@code referenceIndex}.
 * @return a {@link Set} of IDs to create ttl update entries for.
 */
private Set<MockId> getIdsToTtlUpdate(NavigableMap<MockId, NavigableSet<IndexValue>> referenceIndex,
    int outOfSegmentIdCount) {
  Set<MockId> idsToTtlUpdate = new HashSet<>();
  // return the first half of ids in the map
  int needed = referenceIndex.size() / 2;
  int current = 0;
  for (MockId id : referenceIndex.keySet()) {
    if (current >= needed) {
      break;
    }
    idsToTtlUpdate.add(id);
    current++;
  }
  // generate some ids for ttl update
  idsToTtlUpdate.addAll(generateIds(referenceIndex, outOfSegmentIdCount));
  return idsToTtlUpdate;
}
 
Example 7
Source Project: scava   Source File: BTreeMapSubSetTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Returns a new set of given size containing consecutive
 * Integers 0 ... n.
 */
private NavigableSet<Integer> populatedSet(int n) {
    NavigableSet<Integer> q =
        newNavigableSet();
    assertTrue(q.isEmpty());

    for (int i = n-1; i >= 0; i-=2)
        assertTrue(q.add(new Integer(i)));
    for (int i = (n & 1); i < n; i+=2)
        assertTrue(q.add(new Integer(i)));
    assertTrue(q.add(new Integer(-n)));
    assertTrue(q.add(new Integer(n)));
    NavigableSet s = q.subSet(new Integer(0), true, new Integer(n), false);
    assertFalse(s.isEmpty());
    assertEquals(n, s.size());
    return s;
}
 
Example 8
Source Project: openjdk-jdk9   Source File: TreeSetTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Subsets of subsets subdivide correctly
 */
public void testRecursiveSubSets() throws Exception {
    int setSize = expensiveTests ? 1000 : 100;
    Class cl = TreeSet.class;

    NavigableSet<Integer> set = newSet(cl);
    bs = new BitSet(setSize);

    populate(set, setSize);
    check(set,                 0, setSize - 1, true);
    check(set.descendingSet(), 0, setSize - 1, false);

    mutateSet(set, 0, setSize - 1);
    check(set,                 0, setSize - 1, true);
    check(set.descendingSet(), 0, setSize - 1, false);

    bashSubSet(set.subSet(0, true, setSize, false),
               0, setSize - 1, true);
}
 
Example 9
@Test
public void testGetGet_SingleCellFieldDefinition() {
    FieldDefinition fieldDef = new FieldDefinition("fieldname", "cf:qualifier", ValueSource.VALUE, "int");
    
    DefaultResultToSolrMapper resultMapper = new DefaultResultToSolrMapper("index-name", Lists.newArrayList(fieldDef),
                    Collections.<DocumentExtractDefinition>emptyList());
    Get get = resultMapper.getGet(ROW);
    
    assertArrayEquals(ROW, get.getRow());
    assertEquals(1, get.getFamilyMap().size());
    
    assertTrue(get.getFamilyMap().containsKey(Bytes.toBytes("cf")));
    NavigableSet<byte[]> qualifiers = get.getFamilyMap().get(Bytes.toBytes("cf"));
    assertEquals(1, qualifiers.size());
    assertTrue(qualifiers.contains(Bytes.toBytes("qualifier")));
}
 
Example 10
Source Project: j2objc   Source File: ConcurrentSkipListSubSetTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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());
}
 
Example 11
Source Project: skywalking   Source File: MeterBuilder.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Build the histogram
 * @return return histogram if support
 */
public static Optional<Histogram> buildHistogram(MeterId meterId, boolean supportsAggregablePercentiles,
                                                 DistributionStatisticConfig distributionStatisticConfig,
                                                 boolean useNanoTime) {
    if (!distributionStatisticConfig.isPublishingHistogram()) {
        return Optional.empty();
    }

    final NavigableSet<Double> buckets = distributionStatisticConfig.getHistogramBuckets(supportsAggregablePercentiles);
    final List<Double> steps = buckets.stream().sorted(Double::compare)
        .map(t -> useNanoTime ? TimeUtils.nanosToUnit(t, TimeUnit.MILLISECONDS) : t).collect(Collectors.toList());

    final Histogram.Builder histogramBuilder = MeterFactory.histogram(
        meterId.copyTo(meterId.getName() + "_histogram", MeterId.MeterType.HISTOGRAM)).steps(steps);
    final Double minimumExpectedValueAsDouble = distributionStatisticConfig.getMinimumExpectedValueAsDouble();
    if (minimumExpectedValueAsDouble != null) {
        histogramBuilder.minValue(useNanoTime ?
            TimeUtils.nanosToUnit(minimumExpectedValueAsDouble, TimeUnit.MILLISECONDS) : minimumExpectedValueAsDouble);
    }
    return Optional.of(histogramBuilder.build());
}
 
Example 12
Source Project: openjdk-jdk9   Source File: TreeSetTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
void mutateSet(NavigableSet<Integer> set, int min, int max) {
    int size = set.size();
    int rangeSize = max - min + 1;

    // Remove a bunch of entries directly
    for (int i = 0, n = rangeSize / 2; i < n; i++) {
        remove(set, min - 5 + rnd.nextInt(rangeSize + 10));
    }

    // Remove a bunch of entries with iterator
    for (Iterator<Integer> it = set.iterator(); it.hasNext(); ) {
        if (rnd.nextBoolean()) {
            bs.clear(it.next());
            it.remove();
        }
    }

    // Add entries till we're back to original size
    while (set.size() < size) {
        int element = min + rnd.nextInt(rangeSize);
        assertTrue(element >= min && element <= max);
        put(set, element);
    }
}
 
Example 13
Source Project: hbase   Source File: ReversedMobStoreScanner.java    License: Apache License 2.0 5 votes vote down vote up
ReversedMobStoreScanner(HStore store, ScanInfo scanInfo, Scan scan, NavigableSet<byte[]> columns,
    long readPt) throws IOException {
  super(store, scanInfo, scan, columns, readPt);
  cacheMobBlocks = MobUtils.isCacheMobBlocks(scan);
  rawMobScan = MobUtils.isRawMobScan(scan);
  readEmptyValueOnMobCellMiss = MobUtils.isReadEmptyValueOnMobCellMiss(scan);
  if (!(store instanceof HMobStore)) {
    throw new IllegalArgumentException("The store " + store + " is not a HMobStore");
  }
  mobStore = (HMobStore) store;
  this.referencedMobCells = new ArrayList<>();
}
 
Example 14
/**
 * isEmpty is true before add, false after
 */
public void testEmpty() {
    NavigableSet q = set0();
    assertTrue(q.isEmpty());
    q.add(new Integer(1));
    assertFalse(q.isEmpty());
    q.add(new Integer(2));
    q.pollFirst();
    q.pollFirst();
    assertTrue(q.isEmpty());
}
 
Example 15
private NavigableSet<KafkaAssignerDiskUsageDistributionGoal.ReplicaWrapper> sortedReplicaAscend(Broker broker) {
  NavigableSet<KafkaAssignerDiskUsageDistributionGoal.ReplicaWrapper> sortedReplicas = new TreeSet<>();
  for (Replica r : broker.replicas()) {
    sortedReplicas.add(new KafkaAssignerDiskUsageDistributionGoal.ReplicaWrapper(r, r.load().expectedUtilizationFor(DISK)));
  }
  return sortedReplicas;
}
 
Example 16
Source Project: j2objc   Source File: TreeSubSetTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * addAll of a collection with null elements throws NPE
 */
public void testDescendingAddAll2() {
    NavigableSet q = dset0();
    Integer[] ints = new Integer[SIZE];
    try {
        q.addAll(Arrays.asList(ints));
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
Example 17
Source Project: j2objc   Source File: TreeSubSetTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * addAll(null) throws NPE
 */
public void testAddAll1() {
    NavigableSet q = set0();
    try {
        q.addAll(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
Example 18
Source Project: j2objc   Source File: ConcurrentSkipListSubSetTest.java    License: Apache License 2.0 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 19
Source Project: beam   Source File: InMemoryTimerInternals.java    License: Apache License 2.0 5 votes vote down vote up
private NavigableSet<TimerData> timersForDomain(TimeDomain domain) {
  switch (domain) {
    case EVENT_TIME:
      return watermarkTimers;
    case PROCESSING_TIME:
      return processingTimers;
    case SYNCHRONIZED_PROCESSING_TIME:
      return synchronizedProcessingTimers;
    default:
      throw new IllegalArgumentException("Unexpected time domain: " + domain);
  }
}
 
Example 20
Source Project: j2objc   Source File: TreeSubSetTest.java    License: Apache License 2.0 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 21
Source Project: phoenix-tephra   Source File: TransactionProcessor.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Ensures that family delete markers are present in the columns requested for any get operation.
 * @param get The original get request
 * @return The modified get request with the family delete qualifiers represented
 */
private Get projectFamilyDeletes(Get get) {
  for (Map.Entry<byte[], NavigableSet<byte[]>> entry : get.getFamilyMap().entrySet()) {
    NavigableSet<byte[]> columns = entry.getValue();
    // wildcard scans will automatically include the delete marker, so only need to add it when we have
    // explicit columns listed
    if (columns != null && !columns.isEmpty()) {
      get.addColumn(entry.getKey(), TxConstants.FAMILY_DELETE_QUALIFIER);
    }
  }
  return get;
}
 
Example 22
Source Project: openjdk-jdk9   Source File: TreeSubSetTest.java    License: GNU General Public License v2.0 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());
    assertTrue(q.add(new Integer(1)));
    assertFalse(q.isEmpty());
    q.clear();
    assertTrue(q.isEmpty());
}
 
Example 23
/**
 * lower returns preceding element
 */
public void testLower() {
    NavigableSet q = set5();
    Object e1 = q.lower(three);
    assertEquals(two, e1);

    Object e2 = q.lower(six);
    assertEquals(five, e2);

    Object e3 = q.lower(one);
    assertNull(e3);

    Object e4 = q.lower(zero);
    assertNull(e4);
}
 
Example 24
Source Project: jdk8u-jdk   Source File: EmptyNavigableSet.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests that contains requires Comparable
 */
@Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class)
public void testContainsRequiresComparable(String description, NavigableSet<?> navigableSet) {
    assertThrows(() -> {
        navigableSet.contains(new Object());
    },
        ClassCastException.class,
        description + ": Compareable should be required");
}
 
Example 25
Source Project: codebuff   Source File: Synchronized.java    License: BSD 2-Clause "Simplified" License 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 26
Source Project: codebuff   Source File: Sets.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public NavigableSet<E> descendingSet() {
  UnmodifiableNavigableSet<E> result = descendingSet;
  if (result == null) {
    result = descendingSet = new UnmodifiableNavigableSet<E>(delegate.descendingSet());
    result.descendingSet = this;
  }
  return result;
}
 
Example 27
/**
 * @throws ClassCastException {@inheritDoc}
 * @throws NullPointerException if {@code fromElement} or
 *         {@code toElement} is null
 * @throws IllegalArgumentException {@inheritDoc}
 */
public NavigableSet<E> subSet(E fromElement,
                              boolean fromInclusive,
                              E toElement,
                              boolean toInclusive) {
    return new ConcurrentSkipListSet<E>
        (m.subMap(fromElement, fromInclusive,
                  toElement,   toInclusive));
}
 
Example 28
Source Project: codebuff   Source File: TreeMultimap.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * @since 14.0 (present with return type {@code SortedSet} since 2.0)
 */

@Override
@GwtIncompatible // NavigableSet
public NavigableSet<V> get(@Nullable K key) {
  return (NavigableSet<V>) super.get(key);
}
 
Example 29
/**
 * add(null) throws NPE
 */
public void testDescendingAddNull() {
    try {
        NavigableSet q = dset0();
        q.add(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
Example 30
Source Project: j2objc   Source File: ConcurrentSkipListSubSetTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new set of first 5 ints.
 */
private NavigableSet set5() {
    ConcurrentSkipListSet q = new ConcurrentSkipListSet();
    assertTrue(q.isEmpty());
    q.add(one);
    q.add(two);
    q.add(three);
    q.add(four);
    q.add(five);
    q.add(zero);
    q.add(seven);
    NavigableSet s = q.subSet(one, true, seven, false);
    assertEquals(5, s.size());
    return s;
}