java.util.HashMap.get()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(203)

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

HashMap.get介绍

[英]Returns the value of the mapping with the specified key.
[中]返回具有指定键的映射的值。

代码示例

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

public final int[] getIntArray(int argLength) {
 if (!aints.containsKey(argLength)) {
  aints.put(argLength, new int[argLength]);
 }
 assert (aints.get(argLength).length == argLength) : "Array not built with correct length";
 return aints.get(argLength);
}

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

private void mapKey(int orikey, int key) throws Exception {
  int orivalue = map.get(orikey);
  int value = map.get(key);
  ArrayList<Integer> oriKeyList = mapList.get(orivalue);
  ArrayList<Integer> keyList = mapList.get(value);
  for (Integer temp : oriKeyList) {
    map.put(temp, value);
    keyList.add(temp);
  }
  mapList.remove(orivalue);
}

代码示例来源:origin: alibaba/jstorm

public static <V> HashMap<V, Integer> multi_set(List<V> list) {
  HashMap<V, Integer> rtn = new HashMap<>();
  for (V v : list) {
    int cnt = 1;
    if (rtn.containsKey(v)) {
      cnt += rtn.get(v);
    }
    rtn.put(v, cnt);
  }
  return rtn;
}

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

/**
 * This method is used only for the analyze command to get the partition specs
 */
public TableSpec getTableSpec() {
 Iterator<String> tName = tableSpecs.keySet().iterator();
 return tableSpecs.get(tName.next());
}

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

public void add(Node node) {
  int level = node.getLevel();
  if (map.get(level) == null) {
    map.put(level, new ArrayList<>());
  }
  map.get(level).add(node);
}

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

private HashMap<String/* brokerName */, Set<MessageQueue>> buildProcessQueueTableByBrokerName() {
  HashMap<String, Set<MessageQueue>> result = new HashMap<String, Set<MessageQueue>>();
  for (MessageQueue mq : this.processQueueTable.keySet()) {
    Set<MessageQueue> mqs = result.get(mq.getBrokerName());
    if (null == mqs) {
      mqs = new HashSet<MessageQueue>();
      result.put(mq.getBrokerName(), mqs);
    }
    mqs.add(mq);
  }
  return result;
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testGenericMapWithKeyType() {
  GenericBean<?> gb = new GenericBean<>();
  BeanWrapper bw = new BeanWrapperImpl(gb);
  Map<String, String> input = new HashMap<>();
  input.put("4", "5");
  input.put("6", "7");
  bw.setPropertyValue("longMap", input);
  assertEquals("5", gb.getLongMap().get(new Long("4")));
  assertEquals("7", gb.getLongMap().get(new Long("6")));
}

代码示例来源:origin: kaushikgopal/RxJava-Android-Samples

private List<String> getListStringFromMap() {
 List<String> list = new ArrayList<>();
 for (String username : _contributionMap.keySet()) {
  String rowLog = String.format("%s [%d]", username, _contributionMap.get(username));
  list.add(rowLog);
 }
 return list;
}

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

public FindBrokerResult findBrokerAddressInSubscribe(
  final String brokerName,
  final long brokerId,
  final boolean onlyThisBroker
) {
  String brokerAddr = null;
  boolean slave = false;
  boolean found = false;
  HashMap<Long/* brokerId */, String/* address */> map = this.brokerAddrTable.get(brokerName);
  if (map != null && !map.isEmpty()) {
    brokerAddr = map.get(brokerId);
    slave = brokerId != MixAll.MASTER_ID;
    found = brokerAddr != null;
    if (!found && !onlyThisBroker) {
      Entry<Long, String> entry = map.entrySet().iterator().next();
      brokerAddr = entry.getValue();
      slave = entry.getKey() != MixAll.MASTER_ID;
      found = true;
    }
  }
  if (found) {
    return new FindBrokerResult(brokerAddr, slave, findBrokerVersion(brokerName, brokerAddr));
  }
  return null;
}

代码示例来源:origin: alibaba/jstorm

public void add(HashMap<String, ArrayList<TaskMessage>> workerTupleSetMap) {
  for (String key : workerTupleSetMap.keySet()) {
    ArrayList<ArrayList<TaskMessage>> bundle = bundles.get(key);
    if (null == bundle) {
      bundle = new ArrayList<>();
      bundles.put(key, bundle);
    }
    ArrayList tupleSet = workerTupleSetMap.get(key);
    if (null != tupleSet && tupleSet.size() > 0) {
      bundle.add(tupleSet);
    }
  }
}

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

public void setEnabled (ParticleEmitter emitter, boolean enabled) {
  ParticleData data = particleData.get(emitter);
  if (data == null) particleData.put(emitter, data = new ParticleData());
  data.enabled = enabled;
  emitter.reset();
}

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

@Override
  public void modifyOutputStream(JarOutputStream jarOut) throws IOException {
    for (String key : this.entries.keySet()) {
      jarOut.putNextEntry(new JarEntry(key));
      jarOut.write(this.entries.get(key).getBytes());
    }
  }
}

