Class CollectionUtils

java.lang.Object
nl.vpro.domain.media.CollectionUtils

public class CollectionUtils extends Object
Some static methods used in this package that are related to dealing with collections
Since:
5.12
Author:
Michiel Meeuwissen
  • Method Details

    • getFromList

      protected static <E> @Nullable E getFromList(@Nullable List<@NonNull E> list)
    • indexOf

      public static <E> int indexOf(List<E> list, E o, int offset)
    • createIfNull

      public static <P extends Comparable<P>> SortedSet<P> createIfNull(SortedSet<P> set)
    • createIfNullUnlessNull

      public static <P extends Comparable<P>> @Nullable SortedSet<P> createIfNullUnlessNull(@Nullable SortedSet<P> set, @Nullable Object check)
    • inCollection

      public static <P> boolean inCollection(@NonNull Collection<@NonNull P> col, @Nullable P element)
      null-safe Collection.contains(Object). null is never in the list.

      Mainly because link java 9's Immutable lists resulting from things as List.of() throw exception if called with null (Things like Collections.unmodifiableList(List) didn't behave like that).

      Since:
      7.2
    • nullSafeSet

      public static <P> Set<@NonNull P> nullSafeSet(@NonNull Set<@NonNull P> set)
      Wraps the given set in a new set, with the same elements.

      The only difference will be that its Set.contains(Object) will simply return false if the argument is null.

      Since:
      7.10
    • nullSafeSet

      public static <P> Set<@NonNull P> nullSafeSet(@NonNull Set<@NonNull P> set, boolean containsNull)
    • removeIf

      public static <E> int removeIf(Collection<E> collection, Predicate<? super E> filter)
      Like Collection.removeIf(Predicate) but returns the number of removed items. TODO it seems odd that we would be the first to want this? Guava?
      Since:
      7.10