Package nl.vpro.domain.media
Class CollectionUtils
java.lang.Object
nl.vpro.domain.media.CollectionUtils
Some static methods used in this package that are related to dealing with collections
- Since:
- 5.12
- Author:
- Michiel Meeuwissen
-
Method Summary
Modifier and TypeMethodDescriptionstatic <P extends Comparable<P>>
SortedSet<P>createIfNull
(SortedSet<P> set) static <P extends Comparable<P>>
@Nullable SortedSet<P>createIfNullUnlessNull
(@Nullable SortedSet<P> set, @Nullable Object check) protected static <E> @Nullable E
getFromList
(@Nullable List<@NonNull E> list) static <P> boolean
inCollection
(@NonNull Collection<@NonNull P> col, @Nullable P element) null
-safeCollection.contains(Object)
.static <E> int
static <P> Set<@NonNull P>
nullSafeSet
(@NonNull Set<@NonNull P> set) Wraps the given set in a new set, with the same elements.static <P> Set<@NonNull P>
nullSafeSet
(@NonNull Set<@NonNull P> set, boolean containsNull) static <E> int
removeIf
(Collection<E> collection, Predicate<? super E> filter) LikeCollection.removeIf(Predicate)
but returns the number of removed items.
-
Method Details
-
getFromList
-
indexOf
-
createIfNull
-
createIfNullUnlessNull
public static <P extends Comparable<P>> @Nullable SortedSet<P> createIfNullUnlessNull(@Nullable SortedSet<P> set, @Nullable Object check) -
inCollection
null
-safeCollection.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 withnull
(Things likeCollections.unmodifiableList(List)
didn't behave like that).- Since:
- 7.2
-
nullSafeSet
Wraps the given set in a new set, with the same elements.The only difference will be that its
Set.contains(Object)
will simply returnfalse
if the argument isnull
.- Since:
- 7.10
-
nullSafeSet
-
removeIf
LikeCollection.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
-