java.util.TreeMap#isEmpty ( )源码实例Demo

下面列出了java.util.TreeMap#isEmpty ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: DDMQ   文件: ConsumerStatusSubCommand.java
private void printRebalanceResult(TreeMap<String, ConsumerRunningInfo> criTable) {
    if (criTable == null || criTable.isEmpty()) {
        System.out.printf("Empty Result: criTable is empty.\n");
        return;
    }
    Map<MessageQueue, String> rbResult = new TreeMap<MessageQueue, String>();
    for (String cid : criTable.keySet()) {
        for (MessageQueue messageQueue : criTable.get(cid).getMqTable().keySet()) {
            rbResult.put(messageQueue, cid);
        }
    }
    String format = "%30s|%20s|%10s| %s\n";
    System.out.printf("--------------------------------------------------------------------------------------------------\n");
    System.out.printf(format, "Topic","Broker Name", "QueueId", "ConsumerClientId");
    System.out.printf("--------------------------------------------------------------------------------------------------\n");
    for (Entry<MessageQueue, String> entry : rbResult.entrySet()) {
        System.out.printf(format, entry.getKey().getTopic(), entry.getKey().getBrokerName(),
                entry.getKey().getQueueId(), entry.getValue());
    }

}
 
源代码2 项目: ambari-metrics   文件: TimelineMetricsCache.java
public synchronized void putMetric(TimelineMetric metric) {
  TreeMap<Long, Double> metricValues = this.timelineMetric.getMetricValues();
  if (metricValues.size() > maxRecsPerName) {
    // remove values for eldest maxEvictionTimeInMillis
    long newEldestTimestamp = oldestTimestamp + maxEvictionTimeInMillis;
    TreeMap<Long, Double> metricsSubSet =
      new TreeMap<>(metricValues.tailMap(newEldestTimestamp));
    if (metricsSubSet.isEmpty()) {
      oldestTimestamp = metric.getStartTime();
      this.timelineMetric.setStartTime(metric.getStartTime());
    } else {
      Long newStartTime = metricsSubSet.firstKey();
      oldestTimestamp = newStartTime;
      this.timelineMetric.setStartTime(newStartTime);
    }
    this.timelineMetric.setMetricValues(metricsSubSet);
    LOG.warn("Metrics cache overflow. Values for metric " +
      metric.getMetricName() + " older than " + newEldestTimestamp +
      " were removed to clean up the cache.");
  }
  this.timelineMetric.addMetricValues(metric.getMetricValues());
  updateTimeDiff(metric.getStartTime());
}
 
/**
 * @return the {@link BuildTarget} to use in the resolved target graph, formed by adding a flavor
 *     generated from the given version selections.
 */
protected final Optional<BuildTarget> getTranslateBuildTarget(
    TargetNode<?> node, ImmutableMap<BuildTarget, Version> selectedVersions) {

  BuildTarget originalTarget = node.getBuildTarget();
  node = resolveVersions(node, selectedVersions);
  BuildTarget newTarget = node.getBuildTarget();

  if (TargetGraphVersionTransformations.isVersionPropagator(node)) {
    VersionInfo info = getVersionInfo(node);
    Collection<BuildTarget> versionedDeps = info.getVersionDomain().keySet();
    TreeMap<BuildTarget, Version> versions = new TreeMap<>();
    for (BuildTarget depTarget : versionedDeps) {
      versions.put(depTarget, selectedVersions.get(depTarget));
    }
    if (!versions.isEmpty()) {
      Flavor versionedFlavor = getVersionedFlavor(versions);
      newTarget = node.getBuildTarget().withAppendedFlavors(versionedFlavor);
    }
  }

  return newTarget.equals(originalTarget) ? Optional.empty() : Optional.of(newTarget);
}
 
