List of utility methods to do Map Reverse
Map | reverseMap(Map 'reverse' a map's key and values, beware this may cause losing some entries(values may have duplications) Map<V, K> ret = new HashMap<V, K>(); for (Map.Entry<K, V> e : map.entrySet()) { ret.put(e.getValue(), e.getKey()); return ret; |
Map | reverseMap(Map reverse Map if (origMap == null) return null; Map<Object, Object> reverseMap = new HashMap<Object, Object>(); for (Object key : origMap.keySet()) { putMultiple(reverseMap, origMap.get(key), key); return reverseMap; |
Map | reverseMap(Map Convert String->Integer map to Integer->String map if (map == null) { return null; Map<Integer, String> rmap = new HashMap<>(); for (Map.Entry<String, Integer> entry : map.entrySet()) { rmap.put(entry.getValue(), entry.getKey()); return rmap; ... |
Map | reverseMap(Map reverse Map Map<K, G> ret = new HashMap<K, G>(); for (Entry<String, G> entry : keyValueMap.entrySet()) { K id = keyIdMap.get(entry.getKey()); ret.put(id, entry.getValue()); return ret; |
K | reverseMapLookup(Map reverse Map Lookup for (Entry<K, V> entry : map.entrySet()) { if (entry.getValue() == value) { return entry.getKey(); return null; |
void | reverseMapping(Map value2keys, Map map) reverse Mapping Iterator it = map.entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); Object value = entry.getValue(); Object key = entry.getKey(); List keys = (List) value2keys.get(value); if (keys == null) keys = new LinkedList(); ... |
Map | reverseMapping(Map reverse a Map to give a mapping from values to a list of keys Map<V, List<K>> rev = new HashMap<>(); for (Map.Entry<K, V> e : map.entrySet()) { V v = e.getValue(); if (!rev.containsKey(v)) { rev.put(v, new ArrayList<>()); rev.get(v).add(e.getKey()); return rev; |
Map | sort(Map sort Map<Long, List<String>> result = getSortedMap(reverse); for (String hostName : dataNodes.keySet()) { Map<Long, Long> usage = dataNodes.get(hostName); long space = usage.values().iterator().next(); List<String> hosts = result.get(space); if (hosts == null) { hosts = new ArrayList<>(); hosts.add(hostName); result.put(space, hosts); return result; |
Map | sort(Map sort Map<String, Object> result = new LinkedHashMap<String, Object>(); List<String> keys = new ArrayList<String>(source.keySet()); Collections.sort(keys); if (reverse) { Collections.reverse(keys); for (String key : keys) { result.put(key, source.get(key)); ... |
Map | sortByUsedSpace(Map sort By Used Space Map<Long, List<String>> sorted = sort(dataNodes, reverse); Map<String, Long> result = new LinkedHashMap<>(); for (long space : sorted.keySet()) { List<String> hosts = sorted.get(space); for (String host : hosts) { result.put(host, space); return result; |