<p>Casts a map in a lazy fashion. Changes to the returned map are reflected in the
the given map.</p>

@param <K> the type parameter
@param <V> the type parameter
@param map the map to cast
@return the casted map or null if the map is null
971620
public static <K, V> Map<K, V> cast(Map<?, ?> map) {
    return map == null ? null : new CastingMap<K, V>(map);
  }
937692
protected final Map<K, V> copyMap(Map<K, Expirable<V>> map) {
    ClassLoader classLoader = cacheManager.getClassLoader();
    return map.entrySet().stream().collect(toMap(
        entry -> copier.copy(entry.getKey(), classLoader),
        entry -> copier.copy(entry.getValue().get(), classLoader)));
  }
725359
public <T extends Map<?, ?>> T notEmpty(final T map, final String message) {
        if (map == null) {
            failNull(message);
        }
        if (map.isEmpty()) {
            fail(message);
        }
        return map;
    }
454924
public void append(Map<?, ?> map) {
		if (map == null || map.size() == 0)
			return;

		for (Map.Entry<?, ?> entry : map.entrySet()) {
			put(StringConverter.toString(entry.getKey()), StringConverter.toNullableString(entry.getValue()));
		}
	}
1323336
public static <T> T get(Map<?, ?> map, Object key, Class<T> type) {
		return null == map ? null : Convert.convert(type, map.get(key));
	}
887510
public static <K, V> Map<K, V> immutableMapView(Map<K, V> map) {
        if (map instanceof ImmutableMap<?, ?>) {
            return map;
        }
        return Collections.unmodifiableMap(map);
    }
1209411
public static <K, V> Map<K, V> toImmutableMap(final Map<K, V> map) {
    switch (map.size()) {
      case 0:
        return Collections.emptyMap();
      case 1:
        final Entry<K, V> entry = map.entrySet().iterator().next();
        return Collections.singletonMap(entry.getKey(), entry.getValue());
      default:
        return Collections.unmodifiableMap(map);
    }
  }
352860
public static <K, V> Map<K, V> asDeepTierMap(Map<K, V> map) {
        return from(map).deepLook().tierKey().map();
    }
1222117
public void putAllWriteable(BeanMap<T> map) {
        map.types.keySet().stream().filter(key -> getWriteInvoker(key) != null).forEach(key -> this.put(key, map.get(key)));
    }
845380
public static Mapper mapMapper(final Map map) {
        return new Mapper() {
            public Object map(final Object a) {
                return map.get(a);
            }
        };
    }
484706
public static <K, E, V extends Set<E>> Set<E> getOrEmptySet(final Map<K, V> map, final Object key) {
        if (N.isNullOrEmpty(map)) {
            return N.<E> emptySet();
        }

        final V val = map.get(key);

        if (val != null || map.containsKey(key)) {
            return val;
        } else {
            return N.emptySet();
        }
    }
1255060
public static <K, V> Map<K, V> sortByValue(Map<K, V> map, BeanComparator beanComparator)
	{
		return map.entrySet()
		.stream()
		.sorted(Map.Entry.comparingByValue(beanComparator))
		.collect(Collectors.toMap(
		Map.Entry::getKey,
		Map.Entry::getValue,
		(e1, e2) -> e1,
		LinkedHashMap::new));
	}
1313830
public static <K, V> Map<K, V> sortNumberMapByKeyDescending(Map<K, V> map) {
        return sortNumberMapByKeyDescending(map.entrySet());
    }
69956
public static <K, V extends Comparable<V>> Stream<Entry<K, V>>
    sortedStreamByValue(Map<K, V> map) {
        return buildEntryStream(map).sorted(comparing(Entry::getValue));
    }
1246438
public static <K,V> MapAdapter<K,V> mapAdapter(final Map<K,V> map) {
        return key -> Optional.ofNullable(map.get(key));
    }
540480
public static String serializeMap(Map<String, String> map) {
        if (map == null) {
            map = new HashMap<String, String>();
        }
        XStream xstream = new XStream(new DomDriver());
        return xstream.toXML(map);
    }
1039212
public static <K, KK, VV> Map<KK, VV> getAndPutMapIfAbsent(final Map<K, Map<KK, VV>> map, final K key) {
        Map<KK, VV> v = map.get(key);

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

        return v;
    }