Java Code Examples for java.util.NavigableMap#lowerEntry()
The following examples show how to use
java.util.NavigableMap#lowerEntry() .
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: StatsBasedCompactionPolicy.java From ambry with Apache License 2.0 | 6 votes |
/** * 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; }
Example 2
Source File: TreeSubMapTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * lowerEntry returns preceding entry. */ public void testLowerEntry() { NavigableMap map = map5(); Map.Entry e1 = map.lowerEntry(three); assertEquals(two, e1.getKey()); Map.Entry e2 = map.lowerEntry(six); assertEquals(five, e2.getKey()); Map.Entry e3 = map.lowerEntry(one); assertNull(e3); Map.Entry e4 = map.lowerEntry(zero); assertNull(e4); }
Example 3
Source File: TreeSubMapTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * lowerEntry returns preceding entry. */ public void testDescendingLowerEntry() { NavigableMap map = dmap5(); Map.Entry e1 = map.lowerEntry(m3); assertEquals(m2, e1.getKey()); Map.Entry e2 = map.lowerEntry(m6); assertEquals(m5, e2.getKey()); Map.Entry e3 = map.lowerEntry(m1); assertNull(e3); Map.Entry e4 = map.lowerEntry(zero); assertNull(e4); }
Example 4
Source File: TreeSubMapTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * lowerEntry returns preceding entry. */ public void testLowerEntry() { NavigableMap map = map5(); Map.Entry e1 = map.lowerEntry(three); assertEquals(two, e1.getKey()); Map.Entry e2 = map.lowerEntry(six); assertEquals(five, e2.getKey()); Map.Entry e3 = map.lowerEntry(one); assertNull(e3); Map.Entry e4 = map.lowerEntry(zero); assertNull(e4); }
Example 5
Source File: TreeSubMapTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * lowerEntry returns preceding entry. */ public void testDescendingLowerEntry() { NavigableMap map = dmap5(); Map.Entry e1 = map.lowerEntry(m3); assertEquals(m2, e1.getKey()); Map.Entry e2 = map.lowerEntry(m6); assertEquals(m5, e2.getKey()); Map.Entry e3 = map.lowerEntry(m1); assertNull(e3); Map.Entry e4 = map.lowerEntry(zero); assertNull(e4); }
Example 6
Source File: KieRepositoryImpl.java From kogito-runtimes with Apache License 2.0 | 4 votes |
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; }