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

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

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

HashMap.putAll介绍

[英]Copies all the mappings in the specified map to this map. These mappings will replace all mappings that this map had for any of the keys currently in the given map.
[中]将指定映射中的所有映射复制到此映射。这些映射将替换此映射对给定映射中当前任何键的所有映射。

代码示例

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

private Map<String, Object> getParameterMap() {
 HashMap<String, Object> parameterMap = new HashMap<String, Object>();
 parameterMap.put("sql", sqlStatement);
 parameterMap.putAll(parameters);
 return parameterMap;
}

代码示例来源:origin: reactor/reactor-core

ContextN(Map<Object, Object> map, Object key, Object value) {
  super(map.size() + 1, 1f);
  super.putAll(map);
  super.put(key, value);
}

代码示例来源:origin: stanfordnlp/CoreNLP

private HashMap<String,String> getPOSFeatures(String word, String pos) {
 HashMap<String, String> features = new HashMap<>();
 String wordPos = word.toLowerCase() + '_' + pos;
 if (wordPosFeatureMap.containsKey(wordPos)) {
   features.putAll(wordPosFeatureMap.get(wordPos));
 } else if (posFeatureMap.containsKey(pos)) {
  features.putAll(posFeatureMap.get(pos));
 }
 if (isOrdinal(word, pos)) {
  features.put("NumType", "Ord");
 }
 if (isMultiplicative(word, pos)) {
  features.put("NumType", "Mult");
 }
 return features;
}

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

public static Response buildMessage(int httpCode, Map<String, Object> params,
          String msg) {
  HashMap<String, Object> err = new HashMap<String, Object>();
  err.put("error", msg);
  if (params != null)
   err.putAll(params);

  String json = "\"error\"";
  try {
   json = new ObjectMapper().writeValueAsString(err);
  } catch (IOException e) {
  }

  return Response.status(httpCode)
   .entity(json)
   .type(MediaType.APPLICATION_JSON)
   .build();
 }
}

代码示例来源:origin: Sable/soot

@Override
 protected void merge(HashMap<Value, Integer> in1, HashMap<Value, Integer> in2, HashMap<Value, Integer> out) {
  // Copy over in1. This will be the baseline
  out.putAll(in1);

  // Merge in in2. Make sure that we do not have ambiguous values.
  for (Value val : in2.keySet()) {
   Integer i1 = in1.get(val);
   Integer i2 = in2.get(val);
   if (i2.equals(i1)) {
    out.put(val, i2);
   } else {
    throw new RuntimeException("Merge of different IDs not supported");
   }
  }
 }
}

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

public static String createJsonResponse(final String status, final String message,
  final String action, final Map<String, Object> params) {
 final HashMap<String, Object> response = new HashMap<>();
 response.put("status", status);
 if (message != null) {
  response.put("message", message);
 }
 if (action != null) {
  response.put("action", action);
 }
 if (params != null) {
  response.putAll(params);
 }
 return JSONUtils.toJSON(response);
}

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

VirtualNodeHack( final String label, Map<String,Object> properties )
{
  this.id = MIN_ID.getAndDecrement();
  this.label = Label.label( label );
  propertyMap.putAll( properties );
  propertyMap.put( "name", label );
}

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

@Override
@SuppressWarnings("unchecked")
public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> options) {
  addValidOptions(ALL_VALID_OPTIONS);
  this.realm = options.containsKey(REALM_OPTION) ? (String) options.get(REALM_OPTION) : DEFAULT_REALM;
  HashMap map = new HashMap(options);
  map.putAll(options);
  map.put("hashAlgorithm", "REALM");
  map.put("hashStorePassword", "false");
  super.initialize(subject, callbackHandler, sharedState, map);
}

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

protected Map<String, Object> collectTransientVariables(HashMap<String, Object> variables) {
 VariableScopeImpl parentScope = getParentVariableScope();
 if (parentScope != null) {
  variables.putAll(parentScope.collectVariables(variables));
 }
 
 if (transientVariabes != null) {
  for (String variableName : transientVariabes.keySet()) {
   variables.put(variableName, transientVariabes.get(variableName).getValue());
  }
 }
 return variables;
}

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

/**
 * Build the environment used for all exec calls.
 *
 * @return The environment variables.
 */
public Map<String, String> execEnv(Map<String, String> env) {
 HashMap<String, String> res = new HashMap<String, String>();
 for (String key : appConf.getStrings(AppConfig.EXEC_ENVS_NAME)) {
  String val = System.getenv(key);
  if (val != null) {
   res.put(key, val);
  }
 }
 if (env != null)
  res.putAll(env);
 for (Map.Entry<String, String> envs : res.entrySet()) {
  LOG.info("Env " + envs.getKey() + "=" + envs.getValue());
 }
 return res;
}

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

