java.util.NavigableMap#lastEntry ( )源码实例Demo

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

源代码1 项目: rcrs-server   文件: FileLogReader.java
private void removeStaleKeyFrames() {
    Logger.trace("Removing stale key frames");
    int size = keyFrames.size();
    if (size < KEY_FRAME_BUFFER_MAX_SIZE) {
        Logger.trace("Key frame buffer is not full: " + size + (size == 1 ? " entry" : " entries"));
        return;
    }
    // Try to balance the number of key frames.
    int window = maxTime / KEY_FRAME_BUFFER_MAX_SIZE;
    for (int i = 0; i < maxTime; i += window) {
        NavigableMap<Integer, WorldModel<? extends Entity>> next = keyFrames.subMap(i, false, i + window, true);
        Logger.trace("Window " + i + " -> " + (i + window) + " has " + next.size() + " entries");
        if (next.size() > 1) {
            // Remove all but the last entry in this window
            Map.Entry<Integer, WorldModel<? extends Entity>> last = next.lastEntry();
            next.clear();
            next.put(last.getKey(), last.getValue());
            Logger.trace("Retained entry " + last);
        }
    }
    Logger.trace("New key frame set: " + keyFrames);
}
 
源代码2 项目: datacollector   文件: HBaseStore.java
private String getValue(HBaseColumn hBaseColumn, Result result) {
  String value = null;
  if (result.isEmpty()) {
    return value;
  }
  if (!hBaseColumn.getCf().isPresent() || !hBaseColumn.getQualifier().isPresent()) {
    Map<String, String> columnMap = new HashMap<>();
    // parse column family, column, timestamp, and value
    for (Map.Entry<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> entry : result.getMap().entrySet()) {
      String columnFamily = Bytes.toString(entry.getKey());
      for (Map.Entry<byte[], NavigableMap<Long, byte[]>> cells : entry.getValue().entrySet()) {
        String column = Bytes.toString(cells.getKey());
        NavigableMap<Long, byte[]> cell = cells.getValue();
        Map.Entry<Long, byte[]> v = cell.lastEntry();
        String columnValue = Bytes.toString(v.getValue());
        columnMap.put(columnFamily + ":" + column, columnValue);
      }
    }
    JSONObject json = new JSONObject(columnMap);
    value = json.toString();
  } else {
    value = Bytes.toString(result.getValue(hBaseColumn.getCf().get(), hBaseColumn.getQualifier().get()));
  }
  return value;
}
 
源代码3 项目: ambry   文件: StatsBasedCompactionPolicy.java
/**
 * Finds the best candidate to compact by finding the candidate with the best cost benefit ratio
 * @param validDataPerLogSegments the valid data size for each log segment in the form of a {@link NavigableMap} of segment names to
 * valid data sizes.
 * @param segmentCapacity Segment capacity of one {@link LogSegment}
 * @param segmentHeaderSize Segment header size of a {@link LogSegment}
 * @param maxBlobSize max blob size to factor in when calculating the cost benefit ratio
 * @return the {@link CostBenefitInfo} for the best candidate to compact. {@code null} if there isn't any.
 */
private CostBenefitInfo getBestCandidateToCompact(NavigableMap<String, Long> validDataPerLogSegments,
    long segmentCapacity, long segmentHeaderSize, long maxBlobSize) {
  Map.Entry<String, Long> firstEntry = validDataPerLogSegments.firstEntry();
  Map.Entry<String, Long> lastEntry = validDataPerLogSegments.lastEntry();
  CostBenefitInfo bestCandidateToCompact = null;
  while (firstEntry != null) {
    Map.Entry<String, Long> endEntry = lastEntry;
    while (endEntry != null && LogSegmentNameHelper.COMPARATOR.compare(firstEntry.getKey(), endEntry.getKey()) <= 0) {
      CostBenefitInfo costBenefitInfo =
          getCostBenefitInfo(firstEntry.getKey(), endEntry.getKey(), validDataPerLogSegments, segmentCapacity,
              segmentHeaderSize, maxBlobSize);
      if (costBenefitInfo.getBenefit() >= storeConfig.storeMinLogSegmentCountToReclaimToTriggerCompaction && (
          bestCandidateToCompact == null
              || costBenefitInfo.getCostBenefitRatio().compareTo(bestCandidateToCompact.getCostBenefitRatio()) < 0)) {
        bestCandidateToCompact = costBenefitInfo;
        logger.trace("Updating best candidate to compact to {} ", bestCandidateToCompact);
      }
      endEntry = validDataPerLogSegments.lowerEntry(endEntry.getKey());
    }
    firstEntry = validDataPerLogSegments.higherEntry(firstEntry.getKey());
  }
  return bestCandidateToCompact;
}
 
