Class AbstractFilteringList<Type,​ListType extends 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 
      Modifier and Type Method Description
      java.util.List<Type> asList()
      Returns the items in this as an immutable list.
      ListType concat​(ListType others)
      Returns the union of the two lists.
      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.
      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 randomness
      int size()  
      ListType sortedBy​(java.util.Comparator<? super Type> comparator)
      Returns the items sorted by the given comparator.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Constructor Detail

      • AbstractFilteringList

        protected AbstractFilteringList​(java.util.Collection<? extends Type> items,
                                        boolean negate,
                                        java.util.function.BiFunction<java.util.List<Type>,​java.lang.Boolean,​ListType> constructor)
    • 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.
      • concat

        public ListType concat​(ListType others)
        Returns the union of the two lists.
      • asList

        public final java.util.List<Type> asList()
        Returns the items in this as an immutable list.
      • 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.
      • isEmpty

        public final boolean isEmpty()
      • size

        public final int size()
      • iterator

        public java.util.Iterator<Type> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<Type>
      • shuffle

        public final ListType shuffle​(java.util.Random random)
        Returns the items in this shuffled using random as source of randomness