List of usage examples for java.util Map keySet
Set<K> keySet();
From source file:Main.java
/** * Convert the given map to a string.//from w ww . j a va 2 s .c om * @param m Any map to display * @return A string (multi-line) containing a view of the desired map */ public static <A, B> String toString(Map<A, B> m) { StringBuffer sb = new StringBuffer(); sb.append("[\n"); for (A key : m.keySet()) { sb.append(" " + key + " => " + m.get(key) + "\n"); } sb.append("]"); return sb.toString(); }
From source file:Main.java
public static final <D, E, F> Map<D, F> reMap(Map<? extends E, F> sourceMap, Function<E, D> mapping) { Map<D, F> resultMap = new HashMap<D, F>(); for (E key : sourceMap.keySet()) { resultMap.put(mapping.apply(key), sourceMap.get(key)); }/*from w w w.ja va 2 s .c om*/ return resultMap; }
From source file:Main.java
public static Map<String, Object> getMapValueSubset(Map<String, Object> list, String pattern) { HashMap<String, Object> result = new HashMap<>(); for (String key : list.keySet()) { if (key.matches(pattern)) { result.put(key, list.get(key)); }/* w w w.jav a 2 s. com*/ } return result; }
From source file:Main.java
/** * not tested yet//from w w w . j av a 2s . co m * * @param map * @return */ public static List<Object> getMapValues(Map<Object, Object> map) { List<Object> valuemaplist = new ArrayList<Object>(); Iterator<Object> iterator = map.keySet().iterator(); while (iterator.hasNext()) { valuemaplist.add(map.get(iterator.next())); } return valuemaplist; }
From source file:Main.java
@SuppressWarnings("rawtypes") private static void mapToXml(Map map, StringBuffer sb) { Set set = map.keySet(); for (Iterator it = set.iterator(); it.hasNext();) { String key = (String) it.next(); Object value = map.get(key); if (null == value) value = ""; if (value instanceof List) { ArrayList list = (ArrayList) map.get(key); // sb.append("<" + key + ">"); for (int i = 0; i < list.size(); i++) { sb.append("<" + key + ">"); // Object listi = list.get(i); if (list.get(i) instanceof HashMap) { HashMap hm = (HashMap) list.get(i); // sb.append("<" + key + ">"); mapToXml(hm, sb);//from ww w . j a va 2 s .co m // sb.append("</" + key + ">"); } else { // sb.append("<" + key + ">" + list.get(i) + "</" + key // + ">"); sb.append(list.get(i)); } // else // if(listi.getClass().getName().equals("java.util.ArrayList")){ // sb.append("<" + key + ">" + "??" + "</" + key + ">");} sb.append("</" + key + ">"); } // sb.append("</" + key + ">"); } else { if (value instanceof HashMap) { sb.append("<" + key + ">"); mapToXml((HashMap) value, sb); sb.append("</" + key + ">"); } else { sb.append("<" + key + ">" + value + "</" + key + ">"); } } } }
From source file:Main.java
/** * Flatten a map of string arrays to a map of strings using the first item in each array. * /*from ww w .java2 s. com*/ * @param parameterMap * The map of string arrays. * @return A map of strings. */ public static Map<String, String> flatten(Map<String, String[]> parameterMap) { Map<String, String> result = new TreeMap<String, String>(); for (String key : parameterMap.keySet()) { result.put(key, parameterMap.get(key)[0]); } return result; }
From source file:com.github.fge.jackson.SampleNodeProvider.java
public static Iterator<Object[]> getSamples(final EnumSet<NodeType> types) { final Map<NodeType, JsonNode> map = Maps.newEnumMap(SAMPLE_DATA); map.keySet().retainAll(types); return FluentIterable.from(map.values()).transform(new Function<JsonNode, Object[]>() { @Override//from w ww . j a va2s . c o m public Object[] apply(final JsonNode input) { return new Object[] { input }; } }).iterator(); }
From source file:de.iritgo.simplelife.bean.BeanTools.java
/** * Copy all attributes from the given map to the given bean * // w w w . j a v a 2 s . c om * @param map The map The map * @param object The bean The bean */ static public void copyMap2Bean(Map<String, Object> map, Object object) { for (String name : map.keySet()) { if (PropertyUtils.isWriteable(object, name)) { try { PropertyUtils.setSimpleProperty(object, name, map.get(name)); } catch (Exception ignore) { } } } }
From source file:Main.java
public static void broadcast(Context context, String what, Map<String, String> params) { Intent intent = new Intent(what); if (params != null) { Set<String> keys = params.keySet(); for (String string : keys) { intent.putExtra(string, params.get(string)); }/*from ww w . j a v a 2s . com*/ } context.sendBroadcast(intent); }
From source file:edu.usu.sdl.openstorefront.util.ServiceUtil.java
public static String printObject(Object o) { StringBuilder sb = new StringBuilder(); if (o != null) { try {//from w ww . ja v a 2 s .com Map fieldMap = BeanUtils.describe(o); fieldMap.keySet().stream().forEach((key) -> { sb.append(key).append(" = ").append(fieldMap.get(key)).append("\n"); }); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) { Logger.getLogger(ServiceUtil.class.getName()).log(Level.SEVERE, null, ex); } } else { sb.append(o); } return sb.toString(); }