代码示例来源:origin: alibaba/jstorm

public static <V> HashMap<V, Integer> multi_set(List<V> list) {
  HashMap<V, Integer> rtn = new HashMap<V, Integer>();
  for (V v : list) {
    int cnt = 1;
    if (rtn.containsKey(v)) {
      cnt += rtn.get(v);
    }
    rtn.put(v, cnt);
  }
  return rtn;
}

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

private void calcAV() {
  System.out.println("count: "+left.size());
  Iterator<String> it = left.keySet().iterator();		
  while(it.hasNext()){
    String key = it.next();
    Double l = Math.log(left.get(key).size());
    Double r = Math.log(right.get(key).size());
    av.put(key, (int)Math.min(l, r));
  }
  System.out.println("av count: "+av.size());
}

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

public void addSeenOp(Task task, Operator operator) {
 List<Operator<?extends OperatorDesc>> seenOps = taskToSeenOps.get(task);
 if (seenOps == null) {
  taskToSeenOps.put(task, seenOps = new ArrayList<Operator<? extends OperatorDesc>>());
 }
 seenOps.add(operator);
}

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

/**
 * <code><pre>
 * type ::= string
 *      ::= int
 * </code></pre>
 */
private void writeType(String type)
    throws IOException {
  flushIfFull();
  int len = type.length();
  if (len == 0) {
    throw new IllegalArgumentException("empty type is not allowed");
  }
  if (_typeRefs == null)
    _typeRefs = new HashMap();
  Integer typeRefV = (Integer) _typeRefs.get(type);
  if (typeRefV != null) {
    int typeRef = typeRefV.intValue();
    writeInt(typeRef);
  } else {
    _typeRefs.put(type, Integer.valueOf(_typeRefs.size()));
    writeString(type);
  }
}

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

private void mapKey(int orikey, int key) throws Exception {
  int orivalue = map.get(orikey);
  int value = map.get(key);
  ArrayList<Integer> oriKeyList = mapList.get(orivalue);
  ArrayList<Integer> keyList = mapList.get(value);
  for (Integer temp : oriKeyList) {
    map.put(temp, value);
    keyList.add(temp);
  }
  mapList.remove(orivalue);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testGenericMapWithKeyTypeConstructor() {
  DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
  RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
  Map<String, String> input = new HashMap<>();
  input.put("4", "5");
  input.put("6", "7");
  rbd.getConstructorArgumentValues().addGenericArgumentValue(input);
  bf.registerBeanDefinition("genericBean", rbd);
  GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");
  assertEquals("5", gb.getLongMap().get(new Long("4")));
  assertEquals("7", gb.getLongMap().get(new Long("6")));
}

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

public final float[] getFloatArray(int argLength) {
 if (!afloats.containsKey(argLength)) {
  afloats.put(argLength, new float[argLength]);
 }
 assert (afloats.get(argLength).length == argLength) : "Array not built with correct length";
 return afloats.get(argLength);
}

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

public void setEnabled (ParticleEmitter emitter, boolean enabled) {
  ParticleData data = particleData.get(emitter);
  if (data == null) particleData.put(emitter, data = new ParticleData());
  data.enabled = enabled;
  emitter.reset();
}

相关文章