java.util.NavigableSet Java Examples

The following examples show how to use java.util.NavigableSet. 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: SCMContainerManager.java    From hadoop-ozone with 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
Source File: TreeSetTest.java    From openjdk-jdk9 with 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 #3
Source File: ConcurrentSkipListSubSetJUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
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 #4
Source File: SingularNavigableSet2.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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 #5
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 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 #6
Source File: MeterBuilder.java    From skywalking with 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 #7
Source File: ExecutableDao.java    From kylin with 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 #8
Source File: ConcurrentSkipListSubSetTest.java    From j2objc with 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 #9
Source File: BTreeMapSubSetTest.java    From scava with 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 #10
Source File: IndexSegmentTest.java    From ambry with 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 #11
Source File: TreeSetTest.java    From openjdk-jdk9 with 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 #12
Source File: DefaultResultToSolrMapperTest.java    From hbase-indexer with Apache License 2.0 6 votes vote down vote up
@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 #13
Source File: ConcurrentSkipListSubSetTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * toArray(a) contains all elements in sorted order
 */
public void testToArray2() {
    NavigableSet<Integer> q = populatedSet(SIZE);
    Integer[] ints = new Integer[SIZE];
    Integer[] array = q.toArray(ints);
    assertSame(ints, array);
    for (int i = 0; i < ints.length; i++)
        assertSame(ints[i], q.pollFirst());
}
 
Example #14
Source File: ConcurrentSkipListSubSetTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * remove(x) removes x and returns true if present
 */
public void testDescendingRemoveElement() {
    NavigableSet q = populatedSet(SIZE);
    for (int i = 1; i < SIZE; i += 2) {
        assertTrue(q.remove(new Integer(i)));
    }
    for (int i = 0; i < SIZE; i += 2 ) {
        assertTrue(q.remove(new Integer(i)));
        assertFalse(q.remove(new Integer(i + 1)));
    }
    assertTrue(q.isEmpty());
}
 
Example #15
Source File: ConcurrentSkipListSubSetTest.java    From openjdk-jdk9 with GNU General Public License v2.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;
}
 
Example #16
Source File: InMemoryTimerInternals.java    From beam with 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 #17
Source File: TreeSubSetTest.java    From j2objc with 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 #18
Source File: BTreeSet2Test.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * addAll of a collection with null elements throws NPE
 */
public void testAddAll2() {
    try {
        NavigableSet q = newNavigableSet();
        Integer[] ints = new Integer[SIZE];
        q.addAll(Arrays.asList(ints));
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
Example #19
Source File: TreeSubSetTest.java    From j2objc with 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 #20
Source File: ReversedMobStoreScanner.java    From hbase with 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 #21
Source File: TransactionProcessor.java    From phoenix-tephra with 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 File: TreeSubSetTest.java    From openjdk-jdk9 with 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
Source File: ConcurrentSkipListSubSetTest.java    From j2objc with 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;
}
 
Example #24
Source File: ConcurrentSkipListSubSetJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * add(null) throws NPE
 */
public void testDescendingAddNull() {
    try {
        NavigableSet q = dset0();
        q.add(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
Example #25
Source File: ConcurrentSkipListSubSetTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #26
Source File: EmptyNavigableSet.java    From jdk8u-jdk with 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 #27
Source File: Synchronized.java    From codebuff with 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 #28
Source File: TreeMultimap.java    From codebuff with 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
Source File: Sets.java    From codebuff with 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 #30
Source File: ConcurrentSkipListSet.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * @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));
}