java.util.TreeSet.iterator()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(11.4k)|赞(0)|评价(0)|浏览(95)

本文整理了Java中java.util.TreeSet.iterator()方法的一些代码示例,展示了TreeSet.iterator()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TreeSet.iterator()方法的具体详情如下:
包路径:java.util.TreeSet
类名称:TreeSet
方法名:iterator

TreeSet.iterator介绍

[英]Returns an Iterator on the elements of this TreeSet.
[中]返回此树集元素的迭代器。

代码示例

代码示例来源:origin: Activiti/Activiti

/**
 * Get an enumeration of the keys of the JSONObject. The keys will be sorted alphabetically.
 * 
 * @return An iterator of the keys.
 */
public Iterator sortedKeys() {
 return new TreeSet(this.map.keySet()).iterator();
}

代码示例来源:origin: apache/storm

private Iterator<ObjectResources> getNodeIterator() {
  if (nodeIterator != null && nodeIterator.hasNext()) {
    return nodeIterator;
  }
  //need to get the next node iterator
  if (rackIterator.hasNext()) {
    ObjectResources rack = rackIterator.next();
    final String rackId = rack.id;
    nodeIterator = parent.getSortedNodesFor(rackId).iterator();
    return nodeIterator;
  }
  return null;
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Sorted list of unique max-versions in the data set.  For select list in jelly.
 */
@Restricted(NoExternalUse.class)
public Iterator<VersionNumber> getVersionList() {
  TreeSet<VersionNumber> set = new TreeSet<VersionNumber>();
  for (VersionRange vr : data.values()) {
    if (vr.max != null) {
      set.add(vr.max);
    }
  }
  return set.iterator();
}

代码示例来源:origin: org.apache.commons/commons-math3

/**
   * Returns an array consisting of the unique values in {@code data}.
   * The return array is sorted in descending order.  Empty arrays
   * are allowed, but null arrays result in NullPointerException.
   * Infinities are allowed.  NaN values are allowed with maximum
   * sort order - i.e., if there are NaN values in {@code data},
   * {@code Double.NaN} will be the first element of the output array,
   * even if the array also contains {@code Double.POSITIVE_INFINITY}.
   *
   * @param data array to scan
   * @return descending list of values included in the input array
   * @throws NullPointerException if data is null
   * @since 3.6
   */
  public static double[] unique(double[] data) {
    TreeSet<Double> values = new TreeSet<Double>();
    for (int i = 0; i < data.length; i++) {
      values.add(data[i]);
    }
    final int count = values.size();
    final double[] out = new double[count];
    Iterator<Double> iterator = values.iterator();
    int i = 0;
    while (iterator.hasNext()) {
      out[count - ++i] = iterator.next();
    }
    return out;
  }
}

代码示例来源:origin: geoserver/geoserver

@Test
public void testMixedElevationExtraction() throws IOException {
  MockDimensionReader reader = new MockDimensionReader();
  reader.metadata.put(GridCoverage2DReader.HAS_ELEVATION_DOMAIN, "true");
  reader.metadata.put(GridCoverage2DReader.ELEVATION_DOMAIN, "0/0/0,10,15/20/1");
  ReaderDimensionsAccessor accessor = new ReaderDimensionsAccessor(reader);
  TreeSet<Object> domain = accessor.getElevationDomain();
  assertEquals(3, domain.size());
  Iterator<Object> it = domain.iterator();
  Number firstEntry = (Number) it.next();
  assertEquals(0, firstEntry.doubleValue(), 0d);
  Number secondEntry = (Number) it.next();
  assertEquals(10, secondEntry.doubleValue(), 0d);
  NumberRange thirdEntry = (NumberRange) it.next();
  assertEquals(15, thirdEntry.getMinimum(), 0d);
  assertEquals(20, thirdEntry.getMaximum(), 0d);
}

代码示例来源:origin: lealone/Lealone

@Override
protected boolean isTargetEndpoint(Database db) {
  // boolean isTargetEndpoint = super.isTargetEndpoint(db);
  // if (session.isRoot() && isTargetEndpoint) {
  // return true;
  // }
  TreeSet<String> hostIds = new TreeSet<>(Arrays.asList(db.getHostIds()));
  NetEndpoint localEndpoint = NetEndpoint.getLocalTcpEndpoint();
  if (hostIds.iterator().next().equalsIgnoreCase(localEndpoint.getHostAndPort())) {
    return true;
  } else {
    return false;
  }
}

代码示例来源:origin: wildfly/wildfly

