Class MapUtils
- java.lang.Object
-
- org.apache.jackrabbit.oak.commons.collections.MapUtils
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <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 newMap
after 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 newMap
after filtering the entries of the given map based on the specified predicate applied to the values.static @NotNull Map<String,String>
fromProperties(@NotNull Properties properties)
Converts aProperties
object to an unmodifiableMap
with string keys and values.static <K,V>
@NotNull Map<K,V>newHashMap(int capacity)
Creates a new, empty HashMap with expected capacity.
-
-
-
Method Detail
-
newHashMap
@NotNull public static <K,V> @NotNull Map<K,V> newHashMap(int capacity)
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:
SetUtils.newHashSet(int)
,SetUtils.newLinkedHashSet(int)
-
fromProperties
@NotNull public static @NotNull Map<String,String> fromProperties(@NotNull @NotNull Properties properties)
Converts aProperties
object to an unmodifiableMap
with string keys and values.- Parameters:
properties
- theProperties
object to convert, must not be null- Returns:
- an unmodifiable
Map
containing the same entries as the givenProperties
object - 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 newMap
after 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(Map, Predicate)
,filterEntries(Map, Predicate)
-
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 newMap
after 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:
filterKeys(Map, Predicate)
,filterEntries(Map, Predicate)
-
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 newMap
after 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:
filterKeys(Map, Predicate)
,filterValues(Map, Predicate)
-
-