List of usage examples for java.util Map putAll
void putAll(Map<? extends K, ? extends V> m);
From source file:adalid.commons.util.FilUtils.java
public static Map<String, File> parentDirectoriesMap(File file, File top) { Map<String, File> map = new LinkedHashMap<>(); File parent;//from w ww. j a va 2 s.c o m File topdir = isVisibleDirectory(top) ? top : null; if (isVisibleDirectory(file) || isVisibleFile(file)) { parent = file.getParentFile(); if (isVisibleDirectory(parent)) { if (parent.equals(topdir)) { } else { map.putAll(parentDirectoriesMap(parent, topdir)); map.put(parent.getPath(), parent); } } } return map; }
From source file:Main.java
public static Map<? extends Object, ? extends Double> merge(Map<? extends Object, ? extends Double> map1, Map<? extends Object, ? extends Double> map2) { Map<Object, Double> result = new HashMap<Object, Double>(); Map<? extends Object, ? extends Double> biggerMap = map1.size() > map2.size() ? map1 : map2; Map<? extends Object, ? extends Double> smallerMap = map1.size() > map2.size() ? map2 : map1; for (Entry<? extends Object, ? extends Double> entry : smallerMap.entrySet()) { Object key = entry.getKey(); Double value = entry.getValue(); Double value2 = (Double) getValue(biggerMap, key, Double.class); value2 += value;/*w ww . j a va 2s. co m*/ result.put(key, value2); biggerMap.remove(key); } result.putAll(biggerMap); return sortByValueDesc(result); }
From source file:backtype.storm.StormSubmitter.java
/** * Submits a topology to run on the cluster. A topology runs forever or * until explicitly killed.//from w ww . j a va 2 s . c o m * * * @param name the name of the storm. * @param stormConf the topology-specific configuration. See {@link Config}. * @param topology the processing to execute. * @param options to manipulate the starting of the topology * @throws AlreadyAliveException if a topology with this name is already * running * @throws InvalidTopologyException if an invalid topology was submitted */ public static void submitTopology(String name, Map stormConf, StormTopology topology, SubmitOptions opts) throws AlreadyAliveException, InvalidTopologyException { if (!Utils.isValidConf(stormConf)) { throw new IllegalArgumentException("Storm conf is not valid. Must be json-serializable"); } stormConf = new HashMap(stormConf); stormConf.putAll(Utils.readCommandLineOpts()); Map conf = Utils.readStormConfig(); conf.putAll(stormConf); putUserInfo(conf, stormConf); try { String serConf = Utils.to_json(stormConf); if (localNimbus != null) { LOG.info("Submitting topology " + name + " in local mode"); localNimbus.submitTopology(name, null, serConf, topology); } else { NimbusClient client = NimbusClient.getConfiguredClient(conf); try { if (topologyNameExists(client, conf, name)) { throw new RuntimeException("Topology with name `" + name + "` already exists on cluster"); } submitJar(client, conf); LOG.info("Submitting topology " + name + " in distributed mode with conf " + serConf); if (opts != null) { client.getClient().submitTopologyWithOpts(name, path, serConf, topology, opts); } else { // this is for backwards compatibility client.getClient().submitTopology(name, path, serConf, topology); } } finally { client.close(); } } LOG.info("Finished submitting topology: " + name); } catch (InvalidTopologyException e) { LOG.warn("Topology submission exception", e); throw e; } catch (AlreadyAliveException e) { LOG.warn("Topology already alive exception", e); throw e; } catch (TopologyAssignException e) { LOG.warn("Failed to assign " + e.get_msg(), e); throw new RuntimeException(e); } catch (TException e) { LOG.warn("Failed to assign ", e); throw new RuntimeException(e); } }
From source file:ar.com.fdvs.dj.core.DynamicJasperHelper.java
/** * For running queries embebed in the report design * @param dr/*from w w w .j a va 2 s .c o m*/ * @param layoutManager * @param con * @param _parameters * @return * @throws JRException */ public static JasperPrint generateJasperPrint(DynamicReport dr, LayoutManager layoutManager, Connection con, Map _parameters) throws JRException { log.info("generating JasperPrint"); JasperPrint jp = null; if (_parameters == null) _parameters = new HashMap(); visitSubreports(dr, _parameters); compileOrLoadSubreports(dr, _parameters); DynamicJasperDesign jd = generateJasperDesign(dr); Map params = new HashMap(); if (!_parameters.isEmpty()) { registerParams(jd, _parameters); params.putAll(_parameters); } registerEntities(jd, dr, layoutManager); layoutManager.applyLayout(jd, dr); JRProperties.setProperty(JRCompiler.COMPILER_PREFIX, DJCompilerFactory.getCompilerClassName()); JasperReport jr = JasperCompileManager.compileReport(jd); params.putAll(jd.getParametersWithValues()); jp = JasperFillManager.fillReport(jr, params, con); return jp; }
From source file:ar.com.fdvs.dj.core.DynamicJasperHelper.java
/** * For compiling and filling reports whose datasource is passed as parameter (e.g. Hibernate, Mondrean, etc.) * @param dr//from w w w . j a va 2 s. c o m * @param layoutManager * @param _parameters * @return * @throws JRException */ public static JasperPrint generateJasperPrint(DynamicReport dr, LayoutManager layoutManager, Map _parameters) throws JRException { log.info("generating JasperPrint"); JasperPrint jp = null; if (_parameters == null) _parameters = new HashMap(); visitSubreports(dr, _parameters); compileOrLoadSubreports(dr, _parameters); DynamicJasperDesign jd = generateJasperDesign(dr); Map params = new HashMap(); if (!_parameters.isEmpty()) { registerParams(jd, _parameters); params.putAll(_parameters); } registerEntities(jd, dr, layoutManager); layoutManager.applyLayout(jd, dr); // JRProperties.setProperty(JRProperties.COMPILER_CLASS, DJCompilerFactory.getCompilerClassName()); JRProperties.setProperty(JRCompiler.COMPILER_PREFIX, DJCompilerFactory.getCompilerClassName()); JasperReport jr = JasperCompileManager.compileReport(jd); params.putAll(jd.getParametersWithValues()); jp = JasperFillManager.fillReport(jr, params); return jp; }
From source file:eu.europa.ejusticeportal.dss.controller.signature.PdfUtils.java
/** * Append attachments to the PDF.//from w w w . j av a 2 s. c o m * * @param pdf the PDF document * @param attachments the bytes for the attachment * @param ignore the names to be ignored */ public static byte[] appendAttachment(byte[] pdf, Map<String, byte[]> attachments, String... ignore) { try { List<String> ignoreList = Arrays.asList(ignore); InputStream is = new ByteArrayInputStream(pdf); PDDocument doc = PDDocument.load(is); PDEmbeddedFilesNameTreeNode tree = new PDDocumentNameDictionary(doc.getDocumentCatalog()) .getEmbeddedFiles(); if (tree == null) { tree = new PDEmbeddedFilesNameTreeNode(); PDDocumentNameDictionary names = new PDDocumentNameDictionary(doc.getDocumentCatalog()); names.setEmbeddedFiles(tree); doc.getDocumentCatalog().setNames(names); } Map<String, COSObjectable> temp = tree.getNames(); Map<String, COSObjectable> map = new HashMap<String, COSObjectable>(); if (temp != null) { map.putAll(temp); } for (String fileName : attachments.keySet()) { if (ignoreList.contains(fileName)) { continue; } byte[] bytes = attachments.get(fileName); if (bytes == null) { continue; } PDComplexFileSpecification cosObject = new PDComplexFileSpecification(); cosObject.setFile(fileName); InputStream isa = new ByteArrayInputStream(bytes); PDEmbeddedFile ef = new PDEmbeddedFile(doc, isa); ef.setSize(bytes.length); cosObject.setEmbeddedFile(ef); map.put(fileName, cosObject); } tree.setNames(map); return toByteArray(doc); } catch (COSVisitorException e) { throw new SigningException(e); } catch (IOException e) { throw new SigningException(e); } }
From source file:com.thinkbiganalytics.nifi.rest.support.NifiProcessUtil.java
/** * Return a map of the process group and their children * * @param group a process group/*from w w w. ja v a 2 s. c o m*/ * @return a map of the process group and their children */ private static Map<String, ProcessGroupDTO> getProcessGroupsMap(ProcessGroupDTO group) { Map<String, ProcessGroupDTO> groups = new HashMap<>(); groups.put(group.getId(), group); if (group.getContents() != null && group.getContents().getProcessGroups() != null) { for (ProcessGroupDTO groupDTO : group.getContents().getProcessGroups()) { groups.putAll(getProcessGroupsMap(groupDTO)); } } return groups; }
From source file:com.tobedevoured.naether.NaetherTest.java
private static void setEnv(Map<String, String> newenv) { try {// ww w . j a va 2s. c o m 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:ac.elements.io.Signature.java
/** * Calculate String to Sign for SignatureVersion 2. * //from ww w.ja va2s . com * @param parameters * request parameters * * @return String to Sign * * @throws java.security.SignatureException */ private static String calculateStringToSignV2(Map<String, String> parameters) { StringBuilder data = new StringBuilder(); data.append("POST"); data.append("\n"); URI endpoint = null; try { endpoint = new URI(SERVICE_URL); } catch (URISyntaxException ex) { // log.error("URI Syntax Exception", ex); throw new RuntimeException("URI Syntax Exception thrown " + "while constructing string to sign", ex); } data.append(endpoint.getHost()); data.append("\n"); String uri = endpoint.getPath(); if (uri == null || uri.length() == 0) { uri = "/"; } data.append(urlEncode(uri, true)); data.append("\n"); Map<String, String> sorted = new TreeMap<String, String>(); sorted.putAll(parameters); Iterator<Map.Entry<String, String>> pairs = sorted.entrySet().iterator(); while (pairs.hasNext()) { Map.Entry<String, String> pair = pairs.next(); String key = pair.getKey(); data.append(urlEncode(key, false)); data.append("="); String value = pair.getValue(); data.append(urlEncode(value, false)); if (pairs.hasNext()) { data.append("&"); } } return data.toString(); }
From source file:com.dtolabs.rundeck.core.dispatcher.DataContextUtils.java
/** * Return a new context with appended data set * * @param key data key/* ww w. ja va2 s .c om*/ * @param data data content * @param context original context * * @return new context containing original data and the new dataset */ public static Map<String, Map<String, String>> addContext(final String key, final Map<String, String> data, final Map<String, Map<String, String>> context) { final Map<String, Map<String, String>> newdata = new HashMap<String, Map<String, String>>(); if (null != context) { newdata.putAll(context); } newdata.put(key, data); return newdata; }