java.util.TreeMap类的使用及代码示例

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

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

TreeMap介绍

[英]Walk the nodes of the tree left-to-right or right-to-left. Note that in descending iterations, next will return the previous node.
[中]从左向右或从右向左遍历树的节点。注意,在递减迭代中,next将返回上一个节点。

代码示例

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

@Override
 protected SortedMap<String, String> create(Entry<String, String>[] entries) {
  /*
   * TODO(cpovirk): it would be nice to create an input Map and use
   * the copy constructor here and in the other tests
   */
  return populate(new TreeMap<String, String>(), entries);
 }
})

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

private void setSegmentSignature(final DataSegment segment, final SegmentMetadataHolder segmentMetadataHolder)
{
 synchronized (lock) {
  TreeMap<DataSegment, SegmentMetadataHolder> dataSourceSegments = segmentMetadataInfo.computeIfAbsent(
    segment.getDataSource(),
    x -> new TreeMap<>(SEGMENT_ORDER)
  );
  if (dataSourceSegments.put(segment, segmentMetadataHolder) == null) {
   totalSegments++;
  }
 }
}

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

@Override
public void add(Integer value) {
  Integer current = treeMap.get(value);
  Integer newValue = (current != null ? current : 0) + 1;
  this.treeMap.put(value, newValue);
}

代码示例来源: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: 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: hankcs/HanLP

/**
 * 克隆一个状态<br>
 * Constructs an MDAGNode possessing the same accept state status and outgoing transitions as another.
 
 * @param node      the MDAGNode possessing the accept state status and 
 *                  outgoing transitions that the to-be-created MDAGNode is to take on
 */
private MDAGNode(MDAGNode node)
{
  isAcceptNode = node.isAcceptNode;
  outgoingTransitionTreeMap = new TreeMap<Character, MDAGNode>(node.outgoingTransitionTreeMap);
  
  //Loop through the nodes in this node's outgoing _transition set, incrementing the number of
  //incoming transitions of each by 1 (to account for this newly created node's outgoing transitions)
  for(Entry<Character, MDAGNode> transitionKeyValuePair : outgoingTransitionTreeMap.entrySet())
    transitionKeyValuePair.getValue().incomingTransitionCount++;
  /////
}

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

private static void addKeyword(TreeMap<String, String> patternMap, String keyword)
{
  patternMap.put(keyword, keyword);
}
static

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

static void combineReverseChain(TreeMap<String, String> t2s, TreeMap<String, String> tw2t, boolean convert)
{
  for (Map.Entry<String, String> entry : tw2t.entrySet())
  {
    String tw = entry.getKey();
    String s = t2s.get(entry.getValue());
    if (s == null)
      s = convert ? CharTable.convert(entry.getValue()) : entry.getValue();
    t2s.put(tw, s);
  }
}

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

public void testTreeMapNonGeneric() {
 TreeMap<LegacyComparable, Integer> map = Maps.newTreeMap();
 assertEquals(Collections.emptyMap(), map);
 map.put(new LegacyComparable("foo"), 1);
 map.put(new LegacyComparable("bar"), 2);
 assertThat(map.keySet())
   .containsExactly(new LegacyComparable("bar"), new LegacyComparable("foo"))
   .inOrder();
 assertThat(map.values()).containsExactly(2, 1).inOrder();
 assertNull(map.comparator());
}

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

@Override
public Double get(Object key)
{
  Double v = super.get(key);
  if (v == null) return 0.;
  return v;
}

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

/**
 * Replaces all the current loaded Rs with the given ones.
 */
public synchronized void reset(TreeMap<Integer,R> builds) {
  Index index = new Index();
  for (R r : builds.values()) {
    BuildReference<R> ref = createReference(r);
    index.byNumber.put(getNumberOf(r),ref);
  }
  this.index = index;
}

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

/**
 * {@inheritDoc}
 */
public int enter() {
  return instrumentedMethod.getStackSize()
      + exitType.getStackSize().getSize()
      + StackSize.of(namedTypes.values());
}

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

public int build(TreeMap<String, Integer> keyValueMap)
{
  idToLabelMap = new String[keyValueMap.size()];
  for (Map.Entry<String, Integer> entry : keyValueMap.entrySet())
  {
    idToLabelMap[entry.getValue()] = entry.getKey();
  }
  return trie.build(keyValueMap);
}

代码示例来源: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: redisson/redisson

/**
 * {@inheritDoc}
 */
public List<TypeDescription> getNamedTypes() {
  List<TypeDescription> namedTypes = new ArrayList<TypeDescription>(this.namedTypes.size());
  for (TypeDefinition typeDefinition : this.namedTypes.values()) {
    namedTypes.add(typeDefinition.asErasure());
  }
  return namedTypes;
}

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

/**
 * 本状态的目标状态们的入度减一
 * Decrements (by 1) the incoming _transition counts of all of the nodes
 * that are targets of outgoing transitions from this node.
 */
public void decrementTargetIncomingTransitionCounts()
{
  for(Entry<Character, MDAGNode> transitionKeyValuePair: outgoingTransitionTreeMap.entrySet())
    transitionKeyValuePair.getValue().incomingTransitionCount--;
}

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

public static String toQueryString(Map<String, String> ps) {
  StringBuilder buf = new StringBuilder();
  if (ps != null && ps.size() > 0) {
    for (Map.Entry<String, String> entry : new TreeMap<String, String>(ps).entrySet()) {
      String key = entry.getKey();
      String value = entry.getValue();
      if (isNoneEmpty(key, value)) {
        if (buf.length() > 0) {
          buf.append("&");
        }
        buf.append(key);
        buf.append("=");
        buf.append(value);
      }
    }
  }
  return buf.toString();
}

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

/**
 * 建立一条边(起点是自己)
 * @param letter 边上的字符串
 * @param newTargetNode 边的重点
 * @return 终点
 */
public MDAGNode addOutgoingTransition(char letter, MDAGNode newTargetNode)
{
  newTargetNode.incomingTransitionCount++;
  outgoingTransitionTreeMap.put(letter, newTargetNode);
  return newTargetNode;
}

代码示例来源: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: google/guava

public void testTreeMapDerived() {
 TreeMap<Derived, Integer> map = Maps.newTreeMap();
 assertEquals(Collections.emptyMap(), map);
 map.put(new Derived("foo"), 1);
 map.put(new Derived("bar"), 2);
 assertThat(map.keySet()).containsExactly(new Derived("bar"), new Derived("foo")).inOrder();
 assertThat(map.values()).containsExactly(2, 1).inOrder();
 assertNull(map.comparator());
}

相关文章