Get the array of all keys in the given map.

@param <K> The component type of the keys

@param map The map to get the keys from

@return The array of all keys in the map
347439
@SuppressWarnings("unchecked")
    public <K> K[] getKeys(Map<K, ?> map) {
        K[] result = null;
        Set<K> keySet = map.keySet();
        if (keySet.size() > 0) {
            result = (K[]) keySet.toArray(new Object[keySet.size()]);
        }
        
        return result;
    }
152086
public static List<Map<String, Object>> nest(String key, Dictionary<String, Object> map) {
        List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
        String patternString = MessageFormat.format("^{0}\\.([0-9]*)\\.(.*)", Pattern.quote(key));
        Pattern pattern = Pattern.compile(patternString);

        for (Enumeration<String> e = map.keys(); e.hasMoreElements();) {
            String k = e.nextElement();
            Matcher matcher = pattern.matcher(k);
            if (matcher.matches()) {
                int base = 0;
                processMatch(result, map.get(k), matcher, base);
            }
        }
        return result;
    }
858789
public static Set<String> getKeysIn(final Map map, final Object... path) {
        return getMap(map, path)
            .map(m -> m
                .keySet()
                .stream()
                .map(Object::toString)
                .collect(Collectors.toSet())
            ).orElse(new HashSet<>());
    }
620554
public void putAll(Map<? extends K, ? extends V> map) {
        //synchronized( this ) {
            for(K key : map.keySet() ) {
                put(key, map.get(key));
            }
        //}
    }
928744
public static <K, V> Map<K, V> sortNumberMapByKeyAscending(Map<K, V> map) {
        return sortNumberMapByKeyAscending(map.entrySet());
    }
1307932
private void readMap(final Element map, final Map<String, KeyDef> keyDefs) {
        readKeyDefinition(map, keyDefs);
        for (final Element elem: getChildElements(map)) {
            if (!(SUBMAP.matches(elem) || elem.getAttributeNode(ATTRIBUTE_NAME_KEYSCOPE) != null)) {
                readMap(elem, keyDefs);
            }
        }
    }
579914
public static <K extends Comparable<K>, V> String toStringSorted(Map<K, V> map) {
    StringBuilder builder = new StringBuilder();
    toStringSorted(map, builder);
    return builder.toString();
  }
562658
List<V> get( K key ) {
        List<V> result = map.get( key );
        if( parent != null ) {
            List<V> resultParent = parent.get( key );
            if( result == null ) {
                return resultParent;
            } else if( resultParent == null ){
                return result;
            } else {
                for( V value : resultParent ) {
                    if( !result.contains( value ) ) {
                        result.add( value );
                    }
                }
            }
        }
        return result;
    }
448646
public static void getExtensions(Map<String, String> map)
                    throws IllegalArgumentException {
        if (map == null) {
            throw new IllegalArgumentException(
                            "Parameter 'map' can not be null.");
        }
        if (recursion.get() == Boolean.TRUE) {
            return;
        }
        recursion.set(Boolean.TRUE);
        LinkedList<String> cleanup = new LinkedList<String>();
        r.lock();
        try {
            for (Map.Entry<String, WeakReference<Extension>> entry : extensionMap
                            .entrySet()) {
                Extension extension = entry.getValue().get();
                if (extension == null) {
                    cleanup.add(entry.getKey());
                } else {
                    String value = extension.getValue();
                    if (value != null) {
                        map.put(entry.getKey(), value);
                    }
                }
            }
        } finally {
            r.unlock();
            recursion.remove();
        }
        if (cleanup.size() > 0) {
            w.lock();
            try {
                for (String key : cleanup) {
                    WeakReference<Extension> extension = extensionMap
                                    .remove(key);
                    if (extension != null && extension.get() != null) {
                        // Special case! Somebody has put new extension for this
                        // key after we released
                        // read lock and before we took write lock. We need to
                        // put it back.
                        extensionMap.put(key, extension);
                    }
                }
            } finally {
                w.unlock();
            }
        }
        if (extensions.get() != null) {
            for (Entry<String, String> entry : extensions.get().entrySet()) {
                map.put(entry.getKey(), entry.getValue());
            }
        }

    }
812400
public static <K,V> List<Pair<K,V>> mapToPair(Map<K,V> map) {
        List<Pair<K,V>> ret = new ArrayList<>(map.size());
        for(Map.Entry<K,V> entry : map.entrySet()) {
            ret.add(Pair.of(entry.getKey(),entry.getValue()));
        }

        return ret;
    }
306709
public void putAll(Map<? extends K, ? extends V> map) {
    for (Map.Entry<? extends K, ? extends V> e : map.entrySet()) {
      addEntry(e.getKey(), e.getValue());
    }
  }
1341775
public static <K> Integer getCount(Map<K, Integer> map, K k)
    {
        Integer count = map.get(k);
        if (count == null)
        {
            count = 0;
            map.put(k, count);
        }
        return count;
    }
1035421
public List<V> getAll(Object key) {
        List<V> res = map.get(key);
        if (res == null) {
            res = Collections.emptyList();
        }
        return res;
    }
275075
public List<K> getKeys() {
        synchronized ( _map ) {
            return new java.util.ArrayList<K>( _map.keySet() );
        }
    }
858156
public static boolean mapContainsKeys(Map<?, ?> _map, Object... _keys) {
        if (_map == null) {
            return false;
        } else if (_keys == null) {
            return true;
        }
        for (Object key : _keys) {
            if (key != null && !_map.containsKey(key)) {
                return false;
            }
        }
        return true;
    }
385384
public static <K extends Comparable< ? super K>,V extends Comparable< ? super V>> List<Entry<K,V>>
            sortKeyValuePairByValue(Map<K,V> map) {
        List<Map.Entry<K,V>> entries = new ArrayList<Map.Entry<K,V>>(map.entrySet());
        Collections.sort(entries, new Comparator<Map.Entry<K,V>>() {
            @Override
            public int compare(Entry<K,V> o1, Entry<K,V> o2) {
                if (!o1.getValue().equals(o2.getValue())) {
                    return (o1.getValue()).compareTo(o2.getValue());
                }
                return o1.getKey().compareTo(o2.getKey());
            }
        } );
        return entries;
    }
1135015
public static <K, E> Set<E> getAndPutLinkedHashSetIfAbsent(final Map<K, Set<E>> map, final K key) {
        Set<E> v = map.get(key);

        if (v == null) {
            v = new LinkedHashSet<>();
            v = map.put(key, v);
        }

        return v;
    }