源代码4 项目: metron   文件: HBaseDao.java
private Document getDocumentFromResult(Result result) throws IOException {
  NavigableMap<byte[], byte[]> columns = result.getFamilyMap( cf);
  if(columns == null || columns.size() == 0) {
    return null;
  }
  Map.Entry<byte[], byte[]> entry= columns.lastEntry();
  Long ts = Bytes.toLong(entry.getKey());
  if(entry.getValue()!= null) {
    Map<String, Object> json = JSONUtils.INSTANCE.load(new String(entry.getValue(),
            StandardCharsets.UTF_8),
        JSONUtils.MAP_SUPPLIER);

    // Make sure comments are in the proper format
    @SuppressWarnings("unchecked")
    List<Map<String, Object>> commentsMap = (List<Map<String, Object>>) json.get(COMMENTS_FIELD);
    try {
      if (commentsMap != null) {
        List<AlertComment> comments = new ArrayList<>();
        for (Map<String, Object> commentMap : commentsMap) {
          comments.add(new AlertComment(commentMap));
        }
        if (comments.size() > 0) {
          json.put(COMMENTS_FIELD,
              comments.stream().map(AlertComment::asMap).collect(Collectors.toList()));
        }
      }
      Key k = Key.fromBytes(result.getRow());
      return new Document(json, k.getGuid(), k.getSensorType(), ts);
    } catch (IOException e) {
      throw new RuntimeException("Unable to convert row key to a document", e);
    }
  }
  else {
    return null;
  }
}
 
源代码5 项目: kogito-runtimes   文件: KieRepositoryImpl.java
synchronized KieModule load(InternalKieScanner kieScanner, ReleaseId releaseId, VersionRange versionRange) {
    String ga = releaseId.getGroupId() + ":" + releaseId.getArtifactId();

    NavigableMap<ComparableVersion, KieModule> artifactMap = kieModules.get(ga);
    if ( artifactMap == null || artifactMap.isEmpty() ) {
        return null;
    }
    KieModule kieModule = artifactMap.get(new ComparableVersion(releaseId.getVersion()));

    if (versionRange.fixed) {
        if ( kieModule != null && releaseId.isSnapshot() ) {
            String oldSnapshotVersion = ((ReleaseIdImpl)kieModule.getReleaseId()).getSnapshotVersion();
            if ( oldSnapshotVersion != null ) {
                String currentSnapshotVersion = kieScanner.getArtifactVersion(releaseId);
                if (currentSnapshotVersion != null &&
                    new ComparableVersion(currentSnapshotVersion).compareTo(new ComparableVersion(oldSnapshotVersion)) > 0) {
                    // if the snapshot currently available on the maven repo is newer than the cached one
                    // return null to enforce the building of this newer version
                    return null;
                }
            }
        }
        return kieModule;
    }

    Map.Entry<ComparableVersion, KieModule> entry =
            versionRange.upperBound == null ?
            artifactMap.lastEntry() :
            versionRange.upperInclusive ?
                artifactMap.floorEntry(new ComparableVersion(versionRange.upperBound)) :
                artifactMap.lowerEntry(new ComparableVersion(versionRange.upperBound));

    if ( entry == null ) {
        return null;
    }

    if ( versionRange.lowerBound == null ) {
        return entry.getValue();
    }

    int comparison = entry.getKey().compareTo(new ComparableVersion(versionRange.lowerBound));
    return comparison > 0 || (comparison == 0 && versionRange.lowerInclusive) ? entry.getValue() : null;
}