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; }
/** * 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(); }
/** * 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; } }
@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); }
@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; } }
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; } }
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 }
@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()); }
@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"); }
@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); } } } }
/** * 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; }
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);
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());
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;
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);