List of usage examples for java.util LinkedHashMap LinkedHashMap
public LinkedHashMap()
From source file:Main.java
public static <K, V> Map<K, V> mapOf(K key, V value, K key2, V value2) { Map<K, V> map = new LinkedHashMap<K, V>(); map.put(key, value);//from w ww.j a va 2 s.com map.put(key2, value2); return map; }
From source file:Main.java
public static <K, V> Map<K, V> asOrderedMap(Map.Entry<K, V>... entry) { Map<K, V> map = new LinkedHashMap<K, V>(); fillEntries(map, entry);/* w w w . j ava 2s.com*/ return map; }
From source file:Main.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public static HashMap<?, ?> sortByValue(HashMap<?, ?> map, final int flag) { // flag = 0 decreasing order otherwise increasing List<Map.Entry<?, ?>> list = new LinkedList<Map.Entry<?, ?>>(map.entrySet()); Collections.sort(list, new Comparator() { public int compare(Object o1, Object o2) { if (flag == 0) return ((Comparable) ((Map.Entry) (o2)).getValue()).compareTo(((Map.Entry) (o1)).getValue()); else//from w w w. j ava 2 s . c om return ((Comparable) ((Map.Entry) (o1)).getValue()).compareTo(((Map.Entry) (o2)).getValue()); } }); HashMap result = new LinkedHashMap(); for (Iterator it = list.iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry) it.next(); result.put(entry.getKey(), entry.getValue()); } return result; }
From source file:Main.java
public static Map<String, Object> flat(Multimap<String, Object> multimap) { Map<String, Object> flattenMap = new LinkedHashMap<String, Object>(); for (String key : multimap.keySet()) { int i = 0; for (Object object : multimap.get(key)) { flattenMap.put(key.replaceAll("\\.", "_") + "_" + i++, object); }// w ww. j a v a2 s . co m } return flattenMap; }
From source file:Main.java
/** * Returns a linked hash map typed to the generics specified in the method * call/*w w w . j a va2 s. c o m*/ */ public static <K, V> Map<K, V> createLinkedHashMap() { return new LinkedHashMap<K, V>(); }
From source file:Main.java
/** * Returns a {@link LinkedHashMap}// w w w . j a v a 2 s . c om * with the mappings <code>a[0] => a[1], a[2] => a[3], ...</code>. * @param a the elements to construct a {@link Map} from. * @return a {@link Map} constructed of the specified elements. */ @Nonnull public static <K, V> Map<K, V> asMap(@Nullable Object... a) { return putAll(new LinkedHashMap<K, V>(), a); }
From source file:Main.java
@SuppressWarnings("unchecked") public static <Key, Value> Map<Key, Value> map(Object... args) { LinkedHashMap<Key, Value> result = new LinkedHashMap<Key, Value>(); for (int i = 0; i < args.length; i += 2) { result.put((Key) args[i], (Value) args[i + 1]); }/*from w w w.j a va 2 s .c om*/ return result; }
From source file:Main.java
public static <K, V extends Comparable<? super V>> LinkedHashMap<K, V> sortMapByValue(Map<K, V> map, final boolean descending) { 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) { int comp = (o1.getValue()).compareTo(o2.getValue()); if (descending) { comp = comp * (-1);/* ww w . j a va 2 s . c om*/ } return comp; } }); LinkedHashMap<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:gov.nih.nci.cabig.caaers.utils.JSONUtils.java
public static Map<String, Object> describe(Object o) { Map<String, Object> m = new LinkedHashMap<String, Object>(); Method[] methods = o.getClass().getMethods(); for (Method method : methods) { String name = method.getName(); if (!name.startsWith("get")) continue; name = name.substring(3);//from ww w . ja v a 2 s .c o m String firstChar = "" + name.charAt(0); name = firstChar.toLowerCase() + name.substring(1); Object value = null; try { value = method.invoke(o); } catch (Exception ignore) { } if (name.equals("class")) value = String.valueOf(value); m.put(name, value); } return m; }
From source file:io.cloudslang.lang.entities.utils.ValueUtils.java
public static Map<String, Serializable> flatten(Map<String, Value> valueMap) { Map<String, Serializable> result = null; if (valueMap != null) { result = new LinkedHashMap<>(); for (Map.Entry<String, Value> entry : valueMap.entrySet()) { result.put(entry.getKey(), entry.getValue().toString()); }/*from w w w . j a va 2s. co m*/ } return result; }