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

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

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

TreeMap.put介绍

[英]Associates the specified value with the specified key in this map. If the map previously contained a mapping for the key, the old value is replaced.
[中]将指定的值与此映射中的指定键相关联。如果映射以前包含键的映射,则替换旧值。

代码示例

代码示例来源:origin: google/ExoPlayer

private void handleManifestExpiredMessage(long eventTimeUs, long manifestPublishTimeMsInEmsg) {
 Long previousExpiryTimeUs = manifestPublishTimeToExpiryTimeUs.get(manifestPublishTimeMsInEmsg);
 if (previousExpiryTimeUs == null) {
  manifestPublishTimeToExpiryTimeUs.put(manifestPublishTimeMsInEmsg, eventTimeUs);
 } else {
  if (previousExpiryTimeUs > eventTimeUs) {
   manifestPublishTimeToExpiryTimeUs.put(manifestPublishTimeMsInEmsg, eventTimeUs);
  }
 }
}

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

public static TreeMap<Integer, Integer> integerDivided(int sum, int numPieces) {
  int base = sum / numPieces;
  int numInc = sum % numPieces;
  int numBases = numPieces - numInc;
  TreeMap<Integer, Integer> ret = new TreeMap<Integer, Integer>();
  ret.put(base, numBases);
  if (numInc != 0) {
    ret.put(base + 1, numInc);
  }
  return ret;
}

代码示例来源:origin: hankcs/HanLP

private Nature(String name)
{
  if (idMap == null) idMap = new TreeMap<String, Integer>();
  assert !idMap.containsKey(name);
  this.name = name;
  ordinal = idMap.size();
  idMap.put(name, ordinal);
  Nature[] extended = new Nature[idMap.size()];
  if (values != null)
    System.arraycopy(values, 0, extended, 0, values.length);
  extended[ordinal] = this;
  values = extended;
}

代码示例来源:origin: stackoverflow.com

//create TreeMap instance
 TreeMap treeMap = new TreeMap();
 //add key value pairs to TreeMap
 treeMap.put("1","One");
 treeMap.put("2","Two");
 treeMap.put("3","Three");
 /*
  get Collection of values contained in TreeMap using
  Collection values()        
 */
 Collection c = treeMap.values();
 //obtain an Iterator for Collection
 Iterator itr = c.iterator();
 //iterate through TreeMap values iterator
 while(itr.hasNext())
  System.out.println(itr.next());

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

private void printRow(TRowResult rowResult) {
 // copy values into a TreeMap to get them in sorted order
 TreeMap<String, TCell> sorted = new TreeMap<>();
 for (Map.Entry<ByteBuffer, TCell> column : rowResult.columns.entrySet()) {
  sorted.put(utf8(column.getKey().array()), column.getValue());
 }
 StringBuilder rowStr = new StringBuilder();
 for (SortedMap.Entry<String, TCell> entry : sorted.entrySet()) {
  rowStr.append(entry.getKey());
  rowStr.append(" => ");
  rowStr.append(utf8(entry.getValue().value.array()));
  rowStr.append("; ");
 }
 System.out.println("row: " + utf8(rowResult.row.array()) + ", cols: " + rowStr);
}

代码示例来源:origin: aragozin/jvm-tools

private void printObjs(List<Long> changedIds, List<Long> oldDomIds, List<Long> newDomIds, List<Boolean> addedByDirtySet, List<Long> changedIdx) {
  if (changedIds.size()>20) return;
  TreeMap<Integer,String> m = new TreeMap();
  for (int i=0; i<changedIds.size(); i++) {
    Long iid = changedIds.get(i);
    Long oldDom = oldDomIds.get(i);
    Long newDom = newDomIds.get(i);
    Long index = changedIdx.get(i);
    Boolean addedByDirt = addedByDirtySet.get(i);
    Instance ii = heap.getInstanceByID(iid.longValue());
    int number = ii.getInstanceNumber();
    String text = "Index: "+index+(addedByDirt?" New ":" Old ")+printInstance(iid);
    text+=" OldDom "+printInstance(oldDom);
    text+=" NewDom: "+printInstance(newDom);
    m.put(number,text);
  }
  for (Integer in : m.keySet()) {
    System.out.println(m.get(in));
  }
}

代码示例来源:origin: hankcs/HanLP