源代码4 项目: rocketmq   文件: MonitorService.java
public void reportConsumerRunningInfo(final String consumerGroup) throws InterruptedException,
    MQBrokerException, RemotingException, MQClientException {
    ConsumerConnection cc = defaultMQAdminExt.examineConsumerConnectionInfo(consumerGroup);
    TreeMap<String, ConsumerRunningInfo> infoMap = new TreeMap<String, ConsumerRunningInfo>();
    for (Connection c : cc.getConnectionSet()) {
        String clientId = c.getClientId();

        if (c.getVersion() < MQVersion.Version.V3_1_8_SNAPSHOT.ordinal()) {
            continue;
        }

        try {
            ConsumerRunningInfo info =
                defaultMQAdminExt.getConsumerRunningInfo(consumerGroup, clientId, false);
            infoMap.put(clientId, info);
        } catch (Exception e) {
        }
    }

    if (!infoMap.isEmpty()) {
        this.monitorListener.reportConsumerRunningInfo(infoMap);
    }
}
 
源代码5 项目: big-c   文件: AMRMClientImpl.java
/**
 * ContainerRequests with locality relaxation cannot be made at the same
 * priority as ContainerRequests without locality relaxation.
 */
private void checkLocalityRelaxationConflict(Priority priority,
    Collection<String> locations, boolean relaxLocality) {
  Map<String, TreeMap<Resource, ResourceRequestInfo>> remoteRequests =
      this.remoteRequestsTable.get(priority);
  if (remoteRequests == null) {
    return;
  }
  // Locality relaxation will be set to relaxLocality for all implicitly
  // requested racks. Make sure that existing rack requests match this.
  for (String location : locations) {
      TreeMap<Resource, ResourceRequestInfo> reqs =
          remoteRequests.get(location);
      if (reqs != null && !reqs.isEmpty()) {
        boolean existingRelaxLocality =
            reqs.values().iterator().next().remoteRequest.getRelaxLocality();
        if (relaxLocality != existingRelaxLocality) {
          throw new InvalidContainerRequestException("Cannot submit a "
              + "ContainerRequest asking for location " + location
              + " with locality relaxation " + relaxLocality + " when it has "
              + "already been requested with locality relaxation " + existingRelaxLocality);
        }
      }
    }
}
 
源代码6 项目: arctic-sea   文件: ProfileValue.java
public Geometry getGeometry() {
    if (isSetGeometry()) {
        TreeMap<Time, Coordinate> map = new TreeMap<>();
        int srid = -1;
        for (ProfileLevel level : getValue()) {
            if (level.isSetPhenomenonTime() && level.isSetLocation()) {
                if (srid < 0) {
                    srid = level.getLocation().getSRID();
                }
                map.put(level.getPhenomenonTime(), level.getLocation().getCoordinate());
            }
        }
        if (!map.isEmpty()) {
            if (new HashSet<>(map.values()).size() == 1) {
                return getValue().iterator().next().getLocation();
            } else {
                return new GeometryFactory(new PrecisionModel(), srid)
                        .createLineString(map.values().toArray(new Coordinate[1]));
            }
        }
    }
    return null;
}
 
源代码7 项目: DDMQ   文件: MonitorService.java
public void reportConsumerRunningInfo(final String consumerGroup) throws InterruptedException,
    MQBrokerException, RemotingException, MQClientException {
    ConsumerConnection cc = defaultMQAdminExt.examineConsumerConnectionInfo(consumerGroup);
    TreeMap<String, ConsumerRunningInfo> infoMap = new TreeMap<String, ConsumerRunningInfo>();
    for (Connection c : cc.getConnectionSet()) {
        String clientId = c.getClientId();

        if (c.getVersion() < MQVersion.Version.V3_1_8_SNAPSHOT.ordinal()) {
            continue;
        }

        try {
            ConsumerRunningInfo info =
                defaultMQAdminExt.getConsumerRunningInfo(consumerGroup, clientId, false);
            infoMap.put(clientId, info);
        } catch (Exception e) {
        }
    }

    if (!infoMap.isEmpty()) {
        this.monitorListener.reportConsumerRunningInfo(infoMap);
    }
}
 
