Class CollectionUtils

java.lang.Object
io.sentry.util.CollectionUtils

@Internal public final class CollectionUtils extends Object
Util class for Collections
  • Method Details

    • size

      public static int size(@NotNull @NotNull Iterable<?> data)
      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 new ConcurrentHashMap as a shallow copy of map given by parameter. Also makes sure no null keys or values are put into the resulting ConcurrentHashMap.
      Type Parameters:
      K - the type of map keys
      V - 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 new HashMap as a shallow copy of map given by parameter.
      Type Parameters:
      K - the type of map keys
      V - the type of map values
      Parameters:
      map - the map to copy
      Returns:
      a new HashMap or null if parameter is null
    • newArrayList

      @Nullable public static <T> @Nullable List<T> newArrayList(@Nullable @Nullable List<T> list)
      Creates a new ArrayList 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 or null if parameter is null
    • 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 type
      V - - map entry value type
      Parameters:
      map - - the map to filter
      predicate - - 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 type
      R - - returned list element type
      Parameters:
      list - - the list to apply the function to
      f - - 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 array
      element - - the element
      Returns:
      true if the element is present in the array, false otherwise.