/**
 * 将分数map排序折叠
 * @param scoreMap
 * @return
 */
private static TreeMap<Double ,Set<String>> sortScoreMap(TreeMap<String, Double> scoreMap)
{
  TreeMap<Double, Set<String>> result = new TreeMap<Double, Set<String>>(Collections.reverseOrder());
  for (Map.Entry<String, Double> entry : scoreMap.entrySet())
  {
    Set<String> sentenceSet = result.get(entry.getValue());
    if (sentenceSet == null)
    {
      sentenceSet = new HashSet<String>();
      result.put(entry.getValue(), sentenceSet);
    }
    sentenceSet.add(entry.getKey());
  }
  return result;
}

代码示例来源:origin: FudanNLP/fnlp

private void initSortMap() {
    for (int i = 0; i < feasize - 1; i++) {
      for (int j = i + 1; j < feasize; j++) {
        double temp = getDistance(i, j);
        Set<String> hashset;
        if (sortmap.containsKey(temp))
          hashset = sortmap.get(temp);
        else
          hashset = new HashSet<String>();
//                System.out.println(temp + " " + i + " " + j);
//                System.out.println(getDistance(i, j));
        hashset.add(id2String(i, j));
        sortmap.put(temp, hashset);
      }
    }
    System.out.println("Map init size: " + sortmap.size());
  }

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

private TreeMap<Long, Integer> getStoredCurrAttempts(long currTransaction, int maxBatches) {
  TreeMap<Long, Integer> ret = new TreeMap<Long, Integer>();
  for (TransactionalState state : _states) {
    Map<Object, Number> attempts = (Map) state.getData(CURRENT_ATTEMPTS);
    if (attempts == null) {
      attempts = new HashMap();
    }
    for (Entry<Object, Number> e : attempts.entrySet()) {
      // this is because json doesn't allow numbers as keys...
      // TODO: replace json with a better form of encoding
      Number txidObj;
      if (e.getKey() instanceof String) {
        txidObj = Long.parseLong((String) e.getKey());
      } else {
        txidObj = (Number) e.getKey();
      }
      long txid = ((Number) txidObj).longValue();
      int attemptId = ((Number) e.getValue()).intValue();
      Integer curr = ret.get(txid);
      if (curr == null || attemptId > curr) {
        ret.put(txid, attemptId);
      }
    }
  }
  ret.headMap(currTransaction).clear();
  ret.tailMap(currTransaction + maxBatches - 1).clear();
  return ret;
}

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

/** This method generates "random double, integer" pairs, sort them, gets first "testSize" elements and returns appropriate indices */
@NotNull private TreeSet<Integer> getSortedIndices(int datasetSize, int testSize) {
  Random rnd = new Random();
  TreeMap<Double, Integer> randomIdxPairs = new TreeMap<>();
  for (int i = 0; i < datasetSize; i++)
    randomIdxPairs.put(rnd.nextDouble(), i);
  final TreeMap<Double, Integer> testIdxPairs = randomIdxPairs.entrySet().stream()
    .limit(testSize)
    .collect(TreeMap::new, (m, e) -> m.put(e.getKey(), e.getValue()), Map::putAll);
  return new TreeSet<>(testIdxPairs.values());
}

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

/**
 * Splits the range set at the given timestamp (if it hasn't been split yet)
 */
private void splitAt(long t) {
  if (data.containsKey(t)) return; // already split at this timestamp
  SortedMap<Long, int[]> head = data.headMap(t);
  int v = head.isEmpty() ? 0 : data.get(head.lastKey())[0];
  data.put(t, new int[]{v});
}

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

synchronized private void changeDisplay(int displayId, DisplayInfo displayInfo) {
 if (!displayInfos.containsKey(displayId)) {
  throw new IllegalStateException("no display " + displayId);
 }
 displayInfos.put(displayId, displayInfo);
 notifyListeners(displayId, DisplayManagerGlobal.EVENT_DISPLAY_CHANGED);
}

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

@Override
public void merge(Accumulator<Integer, TreeMap<Integer, Integer>> other) {
  // Merge the values into this map
  for (Map.Entry<Integer, Integer> entryFromOther : other.getLocalValue().entrySet()) {
    Integer ownValue = this.treeMap.get(entryFromOther.getKey());
    if (ownValue == null) {
      this.treeMap.put(entryFromOther.getKey(), entryFromOther.getValue());
    } else {
      this.treeMap.put(entryFromOther.getKey(), entryFromOther.getValue() + ownValue);
    }
  }
}

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