源代码8 项目: rocketmq   文件: MonitorService.java
public void reportConsumerRunningInfo(final String consumerGroup) throws InterruptedException,
    MQBrokerException, RemotingException, MQClientException {
    ConsumerConnection cc = defaultMQAdminExt.examineConsumerConnectionInfo(consumerGroup);
    TreeMap<String, ConsumerRunningInfo> infoMap = new TreeMap<String, ConsumerRunningInfo>();
    for (Connection c : cc.getConnectionSet()) {
        String clientId = c.getClientId();

        if (c.getVersion() < MQVersion.Version.V3_1_8_SNAPSHOT.ordinal()) {
            continue;
        }

        try {
            ConsumerRunningInfo info =
                defaultMQAdminExt.getConsumerRunningInfo(consumerGroup, clientId, false);
            infoMap.put(clientId, info);
        } catch (Exception e) {
        }
    }

    if (!infoMap.isEmpty()) {
        this.monitorListener.reportConsumerRunningInfo(infoMap);
    }
}
 
源代码9 项目: star-zone   文件: ShardUtil.java
/**
 * 沿环的顺时针找到节点
 *
 * @param map
 * @param key
 * @return
 */
public static String doGetTableName(TreeMap<Long, String> map, String key) {
    final Long hash = alg.hash(key);
    Long target = hash;
    if (!map.containsKey(hash)) {
        target = map.ceilingKey(hash);
        if (target == null && !map.isEmpty()) {
            target = map.firstKey();
        }
    }
    return map.get(target);
}
 
源代码10 项目: gemfirexd-oss   文件: OrderedTombstoneMap.java
/**
 * Remove a version tag from the map.
 */
public Map.Entry<VersionTag, T> take() {
  if(tombstoneMap.isEmpty()) {
    //if there are no more entries, return null;
    return null;
  } else {
    //Otherwise, look at all of the members and find the tag with the 
    //lowest timestamp.
    long lowestTimestamp = Long.MAX_VALUE;
    TreeMap<VersionTag, T> lowestMap = null;
    for(TreeMap<VersionTag, T> memberMap: tombstoneMap.values()) {
      VersionTag firstTag = memberMap.firstKey();
      long stamp = firstTag.getVersionTimeStamp();
      if(stamp < lowestTimestamp) {
        lowestTimestamp = stamp;
        lowestMap = memberMap;
      }
    }
    if(lowestMap == null) {
      return null;
    }
    //Remove the lowest entry
    Entry<VersionTag, T> result = lowestMap.firstEntry();
    lowestMap.remove(result.getKey());
    if(lowestMap.isEmpty()) {
      //if this is the last entry from a given member,
      //the map for that member
      tombstoneMap.remove(result.getKey().getMemberID());
    }
    
    return result;
  }
}
 
源代码11 项目: galaxy-sdk-java   文件: LCSFileReader.java
@Override
protected void doStartTransaction() {
  TreeMap<String, File> fileTreeMap = FileUtils.listFile(topicFilePath, topicName);
  if (!fileTreeMap.isEmpty()) {
    curFilePath = fileTreeMap.firstEntry().getValue().getAbsolutePath();
  } else {
    curFilePath = null;
  }

}
 
源代码12 项目: gpx-animator   文件: Renderer.java
private void translateCoordinatesToZeroZero(final double scale, final TreeMap<Long, Point2D> timePointMap) {
    if (!timePointMap.isEmpty()) {
        maxTime = Math.max(maxTime, timePointMap.lastKey());
        minTime = Math.min(minTime, timePointMap.firstKey());

        for (final Point2D point : timePointMap.values()) {
            point.setLocation((point.getX() - minX) * scale, (maxY - point.getY()) * scale);
        }
    }
}
 
源代码13 项目: hadoop-gpu   文件: JobInitializationPoller.java
/**
 * This method returns the first job in the queue and removes the same.
 * 
 * @param queue
 *          queue name
 * @return First job in the queue and removes it.
 */
private JobInProgress getFirstJobInQueue(String queue) {
  TreeMap<JobSchedulingInfo, JobInProgress> jobsList = jobsPerQueue
      .get(queue);
  synchronized (jobsList) {
    if (jobsList.isEmpty()) {
      return null;
    }
    Iterator<JobInProgress> jobIterator = jobsList.values().iterator();
    JobInProgress job = jobIterator.next();
    jobIterator.remove();
    currentJobCount.getAndDecrement();
    return job;
  }
}
 
