List of usage examples for java.util LinkedHashMap LinkedHashMap
public LinkedHashMap()
From source file:Main.java
public static LinkedHashMap<String, Uri> GetMatchedContactsList(Context context, String searchTerm) { LinkedHashMap<String, Uri> contactList = new LinkedHashMap<String, Uri>(); ContentResolver cr = context.getContentResolver(); String columns[] = { ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.Contacts.PHOTO_THUMBNAIL_URI }; Cursor cur;// ww w .j a v a 2s . co m if (searchTerm == null) { cur = cr.query(ContactsContract.Contacts.CONTENT_URI, columns, null, null, null); } else { cur = cr.query(ContactsContract.Contacts.CONTENT_URI, columns, ContactsContract.Contacts.DISPLAY_NAME + " LIKE " + DatabaseUtils.sqlEscapeString("%" + searchTerm + "%"), null, ContactsContract.Contacts.DISPLAY_NAME + " ASC"); } if (cur != null) { if (cur.getCount() > 0) { while (cur.moveToNext()) { String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); String photoURI = cur .getString(cur.getColumnIndex(ContactsContract.Contacts.PHOTO_THUMBNAIL_URI)); if (photoURI != null) { Uri thumbUri = Uri.parse(photoURI); contactList.put(name, thumbUri); } } } cur.close(); } return contactList; }
From source file:Main.java
public static Map<String, String> attrbiuteToMap(NamedNodeMap attributes) { if (attributes == null) return new LinkedHashMap<String, String>(); Map<String, String> result = new LinkedHashMap<String, String>(); for (int i = 0; i < attributes.getLength(); i++) { result.put(attributes.item(i).getNodeName(), attributes.item(i).getNodeValue()); }/*from www.j ava2 s . c o m*/ return result; }
From source file:Main.java
/** * map sort/*w ww.j a va 2s . co m*/ * @param map * @param compator * @return */ public static <K, V> Map<K, V> sortMap(Map<K, V> map, Comparator<Entry<K, V>> compator) { Map<K, V> result = new LinkedHashMap<K, V>(); List<Entry<K, V>> entries = new ArrayList<Entry<K, V>>(map.entrySet()); Collections.sort(entries, compator); for (Entry<K, V> entry : entries) { result.put(entry.getKey(), entry.getValue()); } return result; }
From source file:Main.java
public static <K, V> Map<K, V> join(Map<? extends K, ? extends V> first, Map<? extends K, ? extends V> second) { return join(first, second, new LinkedHashMap<>()); }
From source file:Main.java
public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue(Map<K, V> map) { List<Map.Entry<K, V>> list = new LinkedList<Map.Entry<K, V>>(map.entrySet()); Collections.sort(list, new Comparator<Map.Entry<K, V>>() { public int compare(Map.Entry<K, V> o1, Map.Entry<K, V> o2) { return (o2.getValue()).compareTo(o1.getValue()); }/*from w w w .ja v a2 s . c om*/ }); Map<K, V> result = new LinkedHashMap<K, V>(); for (Map.Entry<K, V> entry : list) { result.put(entry.getKey(), entry.getValue()); } return result; }
From source file:Main.java
/** * setting value to current ThreadLocal map. * @param name/* w w w . ja va 2 s. co m*/ * @param value * @author <a href="mailto:iffiff1@gmail.com">Tyler Chen</a> * @since Aug 18, 2015 */ public static void set(String name, Object value) { Map map = params.get(); if (map == null) { map = new LinkedHashMap(); params.set(map); } map.put(name, value); }
From source file:Main.java
/** * Converts {@link NamedNodeMap} to a {@link LinkedHashMap}<String,String>. * @param _nodeMap node map/* ww w . java2 s. c om*/ * @return {@link LinkedHashMap}, maybe empty but never null */ public static Map<String, String> convertToAttributeMap(NamedNodeMap _nodeMap) { Map<String, String> map = new LinkedHashMap<>(); for (int i = 0; i < _nodeMap.getLength(); i++) { Node node = _nodeMap.item(i); map.put(node.getNodeName(), node.getNodeValue()); } return map; }
From source file:Main.java
public static Map<String, Uri> getRingtones(Activity activity) { RingtoneManager manager = new RingtoneManager(activity); manager.setType(RingtoneManager.TYPE_RINGTONE); Cursor cursor = manager.getCursor(); Map<String, Uri> list = new LinkedHashMap<>(); while (cursor.moveToNext()) { String notificationTitle = cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX); Uri notificationUri = manager.getRingtoneUri(cursor.getPosition()); list.put(notificationTitle, notificationUri); }/*from ww w . ja va 2 s . com*/ return list; }
From source file:Main.java
/** * From http://stackoverflow.com/questions/13592236/parse-a-uri-string-into-name-value-collection *///from w w w. j av a 2 s . c o m public static Map<String, List<String>> splitQuery(String urlQuery) throws UnsupportedEncodingException { final Map<String, List<String>> query_pairs = new LinkedHashMap<>(); final String[] pairs = urlQuery.split("&"); for (String pair : pairs) { final int idx = pair.indexOf("="); final String key = idx > 0 ? URLDecoder.decode(pair.substring(0, idx), "UTF-8") : pair; if (!query_pairs.containsKey(key)) { query_pairs.put(key, new LinkedList<String>()); } final String value = idx > 0 && pair.length() > idx + 1 ? URLDecoder.decode(pair.substring(idx + 1), "UTF-8") : null; query_pairs.get(key).add(value); } return query_pairs; }
From source file:Main.java
/** * Sorts given map by given comparator/*from w ww . j a va 2 s . c o m*/ * * @param map The map * @param comparator The comparator to sort the map * @param <K> The key type * @param <V> The value type * @return The sorted map */ public static <K, V> Map<K, V> sortMapByValue(Map<K, V> map, Comparator<Map.Entry<K, V>> comparator) { List<Map.Entry<K, V>> list = new LinkedList<>(map.entrySet()); list.sort(comparator); Map<K, V> result = new LinkedHashMap<>(); for (Map.Entry<K, V> entry : list) { result.put(entry.getKey(), entry.getValue()); } return result; }