Package io.sentry.util
Class CollectionUtils
java.lang.Object
io.sentry.util.CollectionUtils
Util class for Collections
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
A simple function to map an object into another.static interface
A simplified copy of Java 8 Predicate. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> boolean
contains
(@NotNull T[] array, T element) Returns true if the element is present in the array, false otherwise.static <T> @NotNull List<T>
filterListEntries
(@NotNull List<T> list, @NotNull CollectionUtils.Predicate<T> predicate) Returns a new list which entries match a predicate specified by a parameter.static <K,
V> @NotNull Map<K, V> filterMapEntries
(@NotNull Map<K, V> map, @NotNull CollectionUtils.Predicate<Map.Entry<K, V>> predicate) Returns a new map which entries match a predicate specified by a parameter.static <T,
R> @NotNull List<R> map
(@NotNull List<T> list, @NotNull CollectionUtils.Mapper<T, R> f) Returns a new list with the results of the function applied to all elements of the original list.static <T> @Nullable List<T>
newArrayList
(@Nullable List<T> list) Creates a newArrayList
as a shallow copy of list given by parameter.static <K,
V> @Nullable Map<K, @NotNull V> newConcurrentHashMap
(@Nullable Map<K, @NotNull V> map) Creates a newConcurrentHashMap
as a shallow copy of map given by parameter.static <K,
V> @Nullable Map<K, @NotNull V> newHashMap
(@Nullable Map<K, @NotNull V> map) Creates a newHashMap
as a shallow copy of map given by parameter.static int
Returns an Iterator size
-
Method Details
-
size
Returns an Iterator size- Parameters:
data
- the Iterable- Returns:
- iterator size
-
newConcurrentHashMap
@Nullable public static <K,V> @Nullable Map<K,@NotNull V> newConcurrentHashMap(@Nullable @Nullable Map<K, @NotNull V> map) Creates a newConcurrentHashMap
as a shallow copy of map given by parameter. Also makes sure no null keys or values are put into the resultingConcurrentHashMap
.- Type Parameters:
K
- the type of map keysV
- the type of map values- Parameters:
map
- the map to copy- Returns:
- the shallow copy of map
-
newHashMap
@Nullable public static <K,V> @Nullable Map<K,@NotNull V> newHashMap(@Nullable @Nullable Map<K, @NotNull V> map) Creates a newHashMap
as a shallow copy of map given by parameter.- Type Parameters:
K
- the type of map keysV
- the type of map values- Parameters:
map
- the map to copy- Returns:
- a new
HashMap
ornull
if parameter isnull
-
newArrayList
Creates a newArrayList
as a shallow copy of list given by parameter.- Type Parameters:
T
- the type of list entries- Parameters:
list
- the list to copy- Returns:
- a new
ArrayList
ornull
if parameter isnull
-
filterMapEntries
@NotNull public static <K,V> @NotNull Map<K,V> filterMapEntries(@NotNull @NotNull Map<K, V> map, @NotNull @NotNull CollectionUtils.Predicate<Map.Entry<K, V>> predicate) Returns a new map which entries match a predicate specified by a parameter.- Type Parameters:
K
- - map entry key typeV
- - map entry value type- Parameters:
map
- - the map to filterpredicate
- - the predicate- Returns:
- a new map
-
map
@NotNull public static <T,R> @NotNull List<R> map(@NotNull @NotNull List<T> list, @NotNull @NotNull CollectionUtils.Mapper<T, R> f) Returns a new list with the results of the function applied to all elements of the original list.- Type Parameters:
T
- - original list element typeR
- - returned list element type- Parameters:
list
- - the list to apply the function tof
- - the function- Returns:
- a new list
-
filterListEntries
@NotNull public static <T> @NotNull List<T> filterListEntries(@NotNull @NotNull List<T> list, @NotNull @NotNull CollectionUtils.Predicate<T> predicate) Returns a new list which entries match a predicate specified by a parameter.- Parameters:
predicate
- - the predicate- Returns:
- a new list
-
contains
public static <T> boolean contains(@NotNull @NotNull T[] array, @NotNull T element) Returns true if the element is present in the array, false otherwise.- Parameters:
array
- - the arrayelement
- - the element- Returns:
- true if the element is present in the array, false otherwise.
-