源代码14 项目: ReactionDecoder   文件: CDKMCSHandler.java
private synchronized void setAllMapping(List<Map<Integer, Integer>> solutions) {

        //System.out.println("Output of the final FinalMappings: ");
        try {
            int counter = 0;
            for (Map<Integer, Integer> final_solution : solutions) {
                TreeMap<Integer, Integer> atomMappings = new TreeMap<>();
                final_solution.entrySet().stream().forEach((Solutions) -> {
                    int iIndex = Solutions.getKey();
                    int jIndex = Solutions.getValue();

                    if (rOnPFlag) {
                        atomMappings.put(iIndex, jIndex);
                    } else {
                        atomMappings.put(jIndex, iIndex);
                    }
                });
                if (!allMCS.contains(atomMappings)) {
                    if (!atomMappings.isEmpty()) {
                        allMCS.add(counter, atomMappings);
                        counter += 1;
                    }
                }
            }

        } catch (Exception ex) {
            ex.getCause();
        }

    }
 
源代码15 项目: pcgen   文件: UnencumberedLoadFacet.java
/**
 * Returns the best Load value to avoid encumberance from Load for the
 * Player Character identified by the given CharID.
 * 
 * @param id
 *            The CharID identifying the Player Character
 * @return The best Load value to avoid encumberance from Load for the
 *         Player Character identified by the given CharID.
 */
public Load getBestLoad(CharID id)
{
	TreeMap<Load, Set<Object>> map = (TreeMap<Load, Set<Object>>) getCachedMap(id);
	if (map == null || map.isEmpty())
	{
		return Load.LIGHT;
	}
	return map.lastKey();
}
 
源代码16 项目: pcgen   文件: UnencumberedArmorFacet.java
/**
 * Returns the best Load value to avoid encumberance from Armor for the
 * Player Character identified by the given CharID.
 * 
 * @param id
 *            The CharID identifying the Player Character
 * @return The best Load value to avoid encumberance from Armor for the
 *         Player Character identified by the given CharID.
 */
public Load getBestLoad(CharID id)
{
	TreeMap<Load, Set<Object>> map = (TreeMap<Load, Set<Object>>) getCachedMap(id);
	if (map == null || map.isEmpty())
	{
		return Load.LIGHT;
	}
	return map.lastKey();
}
 
源代码17 项目: mzmine3   文件: RawDataFileOpenHandler_2_0.java
/**
 * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String,
 *      java.lang.String)
 */
public void endElement(String namespaceURI, String sName, String qName) throws SAXException {

  if (canceled)
    throw new SAXException("Parsing canceled");

  // <NAME>
  if (qName.equals(RawDataElementName_2_0.NAME.getElementName())) {

    // Adds the scan file and the name to the new raw data file
    String name = getTextOfElement();
    logger.info("Loading raw data file: " + name);
    newRawDataFile.setName(name);
  }

  if (qName.equals(RawDataElementName_2_0.QUANTITY_SCAN.getElementName())) {
    Integer.parseInt(getTextOfElement());
  }

  if (qName.equals(RawDataElementName_2_0.SCAN_ID.getElementName())) {
    scanNumber = Integer.parseInt(getTextOfElement());
  }

  if (qName.equals(RawDataElementName_2_0.MS_LEVEL.getElementName())) {
    msLevel = Integer.parseInt(getTextOfElement());
  }

  if (qName.equals(RawDataElementName_2_0.PARENT_SCAN.getElementName())) {
    Integer.parseInt(getTextOfElement());
  }

  if (qName.equals(RawDataElementName_2_0.PRECURSOR_MZ.getElementName())) {
    precursorMZ = Double.parseDouble(getTextOfElement());
  }

  if (qName.equals(RawDataElementName_2_0.PRECURSOR_CHARGE.getElementName())) {
    precursorCharge = Integer.parseInt(getTextOfElement());
  }

  if (qName.equals(RawDataElementName_2_0.RETENTION_TIME.getElementName())) {
    // Before MZmine.6 retention time was saved in seconds, but now we
    // use
    // minutes, so we need to divide by 60
    retentionTime = Double.parseDouble(getTextOfElement()) / 60d;
  }

  if (qName.equals(RawDataElementName_2_0.ION_MOBILITY.getElementName()))
  {
    mobility = Double.parseDouble(getTextOfElement());
  }

  if (qName.equals(RawDataElementName_2_0.CENTROIDED.getElementName())) {
    boolean centroided = Boolean.parseBoolean(getTextOfElement());
    if (centroided)
      spectrumType = MassSpectrumType.CENTROIDED;
    else
      spectrumType = MassSpectrumType.PROFILE;
  }

  if (qName.equals(RawDataElementName_2_0.QUANTITY_DATAPOINTS.getElementName())) {
    dataPointsNumber = Integer.parseInt(getTextOfElement());
  }

  if (qName.equals(RawDataElementName_2_0.FRAGMENT_SCAN.getElementName())) {
    fragmentScan[fragmentCount++] = Integer.parseInt(getTextOfElement());
  }

  if (qName.equals(RawDataElementName_2_0.SCAN.getElementName())) {

    try {
      int newStorageID = 1;
      TreeMap<Integer, Long> dataPointsOffsets = newRawDataFile.getDataPointsOffsets();
      TreeMap<Integer, Integer> dataPointsLengths = newRawDataFile.getDataPointsLengths();
      if (!dataPointsOffsets.isEmpty())
        newStorageID = dataPointsOffsets.lastKey().intValue() + 1;

      StorableScan storableScan = new StorableScan(newRawDataFile, newStorageID, dataPointsNumber,
          scanNumber, msLevel, retentionTime, mobility, precursorMZ, precursorCharge, fragmentScan,
          spectrumType, PolarityType.UNKNOWN, "", null);
      newRawDataFile.addScan(storableScan);

      dataPointsOffsets.put(newStorageID, storageFileOffset);
      dataPointsLengths.put(newStorageID, dataPointsNumber);

    } catch (IOException e) {
      throw new SAXException(e);
    }
    storageFileOffset += dataPointsNumber * 4 * 2;

  }
}
 
