本文整理汇总了Java中java.util.TreeSet.floor方法的典型用法代码示例。如果您正苦于以下问题:Java TreeSet.floor方法的具体用法?Java TreeSet.floor怎么用?Java TreeSet.floor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.TreeSet
的用法示例。
在下文中一共展示了TreeSet.floor方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSpan
import java.util.TreeSet; //导入方法依赖的package包/类
/**
* Returns the cache {@link CacheSpan} corresponding to the provided lookup {@link CacheSpan}.
* <p>
* If the lookup position is contained by an existing entry in the cache, then the returned
* {@link CacheSpan} defines the file in which the data is stored. If the lookup position is not
* contained by an existing entry, then the returned {@link CacheSpan} defines the maximum extents
* of the hole in the cache.
*
* @param lookupSpan A lookup {@link CacheSpan} specifying a key and position.
* @return The corresponding cache {@link CacheSpan}.
*/
private CacheSpan getSpan(CacheSpan lookupSpan) {
String key = lookupSpan.key;
long offset = lookupSpan.position;
TreeSet<CacheSpan> entries = cachedSpans.get(key);
if (entries == null) {
return CacheSpan.createOpenHole(key, lookupSpan.position);
}
CacheSpan floorSpan = entries.floor(lookupSpan);
if (floorSpan != null &&
floorSpan.position <= offset && offset < floorSpan.position + floorSpan.length) {
// The lookup position is contained within floorSpan.
if (floorSpan.file.exists()) {
return floorSpan;
} else {
// The file has been deleted from under us. It's likely that other files will have been
// deleted too, so scan the whole in-memory representation.
removeStaleSpans();
return getSpan(lookupSpan);
}
}
CacheSpan ceilEntry = entries.ceiling(lookupSpan);
return ceilEntry == null ? CacheSpan.createOpenHole(key, lookupSpan.position) :
CacheSpan.createClosedHole(key, lookupSpan.position,
ceilEntry.position - lookupSpan.position);
}
示例2: groupRunningLineCharactersByColumn
import java.util.TreeSet; //导入方法依赖的package包/类
/**
* For each character in each running line, add it to a list assigned to the appropriate header
* column e.g. all the characters between
*/
public static Map<String, List<ChartCharacter>> groupRunningLineCharactersByColumn(
TreeSet<RunningLineColumnIndex> runningLineColumnIndices,
List<ChartCharacter> runningLine) {
Map<String, List<ChartCharacter>> runningLineCharactersByColumn = new LinkedHashMap<>();
for (ChartCharacter pdfCharacter : runningLine) {
// get the location of the character for this particular running line row
RunningLineColumnIndex columnIndex =
new RunningLineColumnIndex(pdfCharacter.getxDirAdj());
// find the header column it belongs to by locating the column with the next-lowest
// xDirAdj value to the columnIndex
RunningLineColumnIndex floor = runningLineColumnIndices.floor(columnIndex);
// for each header column, store the characters that apply to it
String columnHeader = floor.getColumnHeader();
List<ChartCharacter> chartCharacters = runningLineCharactersByColumn.get(columnHeader);
if (chartCharacters == null) {
chartCharacters = new ArrayList<>();
}
chartCharacters.add(pdfCharacter);
runningLineCharactersByColumn.put(columnHeader, chartCharacters);
}
return runningLineCharactersByColumn;
}
示例3: isCached
import java.util.TreeSet; //导入方法依赖的package包/类
@Override
public synchronized boolean isCached(String key, long position, long length) {
TreeSet<CacheSpan> entries = cachedSpans.get(key);
if (entries == null) {
return false;
}
CacheSpan lookupSpan = CacheSpan.createLookup(key, position);
CacheSpan floorSpan = entries.floor(lookupSpan);
if (floorSpan == null || floorSpan.position + floorSpan.length <= position) {
// We don't have a span covering the start of the queried region.
return false;
}
long queryEndPosition = position + length;
long currentEndPosition = floorSpan.position + floorSpan.length;
if (currentEndPosition >= queryEndPosition) {
// floorSpan covers the queried region.
return true;
}
Iterator<CacheSpan> iterator = entries.tailSet(floorSpan, false).iterator();
while (iterator.hasNext()) {
CacheSpan next = iterator.next();
if (next.position > currentEndPosition) {
// There's a hole in the cache within the queried region.
return false;
}
// We expect currentEndPosition to always equal (next.position + next.length), but
// perform a max check anyway to guard against the existence of overlapping spans.
currentEndPosition = Math.max(currentEndPosition, next.position + next.length);
if (currentEndPosition >= queryEndPosition) {
// We've found spans covering the queried region.
return true;
}
}
// We ran out of spans before covering the queried region.
return false;
}
示例4: testFloor
import java.util.TreeSet; //导入方法依赖的package包/类
/**
* floor returns preceding element
*/
public void testFloor() {
TreeSet q = set5();
Object e1 = q.floor(three);
assertEquals(three, e1);
Object e2 = q.floor(six);
assertEquals(five, e2);
Object e3 = q.floor(one);
assertEquals(one, e3);
Object e4 = q.floor(zero);
assertNull(e4);
}