List of usage examples for java.util Map keySet
Set<K> keySet();
From source file:Main.java
/** * Removes the entries of a map that have null values. * /*from ww w.j a v a 2 s . c o m*/ * @param map * The map to strip. * @return The map that was passed in. */ public static <K, V> Map<K, V> stripNulls(final Map<K, V> map) { List<Object> toRemove = null; for (final Object key : map.keySet()) { if (map.get(key) == null) { toRemove = safeAdd(toRemove, key); } } if (toRemove != null) { for (final Object key : toRemove) { map.remove(key); } } return map; }
From source file:Main.java
/** * Copy tags to clipboard as multi-line text in the form * key1=value1// w ww . j a va2s .c o m * key2=value2 * ..... * @param tags */ @SuppressWarnings("deprecation") @SuppressLint("NewApi") public static void copyTags(Context ctx, Map<String, String> tags) { StringBuffer tagsAsText = new StringBuffer(); for (String key : tags.keySet()) { tagsAsText.append(key + "=" + tags.get(key) + "\n"); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { ClipboardManager clipboard = (ClipboardManager) ctx.getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("OSM Tags", tagsAsText.toString()); clipboard.setPrimaryClip(clip); } else { android.text.ClipboardManager oldClipboard = (android.text.ClipboardManager) ctx .getSystemService(Context.CLIPBOARD_SERVICE); oldClipboard.setText(tagsAsText.toString()); } }
From source file:Main.java
public static boolean savePreferencesInExternal(Context ctx, SharedPreferences pref) { Properties propfile = new Properties(); Map<String, ?> keymap = pref.getAll(); Iterator<String> keyit = keymap.keySet().iterator(); Log.d("External", "Saving prefrences to external Storages"); while (keyit.hasNext()) { String key = keyit.next(); propfile.put(key, keymap.get(key)); }//from ww w .j a va 2 s .c o m if (isExternalStorageAvailableforWriting() == true) { try { propfile.storeToXML(new FileOutputStream(new File(ctx.getExternalFilesDir(null), "install_info")), null); } catch (Exception e) { e.printStackTrace(); } Log.d("External", "Saved prefrences to external "); return true; } else { Log.d("External", "Failed to Save prefrences for external "); return false; } }
From source file:Main.java
public static String getChartsType(Map<String, Long> map) { String TITLE = ""; if (map.isEmpty()) { return null; }//from w ww . j a v a 2s . c om Set<String> keySet = map.keySet(); for (String title : keySet) { TITLE += title + ","; } TITLE = TITLE.substring(0, TITLE.length() - 1); return TITLE; }
From source file:Main.java
public static String convertToString(Map<String, Object> properties) { List<String> parts = new ArrayList<String>(); for (String key : properties.keySet()) { Object value = properties.get(key); if (value instanceof String) { parts.add(encode('=', new String[] { key, (String) value })); } else {/*from www .j ava 2 s . c o m*/ throw new RuntimeException("Can't encode " + value); } } return encode(';', parts); }
From source file:no.digipost.api.xml.XpathUtil.java
@SuppressWarnings("unchecked") public static List<Node> getDOMXPath(final String expression, final Element element) { try {/*from w w w . j a va 2 s . c om*/ DOMXPath xpath = new DOMXPath(expression); Map<String, String> xpathNamespaces = getXpathNamespaces(); for (String s : xpathNamespaces.keySet()) { xpath.addNamespace(s, xpathNamespaces.get(s)); } return xpath.selectNodes(element); } catch (JaxenException e) { throw new RuntimeException(e); } }
From source file:Main.java
public static String getChartsType1(Map<String, Long> map) { String DATA = ""; if (map.isEmpty()) { return null; }//from w ww .jav a 2 s . c om Set<String> keySet = map.keySet(); for (String title : keySet) { Long long1 = map.get(title); DATA += "{value:" + long1 + ",name:'" + title + "'},"; } DATA = DATA.substring(0, DATA.length() - 1); return "[" + DATA + "]"; }
From source file:Main.java
private static void organizeAndStart(Activity activity, Class<?> classes, Map<String, String> paramMap) { intent = new Intent(activity, classes); if (null != paramMap) { Set<String> set = paramMap.keySet(); for (Iterator<String> iterator = set.iterator(); iterator.hasNext();) { String key = iterator.next(); intent.putExtra(key, paramMap.get(key)); }//from w w w. ja v a 2s. c o m } intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); activity.startActivity(intent); }
From source file:Main.java
public static void mapToAndroidLayoutMapper(Class classObj, Map map, String prefixStr, View view) { for (Object keyObj : map.keySet().toArray()) { String keyStr = keyObj.toString(); Field fieldObj = null;/*w w w . java2 s . c o m*/ try { fieldObj = classObj.getField(prefixStr + "_" + keyStr); } catch (NoSuchFieldException e) { continue; } Object layoutObj = null; try { layoutObj = fieldObj.get(fieldObj); } catch (IllegalAccessException e) { continue; } Integer layoutIntvalue = (Integer) layoutObj; View selectedView = view.findViewById(layoutIntvalue); if (selectedView instanceof TextView) { TextView textView = (TextView) selectedView; textView.setText(String.valueOf(map.get(keyStr))); } else if (selectedView instanceof ImageView) { ImageView imageView = (ImageView) selectedView; } } }
From source file:Main.java
public static String simpleMapToJsonStr(Map map) { if (map == null || map.isEmpty()) { return "null"; }// ww w . jav a 2 s. co m String jsonStr = "{"; Set<?> keySet = map.keySet(); for (Object key : keySet) { jsonStr += "\"" + key + "\":\"" + map.get(key) + "\","; } jsonStr = jsonStr.substring(0, jsonStr.length() - 1); jsonStr += "}"; return jsonStr; }