/**
 * <p>Get {@link Node} of the specific origin. Usually the origin is the Service Consumer's app name.</p>
 * <p>If the origin node for given origin is absent, then a new {@link StatisticNode}
 * for the origin will be created and returned.</p>
 *
 * @param origin The caller's name, which is designated in the {@code parameter} parameter
 *               {@link ContextUtil#enter(String name, String origin)}.
 * @return the {@link Node} of the specific origin
 */
public Node getOrCreateOriginNode(String origin) {
  StatisticNode statisticNode = originCountMap.get(origin);
  if (statisticNode == null) {
    try {
      lock.lock();
      statisticNode = originCountMap.get(origin);
      if (statisticNode == null) {
        // The node is absent, create a new node for the origin.
        statisticNode = new StatisticNode();
        HashMap<String, StatisticNode> newMap = new HashMap<String, StatisticNode>(
          originCountMap.size() + 1);
        newMap.putAll(originCountMap);
        newMap.put(origin, statisticNode);
        originCountMap = newMap;
      }
    } finally {
      lock.unlock();
    }
  }
  return statisticNode;
}

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

protected Map<String, VariableInstance> collectVariableInstances(HashMap<String, VariableInstance> variables) {
 ensureVariableInstancesInitialized();
 VariableScopeImpl parentScope = getParentVariableScope();
 if (parentScope != null) {
  variables.putAll(parentScope.collectVariableInstances(variables));
 }
 for (VariableInstance variableInstance : variableInstances.values()) {
  variables.put(variableInstance.getName(), variableInstance);
 }
 for (String variableName : usedVariablesCache.keySet()) {
  variables.put(variableName, usedVariablesCache.get(variableName));
 }
 
 if (transientVariabes != null) {
  variables.putAll(transientVariabes);
 }
 return variables;
}

代码示例来源:origin: com.h2database/h2

/**
 * Update session meta data information and get the information in a map.
 *
 * @return a map containing the session meta data
 */
HashMap<String, Object> getInfo() {
  HashMap<String, Object> m = new HashMap<>(map.size() + 5);
  m.putAll(map);
  m.put("lastAccess", new Timestamp(lastAccess).toString());
  try {
    m.put("url", conn == null ?
        "${text.admin.notConnected}" : conn.getMetaData().getURL());
    m.put("user", conn == null ?
        "-" : conn.getMetaData().getUserName());
    m.put("lastQuery", commandHistory.isEmpty() ?
        "" : commandHistory.get(0));
    m.put("executing", executingStatement == null ?
        "${text.admin.no}" : "${text.admin.yes}");
  } catch (SQLException e) {
    DbException.traceThrowable(e);
  }
  return m;
}

代码示例来源:origin: igniterealtime/Smack

@Override
public HashMap<Integer, T_Sess> loadAllRawSessionsOf(OmemoDevice userDevice, BareJid contact) {
  HashMap<Integer, T_Sess> sessions = getCache(userDevice).sessions.get(contact);
  if (sessions == null) {
    sessions = new HashMap<>();
    getCache(userDevice).sessions.put(contact, sessions);
  }
  if (sessions.isEmpty() && persistent != null) {
    sessions.putAll(persistent.loadAllRawSessionsOf(userDevice, contact));
  }
  return new HashMap<>(sessions);
}

代码示例来源:origin: NLPchina/elasticsearch-sql

protected void  onlyReturnedFields(Map<String, Object> fieldsMap, List<Field> required,boolean allRequired) {
  HashMap<String,Object> filteredMap = new HashMap<>();
  if(allFieldsReturn || allRequired) {
    filteredMap.putAll(fieldsMap);
    return;
  }
  for(Field field: required){
    String name = field.getName();
    String returnName = name;
    String alias = field.getAlias();
    if(alias !=null && alias !=""){
      returnName = alias;
      aliasesOnReturn.add(alias);
    }
    filteredMap.put(returnName, deepSearchInMap(fieldsMap, name));
  }
  fieldsMap.clear();
  fieldsMap.putAll(filteredMap);
}

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

public String[][] getHeaders(Object value, Operation operation) throws ServiceException {
  Response delegate = (Response) value;
  HashMap map = new HashMap();
  if (delegate.getContentDisposition() != null) {
    map.put("Content-Disposition", delegate.getContentDisposition());
  }
  HashMap m = delegate.getResponseHeaders();
  if (m != null && !m.isEmpty()) {
    map.putAll(m);
  }
  if (map == null || map.isEmpty()) return null;
  String[][] headers = new String[map.size()][2];
  List keys = new ArrayList(map.keySet());
  for (int i = 0; i < headers.length; i++) {
    headers[i][0] = (String) keys.get(i);
    headers[i][1] = (String) map.get(keys.get(i));
  }
  return headers;
}