public Key executeAfter(final Runnable command, final long time, final TimeUnit unit) {
  final long millis = unit.toMillis(time);
  if ((state & SHUTDOWN) != 0) {
    throw log.threadExiting();
  }
  if (millis <= 0) {
    execute(command);
    return Key.IMMEDIATE;
  }
  final long deadline = (nanoTime() - START_TIME) + Math.min(millis, LONGEST_DELAY) * 1000000L;
  final TimeKey key = new TimeKey(deadline, command);
  synchronized (workLock) {
    final TreeSet<TimeKey> queue = delayWorkQueue;
    queue.add(key);
    if (queue.iterator().next() == key) {
      // we're the next one up; poke the selector to update its delay time
      if (polling) { // flag is always false if we're the same thread
        selector.wakeup();
      }
    }
    return key;
  }
}

代码示例来源:origin: deeplearning4j/nd4j

public String key(String s, Object... o) {
  if (s == null || o != null && o.length > 0) {
    throw new IllegalArgumentException("Fingerprint keyer accepts a single string parameter");
  }
  s = s.trim(); // first off, remove whitespace around the string
  s = s.toLowerCase(); // then lowercase it
  s = punctctrl.matcher(s).replaceAll(""); // then remove all punctuation and control chars
  String[] frags = StringUtils.split(s); // split by whitespace
  TreeSet<String> set = new TreeSet<>();
  Collections.addAll(set, frags);
  StringBuilder b = new StringBuilder();
  Iterator<String> i = set.iterator();
  while (i.hasNext()) { // join ordered fragments back together
    b.append(i.next());
    if (i.hasNext()) {
      b.append(' ');
    }
  }
  return asciify(b.toString()); // find ASCII equivalent to characters 
}

代码示例来源:origin: apache/incubator-druid

public PartitionChunk<T> getChunk(final int partitionNum)
{
 final Iterator<PartitionChunk<T>> retVal = Iterators.filter(
   holderSet.iterator(),
   input -> input.getChunkNumber() == partitionNum
 );
 return retVal.hasNext() ? retVal.next() : null;
}

代码示例来源:origin: geoserver/geoserver

@Test
public void testMixedTimeExtraction() throws IOException, ParseException {
  MockDimensionReader reader = new MockDimensionReader();
  reader.metadata.put(GridCoverage2DReader.HAS_TIME_DOMAIN, "true");
  reader.metadata.put(
      GridCoverage2DReader.TIME_DOMAIN,
      "2016-02-23T03:00:00.000Z/2016-02-23T03:00:00.000Z/PT1S,2016-02-23T06:00:00.000Z,2016-02-23T09:00:00.000Z/2016-02-23T12:00:00.000Z/PT1S");
  ReaderDimensionsAccessor accessor = new ReaderDimensionsAccessor(reader);
  TreeSet<Object> domain = accessor.getTimeDomain();
  assertEquals(3, domain.size());
  Iterator<Object> it = domain.iterator();
  Date firstEntry = (Date) it.next();
  assertEquals(accessor.getTimeFormat().parse("2016-02-23T03:00:00.000Z"), firstEntry);
  Date secondEntry = (Date) it.next();
  assertEquals(accessor.getTimeFormat().parse("2016-02-23T06:00:00.000Z"), secondEntry);
  DateRange thirdEntry = (DateRange) it.next();
  assertEquals(
      accessor.getTimeFormat().parse("2016-02-23T09:00:00.000Z"),
      thirdEntry.getMinValue());
  assertEquals(
      accessor.getTimeFormat().parse("2016-02-23T12:00:00.000Z"),
      thirdEntry.getMaxValue());
}

代码示例来源:origin: swagger-api/swagger-core

@Test(description = "it should maintain property names")
public void maintainPropertyNames() {
  final Map<String, Schema> schemas = readAll(ModelPropertyName.class);
  assertEquals(schemas.size(), 1);
  final String modelName = schemas.keySet().iterator().next();
  assertEquals(modelName, "ModelPropertyName");
  final Schema model = schemas.get(modelName);
  final Iterator<String> itr = new TreeSet(model.getProperties().keySet()).iterator();
  assertEquals(itr.next(), "gettersAndHaters");
  assertEquals(itr.next(), "is_persistent");
}

代码示例来源:origin: apache/incubator-druid

@JsonCreator
public ArbitraryGranularitySpec(
  @JsonProperty("queryGranularity") Granularity queryGranularity,
  @JsonProperty("rollup") Boolean rollup,
  @JsonProperty("intervals") List<Interval> inputIntervals
)
{
 this.queryGranularity = queryGranularity == null ? Granularities.NONE : queryGranularity;
 this.rollup = rollup == null ? Boolean.TRUE : rollup;
 this.intervals = new TreeSet<>(Comparators.intervalsByStartThenEnd());
 if (inputIntervals == null) {
  inputIntervals = new ArrayList<>();
 }
 // Insert all intervals
 for (final Interval inputInterval : inputIntervals) {
  intervals.add(inputInterval);
 }
 // Ensure intervals are non-overlapping (but they may abut each other)
 final PeekingIterator<Interval> intervalIterator = Iterators.peekingIterator(intervals.iterator());
 while (intervalIterator.hasNext()) {
  final Interval currentInterval = intervalIterator.next();
  if (intervalIterator.hasNext()) {
   final Interval nextInterval = intervalIterator.peek();
   if (currentInterval.overlaps(nextInterval)) {
    throw new IAE("Overlapping intervals: %s, %s", currentInterval, nextInterval);
   }
  }
 }
}

