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


Java TreeSet.floor方法代码示例

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

示例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;
}
 
开发者ID:robinhowlett,项目名称:chart-parser,代码行数:31,代码来源:RunningLine.java

示例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;
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:37,代码来源:SimpleCache.java

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


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