List of usage examples for java.util LinkedHashMap LinkedHashMap
public LinkedHashMap()
From source file:Main.java
public static <T> Set removeRepetition(Collection<T> ts) { if (ts == null || ts.isEmpty()) { return Collections.emptySet(); }//from w ww . ja v a 2 s .co m Map<T, Object> map = new LinkedHashMap(); for (T t : ts) { if (!map.containsKey(t)) { map.put(t, -1); } } Set<T> set = map.keySet(); return set; }
From source file:Main.java
public static Map<String, Object> getClassFields(Object obj) { Map<String, Object> values = new LinkedHashMap<String, Object>(); for (Field field : getAllFieldsValues(obj.getClass())) { values.put(field.getName(), getField(field, obj)); }/*from ww w . j a v a 2 s .c o m*/ return values; }
From source file:Main.java
@SuppressWarnings("unchecked") public static <T> Map<T, Object> asMap(T key, Object... values) { Map<T, Object> result = new LinkedHashMap<T, Object>(); if (values == null || values.length % 2 == 0) { throw new IllegalArgumentException("value[] must be not null and an odd length"); }// w w w . j a v a 2 s .c om result.put(key, values[0]); for (int i = 1; i < values.length; i += 2) { result.put((T) values[i], values[i + 1]); } return result; }
From source file:Main.java
public static Map<String, String> splitQuery(String query) { Map<String, String> query_pairs = new LinkedHashMap<String, String>(); try {//from w w w . j av a 2s .c o m String[] pairs = query.split("&"); for (String pair : pairs) { int idx = pair.indexOf("="); query_pairs.put(URLDecoder.decode(pair.substring(0, idx), "UTF-8"), URLDecoder.decode(pair.substring(idx + 1), "UTF-8")); } } catch (UnsupportedEncodingException e) { query_pairs.put("error", "UnsupportedEncodingException"); query_pairs.put("error_description", e.getMessage()); } return query_pairs; }
From source file:Main.java
/** * it returns an ordered Map implementation * /*from w ww .jav a2 s. co m*/ * @return */ public static <T, D> Map<T, D> newOrderedMap() { return new LinkedHashMap<>(); }
From source file:Main.java
public static Map<String, String> getTagValueMap(Element ele, String language) { Map<String, String> map = new LinkedHashMap<String, String>(); NodeList children = ele.getChildNodes(); Node current = null;//w w w .j av a 2 s. c o m int count = children.getLength(); for (int i = 0; i < count; i++) { current = children.item(i); if (current.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) current; map.put(current.getNodeName(), element.getFirstChild().getNodeValue()); } } return map; }
From source file:Main.java
public static <G> Map<String, G> transferRootNameMap(Map<Integer, Integer> rootIdIdMap, Map<Integer, G> idValueMap, G defaultValue) { Map<String, G> rootValueMap = new LinkedHashMap<String, G>(); for (Entry<Integer, Integer> entry : rootIdIdMap.entrySet()) { if (idValueMap.containsKey(entry.getValue())) { rootValueMap.put(entry.getKey().toString(), idValueMap.get(entry.getValue())); } else {/*from w ww . j a v a2 s . c om*/ rootValueMap.put(entry.getKey().toString(), defaultValue); } } return rootValueMap; }
From source file:Main.java
public static Integer firstUnique(Collection<Integer> collection) { Map<Integer, Integer> linkedHashMap = new LinkedHashMap<Integer, Integer>(); java.util.Iterator<Integer> it = collection.iterator(); Integer currentInt;/*from w ww .jav a 2 s. co m*/ java.util.Iterator it1; Set entrySet; Map.Entry<Integer, Integer> me; while (it.hasNext()) { currentInt = it.next(); if (!linkedHashMap.containsKey(currentInt)) { linkedHashMap.put(currentInt, 1); } else { linkedHashMap.put(currentInt, linkedHashMap.get(currentInt) + 1); } } entrySet = linkedHashMap.entrySet(); it1 = entrySet.iterator(); while (it1.hasNext()) { me = (Entry) it1.next(); if (me.getValue().equals(1)) { return (Integer) me.getKey(); } } return null; }
From source file:Main.java
public static <K, V> void putAt(LinkedHashMap<K, V> map, K key, V value, int pos) { Iterator<Entry<K, V>> ei = map.entrySet().iterator(); LinkedHashMap<K, V> pre = new LinkedHashMap<>(); LinkedHashMap<K, V> post = new LinkedHashMap<>(); for (int i = 0; i < pos; i++) { if (!ei.hasNext()) break; Entry<K, V> tmpE = ei.next(); pre.put(tmpE.getKey(), tmpE.getValue()); }/*from w w w . j a va 2 s.c o m*/ // skip element at pos if (ei.hasNext()) ei.next(); while (ei.hasNext()) { Entry<K, V> tmpE = ei.next(); post.put(tmpE.getKey(), tmpE.getValue()); } map.clear(); map.putAll(pre); map.put(key, value); map.putAll(post); }
From source file:Main.java
public static <K, V> Map<K, V> map(List<K> keys, List<V> values, boolean ignoreNull) { Map<K, V> ret = new LinkedHashMap<K, V>(); for (int i = 0; i < keys.size(); i++) { V v = values.get(i);//w ww. ja v a 2s. co m if (ignoreNull && v == null) { continue; } ret.put(keys.get(i), values.get(i)); } return ret; }