@Override
public void resumeFromBlacklist() {
  Set<String> readyToRemove = new HashSet<>();
  for (Map.Entry<String, Integer> entry : blacklist.entrySet()) {
    String key = entry.getKey();
    int value = entry.getValue() - 1;
    if (value == 0) {
      readyToRemove.add(key);
    } else {
      blacklist.put(key, value);
    }
  }
  for (String key : readyToRemove) {
    blacklist.remove(key);
    LOG.info("Supervisor {} has been blacklisted more than resume period. Removed from blacklist.", key);
  }
}

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

public void putAll(Map<? extends String, ? extends V> map) {
    for (Map.Entry<? extends String, ? extends V> e : map.entrySet()) {
      super.put(convertCase(e.getKey()), e.getValue());
    }
  }
}

代码示例来源:origin: stackoverflow.com

TreeMap<String, Object> myMap = new TreeMap<String, Object>();
myMap.put( "111-hello", null );
myMap.put( "111-world", null );
myMap.put( "111-test", null );
myMap.put( "111-java", null );
myMap.put( "123-one", null );
myMap.put( "123-two", null );
myMap.put( "123--three", null );
myMap.put( "123--four", null );
myMap.put( "125-hello", null );
myMap.put( "125--world", null );
System.out.println( "111 \t" + getByPreffix( myMap, "111" ) );
System.out.println( "123 \t" + getByPreffix( myMap, "123" ) );
System.out.println( "123-- \t" + getByPreffix( myMap, "123--" ) );
System.out.println( "12 \t" + getByPreffix( myMap, "12" ) );

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

private void printRow(TRowResult rowResult) {
  // copy values into a TreeMap to get them in sorted order
  TreeMap<String, TCell> sorted = new TreeMap<>();
  for (Map.Entry<ByteBuffer, TCell> column : rowResult.columns.entrySet()) {
    sorted.put(utf8(column.getKey().array()), column.getValue());
  }
  StringBuilder rowStr = new StringBuilder();
  for (SortedMap.Entry<String, TCell> entry : sorted.entrySet()) {
    rowStr.append(entry.getKey());
    rowStr.append(" => ");
    rowStr.append(utf8(entry.getValue().value.array()));
    rowStr.append("; ");
  }
  System.out.println("row: " + utf8(rowResult.row.array()) + ", cols: " + rowStr);
}

代码示例来源:origin: osmandapp/Osmand

TreeMap<MapObject, Street> resMap = new TreeMap<MapObject, Street>(new Comparator<MapObject>() {
  resMap.put(s, s);
  reader.preloadBuildings(s, null);
  for (Building b : s.getBuildings()) {
    if (MapUtils.getDistance(b.getLocation(), lat, lon) < 100) {
      resMap.put(b, s);
  Street s = resMap.get(e);
  if (e instanceof Building && MapUtils.getDistance(e.getLocation(), lat, lon) < 40) {
    Building b = (Building) e;
    System.out.println(b.getName() + "   " + s);
  } else if (e instanceof Street) {
    System.out.println(s + "   " + ((Street) s).getCity());

代码示例来源:origin: hankcs/HanLP

static void combineChain(TreeMap<String, String> s2t, TreeMap<String, String> t2x)
{
  for (Map.Entry<String, String> entry : s2t.entrySet())
  {
    String x = t2x.get(entry.getValue());
    if (x != null)
    {
      entry.setValue(x);
    }
  }
  for (Map.Entry<String, String> entry : t2x.entrySet())
  {
    String s = CharTable.convert(entry.getKey());
    if (!s2t.containsKey(s))
    {
      s2t.put(s, entry.getValue());
    }
  }
}

代码示例来源:origin: prestodb/presto

private final void assignNativeIds(int index, Object objectId, Object typeId)
{
  if (_nativeIds == null) {
    _nativeIds = new TreeMap<Integer,Object>();
  }
  if (objectId != null) {
    _nativeIds.put(_objectIdIndex(index), objectId);
  }
  if (typeId != null) {
    _nativeIds.put(_typeIdIndex(index), typeId);
  }
}

相关文章