本文整理匯總了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);
}