List of usage examples for java.util Map putAll
void putAll(Map<? extends K, ? extends V> m);
From source file:Main.java
/** * Clones the lhs map and add all things from the * rhs map.// ww w.ja va 2 s . c om * * @param lhs the first map * @param rhs the second map * @return the merged map */ public static Map merge(Map lhs, Map rhs) { Map result = null; if ((lhs == null) || (lhs.size() == 0)) { result = copy(rhs); } else if ((rhs == null) || (rhs.size() == 0)) { result = copy(lhs); } else { result = copy(lhs); result.putAll(rhs); } return result; }
From source file:com.etsy.arbiter.util.NamedArgumentInterpolator.java
private static Map<String, String> createFinalInterpolationMap(final Map<String, String> namedArgs, final Map<String, String> defaultArgs) { Map<String, String> interpolationArgs = new HashMap<>(); if (defaultArgs != null) { // We want entries from namedArgs to overwrite entries from defaultArgs interpolationArgs.putAll(defaultArgs); interpolationArgs.putAll(namedArgs); } else {//from w w w.j ava 2 s. com interpolationArgs.putAll(namedArgs); } return interpolationArgs; }
From source file:com.vmware.bdd.plugin.ambari.utils.AmUtils.java
public static List<Map<String, Object>> toAmConfigurations(List<Map<String, Object>> configurations, String configurationType, Map<String, String> property) { if (configurations == null) { configurations = new ArrayList<Map<String, Object>>(); }/*from w w w .j a v a2 s . c o m*/ Map<String, Object> configuration = new HashMap<String, Object>(); configuration.put(configurationType, property); if (configurations.isEmpty()) { configurations.add(configuration); } else { boolean isContainsKey = false; for (Map<String, Object> nodeConfiguration : configurations) { if (nodeConfiguration.containsKey(configurationType)) { Map<String, String> properties = (Map<String, String>) nodeConfiguration.get(configurationType); properties.putAll(property); isContainsKey = true; } } if (!isContainsKey) { configurations.add(configuration); } } return configurations; }
From source file:eu.edisonproject.classification.main.BatchMain.java
private static void profile(String csvFile1, String csvFile2, String output) throws IOException, Exception { Map<String, Collection<Double>> cv = CSVFileReader.csvCompetanceToMap(csvFile1, ",", Boolean.TRUE); Map<String, Collection<Double>> jobVec = CSVFileReader.csvCompetanceToMap(csvFile2, ",", Boolean.TRUE); CosineSimilarityMatrix cosineFunction = new CosineSimilarityMatrix(); String k1 = cv.keySet().iterator().next(); Map<String, Double> winners = new HashMap<>(); for (String k : jobVec.keySet()) { Collection<Double> j = jobVec.get(k); double d = cosineFunction.computeDistance(cv.get(k1), j); // if (!Double.isNaN(d)) { winners.put(k, d);/* w w w.j ava 2s . co m*/ // } } StringBuilder lines = new StringBuilder(); ReaderFile rf = new ReaderFile(csvFile1); String fileHeader = rf.readFileWithN().split("\n")[0]; String[] header = fileHeader.split(","); lines.append("rank").append(","); lines.append(fileHeader); lines.append("\n"); int rank = 0; JSONObject cvJson = new JSONObject(); Collection<Double> vector = cv.get(k1); String val = vector.toString().replaceAll("\\[", "").replaceAll("\\]", ""); lines.append(rank).append(",").append(k1).append(",").append(val).append("\n"); Iterator<Double> iter = vector.iterator(); int i = 0; cvJson.put(header[i++], k1); while (iter.hasNext()) { String key = header[i++]; Double value = iter.next(); cvJson.put(key, value); } cvJson.put("rank", rank); JSONArray profileJson = new JSONArray(); profileJson.add(cvJson); ValueComparator bvc = new ValueComparator(winners); Map<String, Double> sorted_map = new TreeMap(bvc); sorted_map.putAll(winners); for (String k : sorted_map.keySet()) { JSONObject jobJason = new JSONObject(); rank++; vector = jobVec.get(k); val = vector.toString().replaceAll("\\[", "").replaceAll("\\]", ""); lines.append(rank).append(",").append(k).append(",").append(val).append("\n"); i = 0; jobJason.put(header[i++], k); iter = vector.iterator(); while (iter.hasNext()) { String key = header[i++]; Double value = iter.next(); jobJason.put(key, value); } jobJason.put("rank", rank); profileJson.add(jobJason); } WriterFile wf = new WriterFile(output + File.separator + "result.csv"); wf.writeFile(lines.toString()); wf = new WriterFile(output + File.separator + "result.json"); wf.writeFile(profileJson.toJSONString()); }
From source file:cn.crawin.msg.gateway.http.SignUtil.java
/** * ??Http//from w ww .ja v a 2 s .co m * * @param headers Http * @param signHeaderPrefixList ???Header? * @return ??Http */ private static String buildHeaders(Map<String, String> headers, List<String> signHeaderPrefixList) { StringBuilder sb = new StringBuilder(); if (null != signHeaderPrefixList) { signHeaderPrefixList.remove(SystemHeader.X_CA_SIGNATURE); signHeaderPrefixList.remove(HttpHeader.HTTP_HEADER_ACCEPT); signHeaderPrefixList.remove(HttpHeader.HTTP_HEADER_CONTENT_MD5); signHeaderPrefixList.remove(HttpHeader.HTTP_HEADER_CONTENT_TYPE); signHeaderPrefixList.remove(HttpHeader.HTTP_HEADER_DATE); Collections.sort(signHeaderPrefixList); if (null != headers) { Map<String, String> sortMap = new TreeMap<String, String>(); sortMap.putAll(headers); StringBuilder signHeadersStringBuilder = new StringBuilder(); for (Map.Entry<String, String> header : sortMap.entrySet()) { if (isHeaderToSign(header.getKey(), signHeaderPrefixList)) { sb.append(header.getKey()); sb.append(Constants.SPE2); if (!StringUtils.isBlank(header.getValue())) { sb.append(header.getValue()); } sb.append(Constants.LF); if (0 < signHeadersStringBuilder.length()) { signHeadersStringBuilder.append(Constants.SPE1); } signHeadersStringBuilder.append(header.getKey()); } } headers.put(SystemHeader.X_CA_SIGNATURE_HEADERS, signHeadersStringBuilder.toString()); } } return sb.toString(); }
From source file:com.etsy.arbiter.config.ConfigurationMerger.java
/** * Merge a collection of maps//from w w w. j a v a 2 s . c om * * @param actionTypes The collection of ActionTypes * @param transformFunction The function that produces a map from an ActionType * @param <T> The type of values in the map * @return A Map representing the merger of all input maps */ public static <T> Map<String, T> mergeMaps(Collection<ActionType> actionTypes, Function<ActionType, Map<String, T>> transformFunction) { Collection<Map<String, T>> values = Collections2.transform(actionTypes, transformFunction); Map<String, T> result = new HashMap<>(); for (Map<String, T> map : values) { result.putAll(map); } return result; }
From source file:com.streamsets.pipeline.lib.util.AvroSchemaHelper.java
/** * Helper method to extract default values from a Schema. This is normally done * in DataGeneratorFormat validation, however we have to do it at runtime for * Schema Registry./*w w w .j av a 2 s. co m*/ * @param schema schema to extract default values from * @return map of default value * @throws SchemaRegistryException */ public static Map<String, Object> getDefaultValues(Schema schema) throws SchemaRegistryException { Map<String, Object> defaultValues = new HashMap<>(); try { defaultValues.putAll(AvroTypeUtil.getDefaultValuesFromSchema(schema, new HashSet<String>())); } catch (IOException e) { throw new SchemaRegistryException(e); } return defaultValues; }
From source file:com.sixt.service.framework.servicetest.helper.DockerComposeHelper.java
@SuppressWarnings("unchecked") private static void setEnv(Map<String, String> newEnv) { try {//from w ww. j a v a 2 s. com Class<?> processEnvironmentClass = Class.forName("java.lang.ProcessEnvironment"); Field theEnvironmentField = processEnvironmentClass.getDeclaredField("theEnvironment"); theEnvironmentField.setAccessible(true); Map<String, String> env = (Map<String, String>) theEnvironmentField.get(null); env.putAll(newEnv); Field theCaseInsensitiveEnvironmentField = processEnvironmentClass .getDeclaredField("theCaseInsensitiveEnvironment"); theCaseInsensitiveEnvironmentField.setAccessible(true); Map<String, String> cienv = (Map<String, String>) theCaseInsensitiveEnvironmentField.get(null); cienv.putAll(newEnv); } catch (NoSuchFieldException e) { try { Class[] classes = Collections.class.getDeclaredClasses(); Map<String, String> env = System.getenv(); for (Class cl : classes) { if ("java.util.Collections$UnmodifiableMap".equals(cl.getName())) { Field field = cl.getDeclaredField("m"); field.setAccessible(true); Object obj = field.get(env); Map<String, String> map = (Map<String, String>) obj; map.clear(); map.putAll(newEnv); } } } catch (Exception e2) { e2.printStackTrace(); } } catch (Exception e1) { e1.printStackTrace(); } }
From source file:au.org.ala.layers.util.BatchProducer.java
public static void addInfoToMap(String batchPath, String batchId, Map map) throws IOException { Map more = (Map) log.get(batchId); if (more != null) { map.putAll(more); } else {//w ww.ja v a2 s . c o m String dir = batchPath + File.separator + batchId + File.separator; if (new File(dir).exists()) { int count = 0; if (new File(dir + "error.txt").exists()) { count++; map.put("error", readFile(dir + "error.txt")); map.put("status", "error"); } if (new File(dir + "finished.txt").exists()) { count++; map.put("finished", readFile(dir + "finished.txt")); map.put("status", "finished"); } if (new File(dir + "started.txt").exists()) { if (count == 0) { //count points map.put("points", getPointCount(batchPath, batchId)); //count fields int fieldCount = getFieldCount(batchPath, batchId); map.put("fields", fieldCount); map.put("progress", 0); } count++; map.put("started", readFile(dir + "started.txt")); map.put("status", "started"); } if (count == 0) { map.put("waiting", "In queue"); map.put("status", "waiting"); } } else { map.put("error", "unknown batchId: " + batchId); } log.put(batchId, map); } }
From source file:com.cloudera.recordservice.tests.ClusterController.java
/** * This method allows the caller to add environment variables to the JVM. * There is no easy way to do this through a simple call, such as there is to * read env variables using System.getEnv(variableName). Much of the method * was written with guidance from stack overflow: * http://stackoverflow.com/questions/*from w w w . j a v a 2s.c o m*/ * /318239/how-do-i-set-environment-variables-from-java */ protected static void setEnv(Map<String, String> newenv) { try { Class<?> processEnvironmentClass = Class.forName("java.lang.ProcessEnvironment"); Field theEnvironmentField = processEnvironmentClass.getDeclaredField("theEnvironment"); theEnvironmentField.setAccessible(true); Map<String, String> env = (Map<String, String>) theEnvironmentField.get(null); env.putAll(newenv); Field theCaseInsensitiveEnvironmentField = processEnvironmentClass .getDeclaredField("theCaseInsensitiveEnvironment"); theCaseInsensitiveEnvironmentField.setAccessible(true); Map<String, String> cienv = (Map<String, String>) theCaseInsensitiveEnvironmentField.get(null); cienv.putAll(newenv); } catch (NoSuchFieldException e) { try { Class[] classes = Collections.class.getDeclaredClasses(); Map<String, String> env = System.getenv(); for (Class cl : classes) { if ("java.util.Collections$UnmodifiableMap".equals(cl.getName())) { Field field = cl.getDeclaredField("m"); field.setAccessible(true); Object obj = field.get(env); Map<String, String> map = (Map<String, String>) obj; map.clear(); map.putAll(newenv); } } } catch (Exception e2) { e2.printStackTrace(); } } catch (Exception e1) { e1.printStackTrace(); } }