代码示例来源:origin: alibaba/mdrill

/**
 * Get an enumeration of the keys of the JSONObject.
 * The keys will be sorted alphabetically.
 *
 * @return An iterator of the keys.
 */
public Iterator sortedKeys() {
 return new TreeSet(this.map.keySet()).iterator();
}

代码示例来源:origin: apache/incubator-gobblin

/**
 * Finds a list of properties whose keys are complete prefix of other keys. This function is
 * meant to be used during conversion from Properties to typesafe Config as the latter does not
 * support this scenario.
 * @param     properties      the Properties collection to inspect
 * @param     keyPrefix       an optional key prefix which limits which properties are inspected.
 * */
public static Set<String> findFullPrefixKeys(Properties properties,
                       Optional<String> keyPrefix) {
 TreeSet<String> propNames = new TreeSet<>();
 for (Map.Entry<Object, Object> entry : properties.entrySet()) {
  String entryKey = entry.getKey().toString();
  if (StringUtils.startsWith(entryKey, keyPrefix.or(StringUtils.EMPTY))) {
   propNames.add(entryKey);
  }
 }
 Set<String> result = new HashSet<>();
 String lastKey = null;
 Iterator<String> sortedKeysIter = propNames.iterator();
 while(sortedKeysIter.hasNext()) {
  String propName = sortedKeysIter.next();
  if (null != lastKey && propName.startsWith(lastKey + ".")) {
   result.add(lastKey);
  }
  lastKey = propName;
 }
 return result;
}

代码示例来源:origin: FudanNLP/fnlp

public  void printDocSim() {
  Iterator<DocSim> iter = dsMap.iterator();
  while (iter.hasNext()) {
    System.out.println(iter.next().toString());
  }
}

代码示例来源:origin: apache/storm

LOG.info("Sorted Racks {}", sortedRacks);
Assert.assertEquals("# of racks sorted", 6, sortedRacks.size());
Iterator<ObjectResources> it = sortedRacks.iterator();
Assert.assertEquals("rack-0 should be ordered first", "rack-0", it.next().id);
Assert.assertEquals("rack-1 should be ordered second", "rack-1", it.next().id);
Assert.assertEquals("rack-4 should be ordered third", "rack-4", it.next().id);
Assert.assertEquals("rack-3 should be ordered fourth", "rack-3", it.next().id);

代码示例来源:origin: apache/ignite

long vals = rnd.nextLong(size) + 1;
TreeSet<Long> exp = new TreeSet<>();
  exp.add(rnd.nextLong(size) + 1);
checkCursor(tree.find(null, null, new TestTreeFindFilteredClosure(exp), null), exp.iterator());
checkCursor(tree.find(0L, null, new TestTreeFindFilteredClosure(exp), null), exp.iterator());
checkCursor(tree.find(0L, size, new TestTreeFindFilteredClosure(exp), null), exp.iterator());
checkCursor(tree.find(null, size, new TestTreeFindFilteredClosure(exp), null), exp.iterator());

代码示例来源:origin: apache/hive

throw e;
TreeSet<Integer> slots = new TreeSet<>();
int approxWorkerCount = 0;
for (String child : allChildNodes) {
  slots.add(Integer.parseInt(child.substring(prefix.length())));
Iterator<Integer> slotIter = slots.iterator();
slotToTake = 0;
while (slotIter.hasNext()) {
 int nextTaken = slotIter.next();
 if (slotToTake < nextTaken) break;
 slotToTake = nextTaken + 1;

代码示例来源:origin: FudanNLP/fnlp

public  void printDocSim() {
  Iterator<DocSim> iter = dsMap.iterator();
  while (iter.hasNext()) {
    System.out.println(iter.next().toString());
  }
}
AtomicInteger jobs;

代码示例来源:origin: apache/storm

TreeSet<ObjectResources> sortedRacks= rs.sortRacks(null, topo1);
Assert.assertEquals("# of racks sorted", 5, sortedRacks.size());
Iterator<ObjectResources> it = sortedRacks.iterator();
Assert.assertEquals("rack-0 should be ordered first", "rack-0", it.next().id);
Assert.assertEquals("rack-1 should be ordered second", "rack-1", it.next().id);
Assert.assertEquals("rack-4 should be ordered third", "rack-4", it.next().id);
Assert.assertEquals("rack-3 should be ordered fourth", "rack-3", it.next().id);

相关文章