java.util.TreeMap.subMap()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(141)

本文整理了Java中java.util.TreeMap.subMap()方法的一些代码示例,展示了TreeMap.subMap()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TreeMap.subMap()方法的具体详情如下:
包路径:java.util.TreeMap
类名称:TreeMap
方法名:subMap

TreeMap.subMap介绍

暂无

代码示例

代码示例来源:origin: commons-collections/commons-collections

/**
 * Return a view of the portion of this map whose keys are in the
 * range fromKey (inclusive) to toKey (exclusive).
 *
 * @param fromKey Lower limit of keys for the returned map
 * @param toKey Upper limit of keys for the returned map
 * @return a sub map
 */
public SortedMap subMap(Object fromKey, Object toKey) {
  if (fast) {
    return (map.subMap(fromKey, toKey));
  } else {
    synchronized (map) {
      return (map.subMap(fromKey, toKey));
    }
  }
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Obtains q(t) for the given t.
 */
private int at(long t) {
  SortedMap<Long, int[]> head = data.subMap(t,Long.MAX_VALUE);
  if (head.isEmpty()) return 0;
  return data.get(head.firstKey())[0];
}

代码示例来源:origin: wildfly/wildfly

/**
 * Return a view of the portion of this map whose keys are in the
 * range fromKey (inclusive) to toKey (exclusive).
 *
 * @param fromKey Lower limit of keys for the returned map
 * @param toKey Upper limit of keys for the returned map
 * @return a sub map
 */
public SortedMap subMap(Object fromKey, Object toKey) {
  if (fast) {
    return (map.subMap(fromKey, toKey));
  } else {
    synchronized (map) {
      return (map.subMap(fromKey, toKey));
    }
  }
}

代码示例来源:origin: goldmansachs/gs-collections

public MutableSortedMap<K, V> subMap(K fromKey, K toKey)
{
  return SortedMapAdapter.adapt(this.treeMap.subMap(fromKey, toKey));
}

代码示例来源:origin: eclipse/eclipse-collections

@Override
public MutableSortedMap<K, V> subMap(K fromKey, K toKey)
{
  return SortedMapAdapter.adapt(this.treeMap.subMap(fromKey, toKey));
}

代码示例来源:origin: eclipse/eclipse-collections

@Override
public MutableSortedMap<K, V> subMap(K fromKey, K toKey)
{
  return SortedMapAdapter.adapt(this.treeMap.subMap(fromKey, toKey));
}

代码示例来源:origin: apache/hive

private SortedMap<Long, Long> getAndValidateMissingChunks(
  int maxAlloc, long from, long to) {
 Map.Entry<Long, Long> firstMissing = chunkIndex.floorEntry(from);
 if (firstMissing == null) {
  throw new AssertionError("No lower bound for start offset " + from);
 }
 if (firstMissing.getValue() <= from
   || ((from - firstMissing.getKey()) % maxAlloc) != 0) {
  // The data does not belong to a recognized chunk, or is split wrong.
  throw new AssertionError("Lower bound for start offset " + from + " is ["
    + firstMissing.getKey() + ", " + firstMissing.getValue() + ")");
 }
 SortedMap<Long, Long> missingChunks = chunkIndex.subMap(firstMissing.getKey(), to);
 if (missingChunks.isEmpty()) {
  throw new AssertionError("No chunks for [" + from + ", " + to + ")");
 }
 long lastMissingOffset = missingChunks.lastKey(),
   lastMissingEnd = missingChunks.get(lastMissingOffset);
 if (lastMissingEnd < to
   || (to != lastMissingEnd && ((to - lastMissingOffset) % maxAlloc) != 0)) {
  // The data does not belong to a recognized chunk, or is split wrong.
  throw new AssertionError("Lower bound for end offset " + to + " is ["
    + lastMissingOffset + ", " + lastMissingEnd + ")");
 }
 return missingChunks;
}

代码示例来源:origin: apache/pulsar

private boolean hasChildren(String path) {
  return !tree.subMap(path + '/', path + '0').isEmpty();
}

代码示例来源:origin: org.apache.poi/poi-ooxml

void applyFont(TreeMap<Integer, CTRPrElt> formats, int startIndex, int endIndex, CTRPrElt fmt) {
    // delete format runs that fit between startIndex and endIndex
    // runs intersecting startIndex and endIndex remain
    int runStartIdx = 0;
    for (Iterator<Integer> it = formats.keySet().iterator(); it.hasNext();) {
      int runEndIdx = it.next();
      if (runStartIdx >= startIndex && runEndIdx < endIndex) {
        it.remove();
      }
      runStartIdx = runEndIdx;
    }
    if(startIndex > 0 && !formats.containsKey(startIndex)) {
      // If there's a format that starts later in the string, make it start now
      for(Map.Entry<Integer, CTRPrElt> entry : formats.entrySet()) {
        if(entry.getKey() > startIndex) {
         formats.put(startIndex, entry.getValue());
         break;
        }
      }
    }
    formats.put(endIndex, fmt);
    // assure that the range [startIndex, endIndex] consists if a single run
    // there can be two or three runs depending whether startIndex or endIndex
    // intersected existing format runs
    SortedMap<Integer, CTRPrElt> sub = formats.subMap(startIndex, endIndex);
    while(sub.size() > 1) sub.remove(sub.lastKey());
  }

代码示例来源:origin: apache/incubator-gobblin

/**
 * Compose meta data when limiter fails to acquire permit
 * The meta data key list is passed from source layer
 * A prefix matching is used because some work unit {@link org.apache.gobblin.source.workunit.MultiWorkUnit} have packing strategy, which
 * can append additional string after the key name
 *
 * @return String map representing all the meta data need to report. Return null if no meta data was found.
 */
private ImmutableMap<String, String> getLimiterStopMetadata() {
 WorkUnit workUnit = this.taskState.getWorkunit();
 Properties properties = workUnit.getProperties();
 String metadataKeyList = properties.getProperty(LimiterConfigurationKeys.LIMITER_REPORT_KEY_LIST, LimiterConfigurationKeys.DEFAULT_LIMITER_REPORT_KEY_LIST);
 List<String> keyList = Splitter.on(',').omitEmptyStrings().trimResults()
     .splitToList(metadataKeyList);
 if (keyList.isEmpty())
  return ImmutableMap.of();
  Set<String> names = properties.stringPropertyNames();
  TreeMap<String, String> orderedProperties = new TreeMap<>();
  for (String name : names) {
   orderedProperties.put(name, properties.getProperty(name));
  }
  ImmutableMap.Builder builder = ImmutableMap.<String, String>builder();
  for (String oldKey : keyList) {
   builder.putAll(orderedProperties.subMap(oldKey, oldKey + Character.MAX_VALUE));
  }
  builder.put(LIMITER_STOP_CAUSE_KEY, LIMITER_STOP_CAUSE_VALUE);
  return builder.build();
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * @param fromKey
 *      Biggest build number to be in the returned set.
 * @param toKey
 *      Smallest build number-1 to be in the returned set (-1 because this is exclusive)
 */
public SortedMap<Integer, R> subMap(Integer fromKey, Integer toKey) {
  // TODO: if this method can produce a lazy map, that'd be wonderful
  // because due to the lack of floor/ceil/higher/lower kind of methods
  // to look up keys in SortedMap, various places of Jenkins rely on
  // subMap+firstKey/lastKey combo.
  R start = search(fromKey, DESC);
  if (start==null)    return EMPTY_SORTED_MAP;
  R end = search(toKey, ASC);
  if (end==null)      return EMPTY_SORTED_MAP;
  for (R i=start; i!=end; ) {
    i = search(getNumberOf(i)-1,DESC);
    assert i!=null;
  }
  return Collections.unmodifiableSortedMap(new BuildReferenceMapAdapter<R>(this, index.byNumber.subMap(fromKey, toKey)));
}

代码示例来源:origin: apache/hive

Map.Entry<Long, BlockLocation> endEntry = locations.floorEntry(offset + length);
NavigableMap<Long, BlockLocation> navigableMap = locations.subMap(startEntry.getKey(),
     true, endEntry.getKey(), true);

代码示例来源:origin: apache/drill

Map.Entry<Long, BlockLocation> endEntry = locations.floorEntry(offset + length);
NavigableMap<Long, BlockLocation> navigableMap = locations.subMap(startEntry.getKey(),
     true, endEntry.getKey(), true);

代码示例来源:origin: org.apache.poi/poi-ooxml

public void groupRow(int fromRow, int toRow)
  for(SXSSFRow row : _rows.subMap(fromRow, toRow + 1).values()){
    int level = row.getOutlineLevel() + 1;
    row.setOutlineLevel(level);

代码示例来源:origin: apache/ignite

/**
 * @throws IgniteCheckedException If failed.
 */
@Test
public void testFind() throws IgniteCheckedException {
  TestTree tree = createTestTree(true);
  TreeMap<Long, Long> map = new TreeMap<>();
  long size = CNT * CNT;
  for (long i = 1; i <= size; i++) {
    tree.put(i);
    map.put(i, i);
  }
  checkCursor(tree.find(null, null), map.values().iterator());
  checkCursor(tree.find(10L, 70L), map.subMap(10L, true, 70L, true).values().iterator());
}

代码示例来源:origin: fearofcode/bateman

public SortedMap<DateTime, BigDecimal> dateSlice(DateTime startPoint, DateTime endPoint) {
  return prices.subMap(startPoint, true, endPoint, true);
}

代码示例来源:origin: rackerlabs/blueflood

private NavigableMap<Long,String> getBlobsWithinRange(PageSet<? extends StorageMetadata> pages) {
  // TreeMap used because of sorted property
  TreeMap<Long, String> tsToBlobName = new TreeMap<Long, String>();
  for (StorageMetadata blobMeta : pages) {
    String fileName = blobMeta.getName(); // 20140226_1393442533000.json.gz
    String dateAndTs = fileName.split("\\.", 2)[0].trim(); // 20140226_1393442533000
    String tsCreated = dateAndTs.split("_")[1].trim(); // 1393442533000
    long ts = Long.parseLong(tsCreated);
    tsToBlobName.put(ts, fileName);
  }
  //Gets key within the time range specified
  NavigableMap<Long, String> mapWithinRange = tsToBlobName.subMap(START_TIME - 60000*15, true, STOP_TIME + 60000*30, true);
  if(mapWithinRange.isEmpty()) {
    lastMarker = tsToBlobName.lastEntry().getValue().trim();
    synchronized (CloudFilesManager.this) {
      // this is where we resume from.
      MarkerUtils.writeLastMarker(tsToBlobName.lastEntry().getValue().trim());
    }
  }
  return mapWithinRange;
}

代码示例来源:origin: matyb/java-koans

@Koan
public void usingBackedSubMap() {
  TreeMap<String, String> map = new TreeMap<String, String>();
  map.put("a", "Aha");
  map.put("b", "Boo");
  map.put("c", "Coon");
  map.put("e", "Emu");
  map.put("f", "Fox");
  SortedMap<String, String> backedMap = map.subMap("c", "f");
  assertEquals(backedMap.size(), __);
  assertEquals(map.size(), __);
  backedMap.put("d", "Dog");
  assertEquals(backedMap.size(), __);
  assertEquals(map.size(), __);
  assertEquals(map.containsKey("d"), __);
  // Again: backed maps are just like those little quantum states
  // that are connected forever...
}

代码示例来源:origin: fearofcode/bateman

public BigDecimal openOnDay(DateTime date) {
  DateTime midnight = date.toDateMidnight().toDateTime();
  NavigableMap<DateTime, BigDecimal> previousPrices = prices.subMap(midnight, true, date, true);
  return previousPrices.firstEntry().getValue();
}

代码示例来源:origin: org.drools/drools-core

public void checkResults2(TreeMap<Integer, String> tree,
               int range,
               int start,
               int end,
               int increment) {
    //FastIterator it = tree.range( start, true, end, true );
    SortedMap<Integer, String> map =  tree.subMap( start, end );

    int i = 0;
    List<Integer> actual = new ArrayList<Integer>();

    for (Iterator<java.util.Map.Entry<Integer, String>> it = map.entrySet().iterator(); it.hasNext(); ) {
      java.util.Map.Entry<Integer, String> entry = it.next();
    }

    for ( i = 0; i < range; i = i + increment ) {
      tree.remove( i );
    }

  }
}

相关文章