public final class FilterUtils
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static <T,C extends java.util.Collection<T>> |
filter(java.util.Collection<T> objects,
org.perro.functions.predicate.FilterCollector<T,C> filterCollector)
Filters a collection of objects, based a predicate, into a
Collection. |
static <T> java.util.List<T> |
filter(java.util.Collection<T> objects,
java.util.function.Predicate<T> predicate)
Filters a
Collection of objects, based a predicate, into a list. |
static <T,C extends java.util.Collection<T>> |
filterAndThen(java.util.function.Predicate<T> filter,
java.util.stream.Collector<T,?,C> collector)
Builds an object combining a
Predicate and a Collector for use in the filter(Collection, FilterCollector) method. |
static <T> java.util.List<T> |
filterDistinct(java.util.Collection<T> objects,
java.util.function.Predicate<T> predicate)
Filters a
Collection of objects, based a predicate, into a list of distinct instances (according to
Object.equals(Object)). |
static <T> java.util.Set<T> |
filterToSet(java.util.Collection<T> objects,
java.util.function.Predicate<T> predicate)
Filters a
Collection of objects, based a predicate, into a set. |
public static <T> java.util.List<T> filter(java.util.Collection<T> objects,
java.util.function.Predicate<T> predicate)
Collection of objects, based a predicate, into a list.T - The target element type for the objects Collection.objects - A collection of objects of type <T> to be filtered.predicate - A predicate with which to filter the objects collection. The provided predicate will be made
null-safe, and if the target is null, then the predicate will return false.public static <T> java.util.Set<T> filterToSet(java.util.Collection<T> objects,
java.util.function.Predicate<T> predicate)
Collection of objects, based a predicate, into a set.T - The target element type for the objects Collection.objects - A collection of objects of type <T> to be filtered.predicate - A predicate with which to filter the objects collection. The provided predicate will be made
null-safe, and if the target is null, then the predicate will return false.public static <T> java.util.List<T> filterDistinct(java.util.Collection<T> objects,
java.util.function.Predicate<T> predicate)
Collection of objects, based a predicate, into a list of distinct instances (according to
Object.equals(Object)).T - The target element type for the objects Collection.objects - A Collection of objects of type <T> to be filtered.predicate - A predicate with which to filter the objects collection. The provided predicate will be made
null-safe, and if the target is null, then the predicate will return false.public static <T,C extends java.util.Collection<T>> C filter(java.util.Collection<T> objects,
org.perro.functions.predicate.FilterCollector<T,C> filterCollector)
Collection. This overload takes an object
that is built using the filterAndThen(Predicate, Collector) method, which allows you to specify both a
predicate and a Collector to build any type of Collection as a result. For
example:
Collection<Widget> widgets = ...
List<Widget> = FilterUtils.filter(widgets, FilterUtils.filterAndThen(Widget::isConsumerProduct, Collectors.toCollection(LinkedList::new)));
Or, with static imports:
filter(widgets, filterAndThen(Widget::isConsumerProduct, toCollection(LinkedList::new)));
T - The target element type for the objects Collection.C - The type of the resulting Collection.objects - A Collection of objects of type <T> to be filtered.filterCollector - An object containing a predicate with which to filter the objects Collection, and a
Collector to accumulate results into a Collection.public static <T,C extends java.util.Collection<T>> org.perro.functions.predicate.FilterCollector<T,C> filterAndThen(java.util.function.Predicate<T> filter,
java.util.stream.Collector<T,?,C> collector)
Predicate and a Collector for use in the filter(Collection, FilterCollector) method.T - The target element type for a collection to be filtered.C - The type of the resulting Collection.filter - A Predicate for filtering elements from a Collection of objects. The provided predicate will be
made null-safe, and if the target is null, then the predicate will return false.collector - A Collector to accumulating elements into a Collection of any type.