Class MapUtils
java.lang.Object
org.apache.jackrabbit.oak.commons.collections.MapUtils
Utility methods for
Map conversions.-
Method Summary
Modifier and TypeMethodDescriptionstatic <K,V> @NotNull Map<K, V> filterEntries(@NotNull Map<K, V> map, @NotNull Predicate<? super Map.Entry<K, V>> predicate) static <K,V> @NotNull Map<K, V> filterKeys(@NotNull Map<K, V> map, @NotNull Predicate<? super K> predicate) Create a newMapafter filtering the entries of the given map based on the specified predicate applied to the keys.static <K,V> @NotNull Map<K, V> filterValues(@NotNull Map<K, V> map, @NotNull Predicate<? super V> predicate) Create a newMapafter filtering the entries of the given map based on the specified predicate applied to the values.fromProperties(@NotNull Properties properties) Converts aPropertiesobject to an unmodifiableMapwith string keys and values.static <K,V> @NotNull Map<K, V> newHashMap(int capacity) Creates a new, empty HashMap with expected capacity.
-
Method Details
-
newHashMap
Creates a new, empty HashMap with expected capacity.The returned map uses the default load factor of 0.75, and its capacity is large enough to add expected number of elements without resizing.
- Parameters:
capacity- the expected number of elements- Throws:
IllegalArgumentException- if capacity is negative- See Also:
-
fromProperties
@NotNull public static @NotNull Map<String,String> fromProperties(@NotNull @NotNull Properties properties) Converts aPropertiesobject to an unmodifiableMapwith string keys and values.- Parameters:
properties- thePropertiesobject to convert, must not be null- Returns:
- an unmodifiable
Mapcontaining the same entries as the givenPropertiesobject - Throws:
NullPointerException- if the properties parameter is null
-
filterKeys
@NotNull public static <K,V> @NotNull Map<K,V> filterKeys(@NotNull @NotNull Map<K, V> map, @NotNull @NotNull Predicate<? super K> predicate) Create a newMapafter filtering the entries of the given map based on the specified predicate applied to the keys.- Type Parameters:
K- the type of keys in the mapV- the type of values in the map- Parameters:
map- the map to filter, must not be nullpredicate- the predicate to apply to the keys, must not be null- Returns:
- a new map containing only the entries whose keys match the predicate
- Throws:
NullPointerException- if the map or predicate is null- See Also:
-
filterValues
@NotNull public static <K,V> @NotNull Map<K,V> filterValues(@NotNull @NotNull Map<K, V> map, @NotNull @NotNull Predicate<? super V> predicate) Create a newMapafter filtering the entries of the given map based on the specified predicate applied to the values.- Type Parameters:
K- the type of keys in the mapV- the type of values in the map- Parameters:
map- the map to filter, must not be nullpredicate- the predicate to apply to the values, must not be null- Returns:
- a new map containing only the entries whose values match the predicate
- Throws:
NullPointerException- if the map or predicate is null- See Also:
-
filterEntries
@NotNull public static <K,V> @NotNull Map<K,V> filterEntries(@NotNull @NotNull Map<K, V> map, @NotNull @NotNull Predicate<? super Map.Entry<K, V>> predicate) Create a newMapafter filtering the entries of the given map based on the specified predicate applied to theMap.Entry.- Type Parameters:
K- the type of keys in the mapV- the type of values in the map- Parameters:
map- the map to filter, must not be nullpredicate- the predicate to apply to theMap.Entry, must not be null- Returns:
- a new map containing only the entries whose values match the predicate
- Throws:
NullPointerException- if the map or predicate is null- See Also:
-