当前位置: 首页>>代码示例>>Java>>正文


Java TreeSet.ceiling方法代码示例

本文整理汇总了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);
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:37,代码来源:SimpleCache.java

示例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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:TreeSetTest.java


注:本文中的java.util.TreeSet.ceiling方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。