List of usage examples for java.util Map putAll
void putAll(Map<? extends K, ? extends V> m);
From source file:com.elasticbox.jenkins.k8s.util.TestUtils.java
public static void setEnv(Map<String, String> newenv) { try {//from ww w.ja v a 2 s .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.putAll(newenv); } } } catch (Exception e2) { e2.printStackTrace(); } } catch (Exception e1) { e1.printStackTrace(); } }
From source file:com.example.aliyundemo.ocr.util.SignUtil.java
/** * ??Path+Query+FormParams//from w w w . j a va2 s.com * * @param url Path+Query * @param formParamMap POST?? * @return ??Path+Query+FormParams */ private static String buildResource(String url, Map formParamMap) { if (url.contains("?")) { String path = url.split("\\?")[0]; String queryString = url.split("\\?")[1]; url = path; if (formParamMap == null) { formParamMap = new HashMap(); } if (StringUtils.isNotBlank(queryString)) { for (String query : queryString.split("\\&")) { String key = query.split("\\=")[0]; String value = ""; if (query.split("\\=").length == 2) { value = query.split("\\=")[1]; } if (formParamMap.get(key) != null) { formParamMap.put(key, value); } } } } StringBuilder sb = new StringBuilder(); sb.append(url); if (formParamMap != null && formParamMap.size() > 0) { sb.append('?'); //?Key? Map<String, String> sortMap = new TreeMap<String, String>(); sortMap.putAll(formParamMap); int flag = 0; for (Map.Entry<String, String> e : sortMap.entrySet()) { if (flag != 0) { sb.append('&'); } flag++; String key = e.getKey(); String val = e.getValue(); if (val == null || ((val instanceof String) && StringUtils.isBlank(val))) { sb.append(key); } else { sb.append(key).append("=").append(val); } } } return sb.toString(); }
From source file:com.investoday.code.util.aliyun.api.gateway.util.SignUtil.java
/** * ??Path+Query+FormParams//w ww .j av a 2s . c o m * * @param url Path+Query * @param formParamMap POST?? * @return ??Path+Query+FormParams */ private static String buildResource(String url, Map formParamMap) { if (url.contains("?")) { String path = url.split("\\?")[0]; String queryString = url.split("\\?")[1]; url = path; if (formParamMap == null) { formParamMap = new HashMap(); } if (StringUtils.isNotBlank(queryString)) { for (String query : queryString.split("\\&")) { String key = query.split("\\=")[0]; String value = ""; if (query.split("\\=").length == 2) { value = query.split("\\=")[1]; } if (formParamMap.get(key) == null) { formParamMap.put(key, value); } } } } StringBuilder sb = new StringBuilder(); sb.append(url); if (formParamMap != null && formParamMap.size() > 0) { sb.append('?'); //?Key? Map<String, String> sortMap = new TreeMap<String, String>(); sortMap.putAll(formParamMap); int flag = 0; for (Map.Entry<String, String> e : sortMap.entrySet()) { if (flag != 0) { sb.append('&'); } flag++; String key = e.getKey(); String val = e.getValue(); if (val == null || ((val instanceof String) && StringUtils.isBlank(val))) { sb.append(key); } else { sb.append(key).append("=").append(val); } } } return sb.toString(); }
From source file:com.reachlocal.grails.plugins.cassandra.utils.OrmHelper.java
public static Map addOptionDefaults(Map<String, Object> options, Integer defaultCount, String cluster) { Map<String, Object> result = new LinkedHashMap<String, Object>(); result.putAll(options); Object reversed = options.get("reversed"); if (reversed == null) { reversed = false;//from ww w. jav a 2 s. c om } result.put("reversed", reversed); Object max = options.get("max"); if (max == null) { max = defaultCount; } result.put("max", max); Object clstr = options.get("cluster"); if (clstr == null && cluster != null) { result.put("cluster", cluster); } return result; }
From source file:io.fabric8.project.support.BuildConfigHelper.java
public static BuildConfig createBuildConfig(KubernetesClient kubernetesClient, String namespace, String projectName, String cloneUrl, Map<String, String> annotations) { LOG.info("Creating a BuildConfig for namespace: " + namespace + " project: " + projectName); String jenkinsUrl = null;//from w w w.ja v a2 s . co m try { jenkinsUrl = getJenkinsServiceUrl(kubernetesClient, namespace); } catch (Exception e) { // ignore missing Jenkins service issue } BuildConfig buildConfig = Builds.createDefaultBuildConfig(projectName, cloneUrl, jenkinsUrl); Map<String, String> currentAnnotations = KubernetesHelper.getOrCreateAnnotations(buildConfig); currentAnnotations.putAll(annotations); return buildConfig; }
From source file:com.cronutils.mapper.CronMapper.java
private static Function<Cron, Cron> setQuestionMark() { return cron -> { CronField dow = cron.retrieve(CronFieldName.DAY_OF_WEEK); CronField dom = cron.retrieve(CronFieldName.DAY_OF_MONTH); if (dow != null && dom != null) { if (dow.getExpression() instanceof QuestionMark || dom.getExpression() instanceof QuestionMark) { return cron; } else { Map<CronFieldName, CronField> fields = Maps.newHashMap(); fields.putAll(cron.retrieveFieldsAsMap()); if (dow.getExpression() instanceof Always) { fields.put(CronFieldName.DAY_OF_WEEK, new CronField(CronFieldName.DAY_OF_WEEK, new QuestionMark(), fields.get(CronFieldName.DAY_OF_WEEK).getConstraints())); } else { if (dom.getExpression() instanceof Always) { fields.put(CronFieldName.DAY_OF_MONTH, new CronField(CronFieldName.DAY_OF_MONTH, new QuestionMark(), fields.get(CronFieldName.DAY_OF_MONTH).getConstraints())); } else { cron.validate(); }/*from w ww . j a v a 2s . c o m*/ } return new Cron(cron.getCronDefinition(), Lists.<CronField>newArrayList(fields.values())); } } return cron; }; }
From source file:com.sixt.service.framework.servicetest.helper.DockerComposeHelper.java
/** * Set environment variable "etcd_endpoints" to the host and port specified by * docker//from www . j a v a 2 s. c o m */ public static void setEtcdEnvironment(DockerComposeRule docker) { DockerPort etcd = docker.containers().container("etcd").port(2379); Map<String, String> newEnv = new HashMap<>(); newEnv.put("etcd_endpoints", etcd.inFormat("http://$HOST:$EXTERNAL_PORT")); newEnv.putAll(System.getenv()); setEnv(newEnv); }
From source file:com.manydesigns.portofino.logic.SecurityLogic.java
public static Permissions calculateActualPermissions(Permissions basePermissions, List<Page> pages) { Permissions result = new Permissions(); Map<String, AccessLevel> resultLevels = result.getActualLevels(); resultLevels.putAll(basePermissions.getActualLevels()); for (Page current : pages) { Permissions currentPerms = current.getPermissions(); Map<String, AccessLevel> currentLevels = currentPerms.getActualLevels(); for (Map.Entry<String, AccessLevel> entry : currentLevels.entrySet()) { String currentGroup = entry.getKey(); AccessLevel currentLevel = entry.getValue(); AccessLevel resultLevel = resultLevels.get(currentGroup); if (resultLevel != AccessLevel.DENY && currentLevel != null) { resultLevels.put(currentGroup, currentLevel); }//from w ww. ja v a 2 s .c o m } } if (pages.size() > 0) { Page lastPage = pages.get(pages.size() - 1); Map<String, Set<String>> lastPermissions = lastPage.getPermissions().getActualPermissions(); result.getActualPermissions().putAll(lastPermissions); } else { result.getActualPermissions().putAll(basePermissions.getActualPermissions()); } return result; }
From source file:com.sixt.service.framework.servicetest.helper.DockerComposeHelper.java
/** * Set environment variable "kafkaServer" to the host and port specified by * docker// w w w .jav a 2 s . c o m */ public static void setKafkaEnvironment(DockerComposeRule docker) { DockerPort kafka = docker.containers().container("kafka").port(9092); Map<String, String> newEnv = new HashMap<>(); newEnv.put(ServiceProperties.KAFKA_SERVER_KEY, kafka.inFormat("$HOST:$EXTERNAL_PORT")); newEnv.putAll(System.getenv()); setEnv(newEnv); }
From source file:com.google.code.rees.scope.struts2.test.ScopeTestUtil.java
private static void extractConversationFields(Object target, ConversationAdapter conversationAdapter) { Collection<ConversationClassConfiguration> actionConversationConfigs = getConfigurationProvider() .getConfigurations(target.getClass()); if (actionConversationConfigs != null) { for (ConversationClassConfiguration conversation : actionConversationConfigs) { Map<String, Field> actionConversationFields = conversation.getFields(); String conversationName = conversation.getConversationName(); String conversationId = conversationAdapter.getRequestContext().get(conversationName); if (conversationId != null) { if (actionConversationFields != null) { Map<String, Object> conversationContext = conversationAdapter .getConversationContext(conversationName, conversationId); conversationContext.putAll(InjectionUtil.getFieldValues(target, actionConversationFields)); }//w w w .ja va2 s . c o m conversationAdapter.getViewContext().put(conversationName, conversationId); } } } }