Package com.yahoo.collections
Class AbstractFilteringList<Type,ListType extends AbstractFilteringList<Type,ListType>>
- java.lang.Object
-
- com.yahoo.collections.AbstractFilteringList<Type,ListType>
-
- All Implemented Interfaces:
java.lang.Iterable<Type>
public abstract class AbstractFilteringList<Type,ListType extends AbstractFilteringList<Type,ListType>> extends java.lang.Object implements java.lang.Iterable<Type>
Abstract, immutable list for subclassing with concrete types and domain specific filters.- Author:
- jonmv
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractFilteringList(java.util.Collection<? extends Type> items, boolean negate, java.util.function.BiFunction<java.util.List<Type>,java.lang.Boolean,ListType> constructor)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description ListType
and(ListType others)
Returns the union of the two lists.java.util.List<Type>
asList()
Returns the items in this as an immutable list.java.util.Set<Type>
asSet()
Returns the items in this as a set.ListType
concat(ListType others)
Deprecated.use and(others)java.util.Optional<Type>
first()
Returns the first item in this list, or empty if there are none.ListType
first(int n)
Returns the first n items in this list, or everything except those if negated.<OtherType>
java.util.Map<OtherType,ListType>groupingBy(java.util.function.Function<Type,OtherType> classifier)
Returns the items grouped by the given classifier.ListType
in(ListType others)
Returns the subset of items in this which are (not) present in the other list.boolean
isEmpty()
java.util.Iterator<Type>
iterator()
<OtherType>
java.util.List<OtherType>mapToList(java.util.function.Function<Type,OtherType> mapper)
Returns the items in this as an immutable list after mapping with the given function.ListType
matching(java.util.function.Predicate<Type> condition)
Returns a new list which is the result of filtering with the -- possibly negated -- condition.ListType
not()
Negates the next filter operation.ListType
shuffle(java.util.Random random)
Returns the items in this shuffled using random as source of randomnessint
size()
ListType
sortedBy(java.util.Comparator<? super Type> comparator)
Returns the items sorted by the given comparator.java.util.Spliterator<Type>
spliterator()
-
-
-
Method Detail
-
not
public final ListType not()
Negates the next filter operation. All other operations which return a new list reset this modifier.
-
matching
public final ListType matching(java.util.function.Predicate<Type> condition)
Returns a new list which is the result of filtering with the -- possibly negated -- condition.
-
first
public ListType first(int n)
Returns the first n items in this list, or everything except those if negated.
-
first
public java.util.Optional<Type> first()
Returns the first item in this list, or empty if there are none.
-
in
public ListType in(ListType others)
Returns the subset of items in this which are (not) present in the other list.
-
asList
public final java.util.List<Type> asList()
Returns the items in this as an immutable list.
-
asSet
public final java.util.Set<Type> asSet()
Returns the items in this as a set.
-
mapToList
public final <OtherType> java.util.List<OtherType> mapToList(java.util.function.Function<Type,OtherType> mapper)
Returns the items in this as an immutable list after mapping with the given function.
-
sortedBy
public final ListType sortedBy(java.util.Comparator<? super Type> comparator)
Returns the items sorted by the given comparator.
-
groupingBy
public final <OtherType> java.util.Map<OtherType,ListType> groupingBy(java.util.function.Function<Type,OtherType> classifier)
Returns the items grouped by the given classifier.
-
isEmpty
public final boolean isEmpty()
-
size
public final int size()
-
iterator
public java.util.Iterator<Type> iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<Type>
-
spliterator
public java.util.Spliterator<Type> spliterator()
- Specified by:
spliterator
in interfacejava.lang.Iterable<Type>
-
shuffle
public final ListType shuffle(java.util.Random random)
Returns the items in this shuffled using random as source of randomness
-
-