List of usage examples for java.util Map entrySet
Set<Map.Entry<K, V>> entrySet();
From source file:Main.java
/** * json//from w ww.jav a 2 s . c om * @param params * @return */ public static String buildJsonString(Map<String, Object> params) { if (params == null || params.size() == 0) return null; Set<Entry<String, Object>> setEntry = params.entrySet(); StringBuilder str = new StringBuilder(); str.append("{"); for (Entry<String, Object> entry : setEntry) { str.append("\""); str.append(entry.getKey()); str.append("\""); str.append(":"); if (entry.getValue() instanceof String) { str.append("\""); } str.append(entry.getValue()); if (entry.getValue() instanceof String) { str.append("\""); } str.append(","); } str.setCharAt(str.length() - 1, '}'); return str.toString(); }
From source file:com.esa.infocontrol.utils.RequestParametersUtils.java
public static MapSqlParameterSource getQueryParameters(String id, Map<String, List<String>> queryParams) { MapSqlParameterSource sqlParams = new MapSqlParameterSource(); for (Map.Entry<String, List<String>> entry : queryParams.entrySet()) { LOG.info(entry.getKey() + " -> " + entry.getValue()); if (!entry.getKey().equalsIgnoreCase("id")) { sqlParams.addValue(entry.getKey(), entry.getValue()); }/*from w w w .ja va2 s.com*/ } if (id != null) { sqlParams.addValue("id", id); } return sqlParams; }
From source file:io.wcm.config.core.management.impl.PersistenceTypeConversion.java
/** * Convert object to be persisted.//from w w w. j a v a2s . c om * @param value Configured value * @param parameterType Parameter type * @return value that can be persisted */ public static Object toPersistenceType(Object value, Class<?> parameterType) { if (!isTypeConversionRequired(parameterType)) { return value; } if (Map.class.isAssignableFrom(parameterType) && (value instanceof Map)) { Map<?, ?> map = (Map<?, ?>) value; Map.Entry<?, ?>[] entries = Iterators.toArray(map.entrySet().iterator(), Map.Entry.class); String[] stringArray = new String[entries.length]; for (int i = 0; i < entries.length; i++) { Map.Entry<?, ?> entry = entries[i]; String entryKey = Objects.toString(entry.getKey(), ""); String entryValue = Objects.toString(entry.getValue(), ""); stringArray[i] = entryKey + KEY_VALUE_DELIMITER + entryValue; } return stringArray; } throw new IllegalArgumentException("Type conversion not supported: " + parameterType.getName()); }
From source file:Main.java
public static JSONObject map2Json(Map<?, ?> data) { JSONObject object = new JSONObject(); for (Map.Entry<?, ?> entry : data.entrySet()) { String key = (String) entry.getKey(); if (key == null) { throw new NullPointerException("key == null"); }/*from w w w .ja v a 2 s . co m*/ try { object.put(key, wrap(entry.getValue())); } catch (JSONException e) { e.printStackTrace(); } } return object; }
From source file:CollectionUtils.java
/** * Converts specified map to {@link java.util.Properties}. The keys and String values * are migrated unchnaged, other types of values are {@link Object#toString() converted to String}. * @param map map to convert.//from www . j a v a2 s . co m * @return converted map as Properties. */ public static Properties asProperties(Map<String, ?> map) { Properties props = new Properties(); for (Map.Entry<String, ?> entry : map.entrySet()) { Object v = entry.getValue(); if (v != null) { props.put(entry.getKey(), v.toString()); } } return props; }
From source file:Main.java
public static String[] map2keyValueStrings(Map<String, String> map, char delimiter) { String[] sa = new String[map.size()]; int i = 0;/* w w w . j ava2 s . c om*/ for (Map.Entry<String, String> e : map.entrySet()) { sa[i++] = e.getKey() + delimiter + e.getValue(); } return sa; }
From source file:Main.java
/** * Tabu refresh./*from w w w . java 2s .c o m*/ * @param map * @param tabu * @return map/tabu */ private static Map<Integer, Integer> tabuRefresh(Map<Integer, Integer> map, List<Integer> tabu) { Map<Integer, Integer> mapCopy = new HashMap<Integer, Integer>(); for (Map.Entry<Integer, Integer> e : map.entrySet()) { Integer key = e.getKey(); Integer value = e.getValue(); if (!tabu.contains(key.intValue())) { mapCopy.put(key, value); } } return mapCopy; }
From source file:org.lightjason.agentspeak.action.buildin.rest.IBaseRest.java
/** * transformas a map into a literal/* www . ja va 2s . c o m*/ * * @param p_map input map * @return term stream */ private static Stream<ITerm> flatmap(final Map<String, ?> p_map) { return p_map.entrySet().stream().map(i -> CLiteral .from(i.getKey().toLowerCase().replaceAll("[^([a-z][0-9]\\-/_)]]", "_"), flatterm(i.getValue()))); }
From source file:deck36.yaml.YamlLoader.java
public static Map updateMap(Map resultYamlMap, Map<String, Object> localYamlMap) { for (Map.Entry<String, Object> entry : localYamlMap.entrySet()) { if (resultYamlMap.containsKey(entry.getKey())) { System.out.println(entry.getKey()); try { Object startValue = resultYamlMap.get(entry.getKey()); Object updateValue = entry.getValue(); if (startValue == null) { resultYamlMap.put(entry.getKey(), updateValue); } else { resultYamlMap.put(entry.getKey(), MethodUtils.invokeStaticMethod(YamlLoader.class, "updateMap", new Object[] { startValue, updateValue })); }/*from w ww .j a va 2s. c o m*/ } catch (Exception e) { e.printStackTrace(); System.exit(1); } } else { resultYamlMap.put(entry.getKey(), entry.getValue()); } } return resultYamlMap; }
From source file:Main.java
public static String paramsmap2ParamsString(Map<String, String> params) { if (params == null) return ""; StringBuilder sb = new StringBuilder(); for (Map.Entry<String, String> param : params.entrySet()) { sb.append(param.getKey()).append("=").append(param.getValue()).append("&"); }//w w w . jav a 2s .c om if (sb.charAt(sb.length() - 1) == '&') sb.deleteCharAt(sb.length() - 1); return sb.toString(); }