List of usage examples for java.util Map putAll
void putAll(Map<? extends K, ? extends V> m);
From source file:Main.java
/** * create a child process with environment variables * @param command/* w w w . ja v a 2 s. com*/ * @param envVars * @return * @throws InterruptedException * @throws IOException */ public static String execUnixCommand(String[] command, Map<String, String> envVars) throws InterruptedException, IOException { /* ProcessBuilder processBuilder = new ProcessBuilder(command); if ( envVars != null ){ Map<String, String> env = processBuilder.environment(); env.clear(); env.putAll(envVars); } Process process = processBuilder.start(); processBuilder.redirectErrorStream(false); process.waitFor(); String outputWithError = loadStream(process.getInputStream()) + loadStream(process.getErrorStream()); return outputWithError; */ ProcessBuilder processBuilder = new ProcessBuilder(command); if (envVars != null) { Map<String, String> env = processBuilder.environment(); env.clear(); env.putAll(envVars); } Process process = processBuilder.start(); String output = loadStream(process.getInputStream()); String error = loadStream(process.getErrorStream()); process.waitFor(); return output + "\n" + error; }
From source file:grails.plugin.searchable.internal.compass.support.SearchableMethodUtils.java
/** * Get the options Map from the given argument array * @param args the given array of arguments, may not be null, may be empty * @param defaultOptions the default options, to be merged with user options, may be null * @return a Map of options, never null/*from w w w . j av a 2 s. com*/ */ public static Map getOptionsArgument(Object[] args, Map defaultOptions) { Assert.notNull(args, "args cannot be null"); Map options = null; for (int i = 0, max = args.length; i < max; i++) { if (args[i] instanceof Map) { options = (Map) args[i]; break; } } Map merged = new HashMap(); if (defaultOptions != null) { merged.putAll(defaultOptions); } if (options != null) { merged.putAll(options); } return merged; }
From source file:com.drtshock.playervaults.vaultmanagement.Serialization.java
public static Map<String, Object> recreateMap(Map<String, Object> original) { Map<String, Object> map = new HashMap<>(); map.putAll(original); return map;//from w w w . j a va 2 s . c o m }
From source file:backtype.storm.command.update_topology.java
private static void updateTopology(String topologyName, String pathJar, String pathConf) { NimbusClient client = null;/*from www .j av a 2 s.c o m*/ Map loadMap = null; if (pathConf != null) { loadMap = Utils.loadConf(pathConf); } else { loadMap = new HashMap(); } Map conf = Utils.readStormConfig(); conf.putAll(loadMap); client = NimbusClient.getConfiguredClient(conf); try { // update jar String uploadLocation = null; if (pathJar != null) { System.out.println("Jar update to master yet. Submitting jar of " + pathJar); String path = client.getClient().beginFileUpload(); String[] pathCache = path.split("/"); uploadLocation = path + "/stormjar-" + pathCache[pathCache.length - 1] + ".jar"; List<String> lib = (List<String>) conf.get(GenericOptionsParser.TOPOLOGY_LIB_NAME); Map<String, String> libPath = (Map<String, String>) conf .get(GenericOptionsParser.TOPOLOGY_LIB_PATH); if (lib != null && lib.size() != 0) { for (String libName : lib) { String jarPath = path + "/lib/" + libName; client.getClient().beginLibUpload(jarPath); StormSubmitter.submitJar(conf, libPath.get(libName), jarPath, client); } } else { if (pathJar == null) { // no lib, no client jar throw new RuntimeException("No client app jar, please upload it"); } } if (pathJar != null) { StormSubmitter.submitJar(conf, pathJar, uploadLocation, client); } else { // no client jar, but with lib jar client.getClient().finishFileUpload(uploadLocation); } } // update topology String jsonConf = Utils.to_json(loadMap); System.out.println("New configuration:\n" + jsonConf); client.getClient().updateTopology(topologyName, uploadLocation, jsonConf); System.out.println("Successfully submit command update " + topologyName); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } finally { if (client != null) { client.close(); } } }
From source file:com.dattack.dbtools.drules.engine.DefaultNotificationActionBeanVisitor.java
private static String formatMessage(final NotificationActionSendMailBean action, final Configuration configuration) throws TemplateException, IOException, ConfigurationException { final Template template = createTemplate(action); final Map<Object, Object> dataModel = new HashMap<>(); dataModel.putAll(ConfigurationConverter.getMap(configuration)); final StringWriter outputWriter = new StringWriter(); template.process(dataModel, outputWriter); return outputWriter.toString(); }
From source file:com.flozano.socialauth.util.OpenIdConsumer.java
/** * It obtains the request token. The Request Token is a temporary token used * to initiate User authorization.//from w ww . jav a2 s.com * * @param requestTokenUrl * the Request Token URL * @param returnTo * Callback URL * @param realm * Realm * @param assocHandle * @param consumerURL * @param scope * @return Generated Request Token URL * @throws Exception */ public static String getRequestTokenURL(final String requestTokenUrl, final String returnTo, final String realm, final String assocHandle, final String consumerURL, final String scope) throws Exception { Map<String, String> params = new HashMap<String, String>(); params.putAll(requestTokenMap); params.put("openid.return_to", returnTo); params.put("openid.realm", realm); params.put("openid.assoc_handle", assocHandle); params.put("openid.ext2.consumer", consumerURL); if (scope != null) { params.put("openid.ext2.scope", scope); } String paramStr = HttpUtil.buildParams(params); char separator = requestTokenUrl.indexOf('?') == -1 ? '?' : '&'; String url = requestTokenUrl + separator + paramStr; LOG.debug("Request Token URL : " + url); return url; }
From source file:Main.java
public static <K, V> void merge(final Map<K, V> into, final Map<K, V> values) { checkNotNull(into, "target cannot be null"); checkNotNull(values, "source cannot be null"); into.putAll(values); }
From source file:it.geosolutions.geoserver.jms.impl.utils.BeanUtils.java
/** * This is a 'smart' (perform checks for some special cases) update function which should be used to copy of the properties for objects * of the catalog and configuration.//from w w w . jav a 2 s . c o m * * @param <T> the type of the bean to update * @param info the bean instance to update * @param properties the list of string of properties to update * @param values the list of new values to update * * @throws IllegalAccessException * @throws InvocationTargetException * @throws NoSuchMethodException */ public static <T> void smartUpdate(final T info, final List<String> properties, final List<Object> values) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { final Iterator<String> itPropertyName = properties.iterator(); final Iterator<Object> itValue = values.iterator(); while (itPropertyName.hasNext() && itValue.hasNext()) { String propertyName = itPropertyName.next(); final Object value = itValue.next(); PropertyDescriptor pd = PropertyUtils.getPropertyDescriptor(info, propertyName); // return null if there is no such descriptor if (pd == null) { // this is a special case used by the NamespaceInfoImpl setURI // the propertyName coming from the ModificationProxy is set to 'uRI' // lets set it to uri propertyName = propertyName.toUpperCase(); pd = PropertyUtils.getPropertyDescriptor(info, propertyName); if (pd == null) { return; } } if (pd.getWriteMethod() != null) { PropertyUtils.setProperty(info, propertyName, value); } else { // T interface do not declare setter method for this property // lets use getter methods to get the property reference final Object property = PropertyUtils.getProperty(info, propertyName); // check type of property to apply new value if (Collection.class.isAssignableFrom(pd.getPropertyType())) { final Collection<?> liveCollection = (Collection<?>) property; liveCollection.clear(); liveCollection.addAll((Collection) value); } else if (Map.class.isAssignableFrom(pd.getPropertyType())) { final Map<?, ?> liveMap = (Map<?, ?>) property; liveMap.clear(); liveMap.putAll((Map) value); } else { if (CatalogUtils.LOGGER.isLoggable(java.util.logging.Level.SEVERE)) CatalogUtils.LOGGER.severe("Skipping unwritable property " + propertyName + " with property type " + pd.getPropertyType()); } } } }
From source file:Main.java
/** * Assign or make new map from source map. Use HashMap for new map. * /*from ww w. java 2 s . c o m*/ * @param src * source map * @param dst * destination map * @return dst or new map if dst null */ public static <K, V> Map<K, V> instanceMap(Map<K, V> src, Map<K, V> dst) { Map<K, V> ret = null; if (src != null) { if (dst == null) { dst = new HashMap<>(); } dst.clear(); dst.putAll(src); ret = dst; } return ret; }
From source file:com.github.lynxdb.server.core.TimeSerie.java
public static TimeSerie merge(List<TimeSerie> _series) { Assert.notEmpty(_series);//from www. ja va2 s .c o m List<SuperIterator> sil = new ArrayList<>(); _series.forEach((TimeSerie t) -> { if (t.hasNext()) { SuperIterator<Entry> si = new SuperIterator<>(t); si.next(); sil.add(si); } }); Map<String, String> tags = new HashMap<>(); tags.putAll(_series.get(0).getTags()); _series.forEach((TimeSerie t) -> { Iterator<Map.Entry<String, String>> i = tags.entrySet().iterator(); while (i.hasNext()) { Map.Entry<String, String> e = i.next(); if (!t.getTags().containsKey(e.getKey()) || !t.getTags().get(e.getKey()).equals(e.getValue())) { i.remove(); } } }); return new TimeSerie(_series.get(0).getName(), tags, new ChainableIterator<Entry>() { @Override public boolean hasNext() { return sil.stream() .anyMatch((superIterator) -> superIterator.hasNext() || superIterator.getCurrent() != null); } @Override public Entry next() { Iterator<SuperIterator> rr = sil.iterator(); while (rr.hasNext()) { if (rr.next().getCurrent() == null) { rr.remove(); } } long max = Long.MIN_VALUE; for (SuperIterator<Entry> r : sil) { max = Long.max(max, r.getCurrent().getTime()); } for (SuperIterator<Entry> r : sil) { if (r.getCurrent().getTime() == max) { r.next(); return r.getPrevious(); } } throw new IllegalStateException("something went wrong"); } }); }