public class CollectionUtil extends Object
| Constructor and Description |
|---|
CollectionUtil() |
| Modifier and Type | Method and Description |
|---|---|
static <K,V> V |
getOrDefault(Map<K,V> map,
K key,
Function<K,V> supplier)
A getOrDefault that doesn't create garbage if its suppler is non-capturing.
|
static <T> int |
removeIf(List<T> values,
Predicate<T> predicate)
Remove element from a list if it matches a predicate.
|
static <V> int |
sum(List<V> values,
ToIntFunction<V> function)
Garbage free sum function.
|
static void |
validateLoadFactor(float loadFactor)
Validate that a load factor is in the range of 0.1 to 0.9.
|
static void |
validatePositivePowerOfTwo(int value)
Validate that a number is a power of two.
|
public static <K,V> V getOrDefault(Map<K,V> map, K key, Function<K,V> supplier)
K - type of the keyV - type of the valuemap - to perform the lookup on.key - on which the lookup is done.supplier - of the default value if one is not found.public static <V> int sum(List<V> values, ToIntFunction<V> function)
Note: the list must implement RandomAccess to be efficient.
V - the value to add upvalues - the list of input valuesfunction - function that map each value to an intpublic static void validateLoadFactor(float loadFactor)
Load factors in the range 0.5 - 0.7 are recommended for open-addressing with linear probing.
loadFactor - to be validated.public static void validatePositivePowerOfTwo(int value)
value - to be validated.public static <T> int removeIf(List<T> values, Predicate<T> predicate)
Note: the list must implement RandomAccess to be efficient.
T - type of the value.values - to be iterated over.predicate - to test the value against