源代码18 项目: j2objc   文件: ULocale.java
private static ULocale getInstance(BaseLocale base, LocaleExtensions exts) {
    String id = lscvToID(base.getLanguage(), base.getScript(), base.getRegion(),
            base.getVariant());

    Set<Character> extKeys = exts.getKeys();
    if (!extKeys.isEmpty()) {
        // legacy locale ID assume Unicode locale keywords and
        // other extensions are at the same level.
        // e.g. @a=ext-for-aa;calendar=japanese;m=ext-for-mm;x=priv-use

        TreeMap<String, String> kwds = new TreeMap<String, String>();
        for (Character key : extKeys) {
            Extension ext = exts.getExtension(key);
            if (ext instanceof UnicodeLocaleExtension) {
                UnicodeLocaleExtension uext = (UnicodeLocaleExtension)ext;
                Set<String> ukeys = uext.getUnicodeLocaleKeys();
                for (String bcpKey : ukeys) {
                    String bcpType = uext.getUnicodeLocaleType(bcpKey);
                    // convert to legacy key/type
                    String lkey = toLegacyKey(bcpKey);
                    String ltype = toLegacyType(bcpKey, ((bcpType.length() == 0) ? "yes" : bcpType)); // use "yes" as the value of typeless keywords
                    // special handling for u-va-posix, since this is a variant, not a keyword
                    if (lkey.equals("va") && ltype.equals("posix") && base.getVariant().length() == 0) {
                        id = id + "_POSIX";
                    } else {
                        kwds.put(lkey, ltype);
                    }
                }
                // Mapping Unicode locale attribute to the special keyword, attribute=xxx-yyy
                Set<String> uattributes = uext.getUnicodeLocaleAttributes();
                if (uattributes.size() > 0) {
                    StringBuilder attrbuf = new StringBuilder();
                    for (String attr : uattributes) {
                        if (attrbuf.length() > 0) {
                            attrbuf.append('-');
                        }
                        attrbuf.append(attr);
                    }
                    kwds.put(LOCALE_ATTRIBUTE_KEY, attrbuf.toString());
                }
            } else {
                kwds.put(String.valueOf(key), ext.getValue());
            }
        }

        if (!kwds.isEmpty()) {
            StringBuilder buf = new StringBuilder(id);
            buf.append("@");
            Set<Map.Entry<String, String>> kset = kwds.entrySet();
            boolean insertSep = false;
            for (Map.Entry<String, String> kwd : kset) {
                if (insertSep) {
                    buf.append(";");
                } else {
                    insertSep = true;
                }
                buf.append(kwd.getKey());
                buf.append("=");
                buf.append(kwd.getValue());
            }

            id = buf.toString();
        }
    }
    return new ULocale(id);
}
 
