本文整理汇总了Java中java.util.TreeSet.ceiling方法的典型用法代码示例。如果您正苦于以下问题:Java TreeSet.ceiling方法的具体用法?Java TreeSet.ceiling怎么用?Java TreeSet.ceiling使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.TreeSet
的用法示例。
在下文中一共展示了TreeSet.ceiling方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: testCeiling
import java.util.TreeSet; //导入方法依赖的package包/类
/**
* ceiling returns next element
*/
public void testCeiling() {
TreeSet q = set5();
Object e1 = q.ceiling(three);
assertEquals(three, e1);
Object e2 = q.ceiling(zero);
assertEquals(one, e2);
Object e3 = q.ceiling(five);
assertEquals(five, e3);
Object e4 = q.ceiling(six);
assertNull(e4);
}