代码示例来源:origin: Sable/soot

protected void flowThrough(HashMap<Local, Set<NewExpr>> in, Unit unit, HashMap<Local, Set<NewExpr>> out) {
 Stmt s = (Stmt) unit;
 out.clear();
 out.putAll(in);
 if (s instanceof DefinitionStmt) {
  DefinitionStmt ds = (DefinitionStmt) s;
  Value lhs = ds.getLeftOp();
  Value rhs = ds.getRightOp();
  if (lhs instanceof Local) {
   HashSet<NewExpr> lv = new HashSet<NewExpr>();
   out.put((Local) lhs, lv);
   if (rhs instanceof NewExpr) {
    lv.add((NewExpr) rhs);
   } else if (rhs instanceof Local) {
    lv.addAll(in.get(rhs));
   } else {
    lv.add(UNKNOWN);
   }
  }
 }
}

代码示例来源:origin: Graylog2/graylog2-server

@AssistedInject
public MessageCountAlertCondition(Searches searches,
                 @Assisted Stream stream,
                 @Nullable @Assisted("id") String id,
                 @Assisted DateTime createdAt,
                 @Assisted("userid") String creatorUserId,
                 @Assisted Map<String, Object> parameters,
                 @Nullable @Assisted("title") String title) {
  super(stream, id, Type.MESSAGE_COUNT.toString(), createdAt, creatorUserId, parameters, title);
  this.searches = searches;
  this.time = Tools.getNumber(parameters.get("time"), 5).intValue();
  final String thresholdType = (String) parameters.get("threshold_type");
  final String upperCaseThresholdType = thresholdType.toUpperCase(Locale.ENGLISH);
  /*
   * Alert conditions created before 2.2.0 had a threshold_type parameter in lowercase, but this was
   * inconsistent with the parameters in FieldValueAlertCondition, which were always stored in uppercase.
   * To ensure we return the expected case in the API and also store the right case in the database, we
   * are converting the parameter to uppercase here, if it wasn't uppercase already.
   */
  if (!thresholdType.equals(upperCaseThresholdType)) {
    final HashMap<String, Object> updatedParameters = new HashMap<>();
    updatedParameters.putAll(parameters);
    updatedParameters.put("threshold_type", upperCaseThresholdType);
    super.setParameters(updatedParameters);
  }
  this.thresholdType = ThresholdType.valueOf(upperCaseThresholdType);
  this.threshold = Tools.getNumber(parameters.get("threshold"), 0).intValue();
  this.query = (String) parameters.getOrDefault(CK_QUERY, CK_QUERY_DEFAULT_VALUE);
}

代码示例来源:origin: json-iterator/java

private static Map<String, Type> collectTypeVariableLookup(Type type) {
  HashMap<String, Type> vars = new HashMap<String, Type>();
  if (null == type) {
    return vars;
  }
  if (type instanceof ParameterizedType) {
    ParameterizedType pType = (ParameterizedType) type;
    Type[] actualTypeArguments = pType.getActualTypeArguments();
    Class clazz = (Class) pType.getRawType();
    for (int i = 0; i < clazz.getTypeParameters().length; i++) {
      TypeVariable variable = clazz.getTypeParameters()[i];
      vars.put(variable.getName() + "@" + clazz.getCanonicalName(), actualTypeArguments[i]);
    }
    vars.putAll(collectTypeVariableLookup(clazz.getGenericSuperclass()));
    return vars;
  }
  if (type instanceof Class) {
    Class clazz = (Class) type;
    vars.putAll(collectTypeVariableLookup(clazz.getGenericSuperclass()));
    return vars;
  }
  if (type instanceof WildcardType) {
    return vars;
  }
  throw new JsonException("unexpected type: " + type);
}

代码示例来源:origin: JetBrains/ideavim

@Nullable
private HashMap<Character, Mark> getAllFileMarks(@NotNull final Document doc) {
 VirtualFile vf = FileDocumentManager.getInstance().getFile(doc);
 if (vf == null) {
  return null;
 }
 HashMap<Character, Mark> res = new HashMap<>();
 FileMarks<Character, Mark> fileMarks = getFileMarks(doc);
 if (fileMarks != null) {
  res.putAll(fileMarks);
 }
 for (Character ch : globalMarks.keySet()) {
  Mark mark = globalMarks.get(ch);
  if (vf.getPath().equals(mark.getFilename())) {
   res.put(ch, mark);
  }
 }
 return res;
}

相关文章