源代码19 项目: java-trader   文件: SimMarketDataService.java
public static Exchangeable getPrimaryInstrument(Exchange exchange, String commodity, LocalDate tradingDay) {
    int occurence=0;
    char cc = commodity.charAt(commodity.length()-1);
    if ( cc>='0' && cc<='9') {
        occurence = cc-'0';
        commodity = commodity.substring(0, commodity.length()-1);
    }
    if ( exchange==null ) {
        exchange = Future.detectExchange(commodity);
    }
    ExchangeableData edata = TraderHomeUtil.getExchangeableData();
    Future cf = new Future(exchange, commodity, commodity);
    TreeMap<Long, Exchangeable> instruments = new TreeMap<>();
    //Load daily stats data
    try {
        if ( edata.exists(cf, ExchangeableData.DAYSTATS, null)) {
            String key = cf.uniqueId()+"-"+tradingDay;
            String cachedData = cachedDayStats.get(key);
            if ( cachedData==null ) {
                cachedData = edata.load(cf, ExchangeableData.DAYSTATS, null);
                cachedDayStats.put(key, cachedData);
            }
            CSVDataSet csvDataSet = CSVUtil.parse(cachedData);
            while(csvDataSet.next()) {
                String statTradingDay = csvDataSet.get(ExchangeableData.COLUMN_TRADINGDAY);
                long openInt = csvDataSet.getLong(ExchangeableData.COLUMN_END_OPENINT);
                Exchangeable instrument = Exchangeable.fromString(csvDataSet.get(ExchangeableData.COLUMN_INSTRUMENT_ID));
                if ( DateUtil.str2localdate(statTradingDay).equals(tradingDay) && StringUtil.equalsIgnoreCase(instrument.commodity(), commodity) ) {
                    instruments.put(openInt, instrument);
                }
            }
        }
    }catch(IOException ioe) {
        throw new AppRuntimeException(ioe, ServiceErrorConstants.ERR_DATA_LOAD_FAILED,
                MessageFormat.format("{0} 加载 dayStats 文件失败: {1}", commodity, ioe) );
    }
    if ( instruments.isEmpty() ) {
        throw new AppRuntimeException(ServiceErrorConstants.ERR_DATA_LOAD_FAILED,
                MessageFormat.format("{0} {1} 在 dayStats 中无数据", commodity, tradingDay) );
    }
    List<Exchangeable> instruments0 = new ArrayList<>(instruments.values());
    Collections.reverse(instruments0);
    Exchangeable result = null;
    int instrumentOccurence=0;
    for(Exchangeable e:instruments0) {
        instrumentOccurence++;
        if ( instrumentOccurence>=occurence) {
            result = e;
            break;
        }
    }
    return result;
}
 
源代码20 项目: mynlp   文件: DefaultCustomDictionary.java
public DefaultCustomDictionary(MynlpEnv mynlp) throws Exception {

        List<String> resourceUrls = mynlp.getSettings().getAsList(dictPathSetting);

        if (resourceUrls == null || resourceUrls.isEmpty()) {
            return;
        }

        this.resourceUrls = resourceUrls;


        TreeMap<String, Integer> map = new TreeMap<>();

        for (String url : resourceUrls) {
            NlpResource resource = mynlp.tryLoadResource(url);

            if (resource == null) {
                logger.warn("miss resource "+url);
                continue;
            }

            try (CharSourceLineReader reader = UseLines.lineReader(resource.inputStream())) {
                while (reader.hasNext()) {
                    String line = reader.next();

                    String[] params = line.split("\\s");

                    if (isNormalization) {
                        params[0] = normalizationString(params[0]);
                    }

                    map.put(params[0], 1000);
                }
            }
        }


        if (map.isEmpty()) {
            return;
        }

        dat = new DoubleArrayTrieStringIntMap(map);
    }