Interface Enumerable<T>

Type Parameters:
T - type of element in the Enumerable
All Superinterfaces:
Iterable<T>
All Known Subinterfaces:
Array<T>, AssociatedEnumerable<K,V>, Association<K,V>, Assortment<T>, DistinctAssortment<T>, EditableAssociation<K,V>, EditableSequence<T>, PropertiesMirror<T>, ResizableAssociation<K,V>, ResizableDistinctAssortment<T>, ResizableSequence<T>, Sequence<T>
All Known Implementing Classes:
AbstractEnumerableDecorator, ArithmeticalEnumerable

public interface Enumerable<T> extends Iterable<T>
An Iterable with fluent stream like transformation methods
  • Method Details

    • empty

      static <X> Enumerable<X> empty()
      Returns an empty instance.
      Returns:
      the result of empty
    • generate

      static <X> Enumerable<X> generate(Supplier<X> supplier)
      Performs generate.
      Parameters:
      supplier - the supplier value
      Returns:
      the result of generate
    • iterate

      static <X> Enumerable<X> iterate(X seed, Function<X,X> successor)
      Performs iterate.
      Parameters:
      seed - the seed value
      successor - the successor value
      Returns:
      the result of iterate
    • from

      static <X> Enumerable<X> from(Iterable<X> iterable)
      Creates an instance from the provided source.
      Parameters:
      iterable - the iterable value
      Returns:
      the result of from
    • single

      static <X> Enumerable<X> single(X value)
      Performs single.
      Parameters:
      value - the value value
      Returns:
      the result of single
    • from

      static <X> Enumerable<X> from(Optional<X> optional)
      Creates an instance from the provided source.
      Parameters:
      optional - the optional value
      Returns:
      the result of from
    • enumerator

      Enumerator<T> enumerator()
      Returns an enumerator over the elements.
      Returns:
      the result of enumerator
    • iterator

      default Iterator<T> iterator()
      Returns an iterator over the elements.
      Specified by:
      iterator in interface Iterable<T>
      Returns:
      the result of iterator
    • first

      default Maybe<T> first()
      Performs first.
      Returns:
      the result of first
    • count

      default Int count()
      Best effort to count the elements. If the Enumerable is Infinite, an {link IllegalStateException} will be thrown
      Returns:
      the number of elements in the Enumerable
    • isEmpty

      default boolean isEmpty()
      Checks whether is Empty.
      Returns:
      the result of isEmpty
    • any

      default boolean any()
      Performs any.
      Returns:
      the result of any
    • toSequence

      default Sequence<T> toSequence() throws InfiniteEnumerableException
      Returns a Sequence with the elements in this Enumerable. The Enumerable must be finite or an exception will be thrown
      Returns:
      the result of toSequence
      Throws:
      IllegalStateException - if the Enumerable is infinite
      InfiniteEnumerableException
    • toSequence

      default <S extends EditableSequence<T>> S toSequence(Supplier<S> supplier) throws InfiniteEnumerableException
      Returns to Sequence.
      Parameters:
      supplier - the supplier value
      Returns:
      the result of toSequence
      Throws:
      InfiniteEnumerableException - if the Enumerable is infinite
    • toDistinctAssortment

      default DistinctAssortment<T> toDistinctAssortment() throws InfiniteEnumerableException
      Returns to Distinct Assortment.
      Returns:
      the result of toDistinctAssortment
      Throws:
      InfiniteEnumerableException - if the Enumerable is infinite
    • toArray

      default Object[] toArray() throws InfiniteEnumerableException
      Creates an array on Object and copies all elements in this to that array. This operation is only possible if the Enumerable is not infinite and its length is less than Integer.MAX_VALUE.
      Returns:
      an array containing all elements in this
      Throws:
      InfiniteEnumerableException - if the Enumerable is infinite
    • toArray

      default T[] toArray(T[] templateArray) throws InfiniteEnumerableException
      Returns a typed array containing all elements in @{code this}. This operation is only possible if the Enumerable is not infinite and its length is less than Integer.MAX_VALUE. If the given array is of the same size, or larger, as the enumerable, it is filled with the values in @{code this} and returned. Otherwise, a new array of the correct size if create from it, with the values in @{code this} copied and returned.
      Parameters:
      templateArray - the template array
      Returns:
      an array containing all elements in @{code this}
      Throws:
      InfiniteEnumerableException - if the Enumerable is infinite
    • toArray

      default T[] toArray(IntFunction<T[]> generator) throws InfiniteEnumerableException
      Returns a typed array containing all elements in @{code this}. The given generator is called to produce an array of the correct size. Then, it is filled with the values in @{code this} and returned.
      Parameters:
      generator - the template array
      Returns:
      an array containing all elements in @{code this}
      Throws:
      InfiniteEnumerableException - if the Enumerable is infinite
    • anyMatch

      default boolean anyMatch(Predicate<T> predicate)
      Performs anyMatch.
      Parameters:
      predicate - the predicate value
      Returns:
      the result of anyMatch
    • allMatch

      default boolean allMatch(Predicate<T> predicate) throws InfiniteEnumerableException
      Performs allMatch.
      Parameters:
      predicate - the predicate value
      Returns:
      the result of allMatch
      Throws:
      InfiniteEnumerableException - if the Enumerable is infinite
    • reduce

      default <A> A reduce(A seed, BiFunction<A,T,A> accumulator) throws InfiniteEnumerableException
      Reduce the Enumerable to a single value by operating between a seed value and each element.
      Parameters:
      seed - the seed value
      accumulator - the accumulator value
      Returns:
      the result of reduce
      Throws:
      InfiniteEnumerableException - if the Enumerable is infinite
    • reduce

      default Maybe<T> reduce(BiFunction<T,T,T> accumulator) throws InfiniteEnumerableException
      Reduce the Enumerable to a single value by operating between each element.
      Parameters:
      accumulator - the accumulator value
      Returns:
      the result of reduce
      Throws:
      InfiniteEnumerableException
    • minimum

      default Maybe<T> minimum(Comparator<T> comparator)
      Performs minimum.
      Parameters:
      comparator - the comparator value
      Returns:
      the result of minimum
    • maximum

      default Maybe<T> maximum(Comparator<T> comparator)
      Performs maximum.
      Parameters:
      comparator - the comparator value
      Returns:
      the result of maximum
    • with

      default <S> ArithmeticalEnumerable<T,S> with(Arithmetic<T,S> arithmetic)
      Performs with.
      Parameters:
      arithmetic - the arithmetic value
      Returns:
      the result of with
    • as

      default <E extends Enumerable<T>> E as(EnumerableExtension<T,E> extension)
      Performs as.
      Parameters:
      extension - the extension value
      Returns:
      the result of as
    • concat

      default Enumerable<T> concat(Enumerable<T> other)
      Performs concat.
      Parameters:
      other - the other value
      Returns:
      the result of concat
    • filter

      default Enumerable<T> filter(Predicate<T> predicate)
      Performs filter.
      Parameters:
      predicate - the predicate value
      Returns:
      the result of filter
    • map

      default <R> Enumerable<R> map(Function<T,R> transform)
      Performs map.
      Parameters:
      transform - the transform value
      Returns:
      the result of map
    • flatMap

      default <R> Enumerable<R> flatMap(Function<T,Enumerable<R>> transform)
      Performs flatMap.
      Parameters:
      transform - the transform value
      Returns:
      the result of flatMap
    • peek

      default Enumerable<T> peek(Consumer<T> consumer)
      Performs peek.
      Parameters:
      consumer - the consumer value
      Returns:
      the result of peek
    • zip

      default <S, R> Enumerable<R> zip(Enumerable<S> other, BiFunction<T,S,R> transform)
      Performs zip.
      Parameters:
      other - the other value
      transform - the transform value
      Returns:
      the result of zip
    • limit

      default Enumerable<T> limit(long maxCount)
      Performs limit.
      Parameters:
      maxCount - the maxCount value
      Returns:
      the result of limit
    • skip

      default Enumerable<T> skip(long minCount)
      Performs skip.
      Parameters:
      minCount - the minCount value
      Returns:
      the result of skip
    • distinct

      default Enumerable<T> distinct()
      Performs distinct.
      Returns:
      the result of distinct
    • sorted

      default Enumerable<T> sorted(Comparator<T> comparator)
      Performs sorted.
      Parameters:
      comparator - the comparator value
      Returns:
      the result of sorted
    • associate

      default <K> AssociatedEnumerable<K,T> associate(Function<T,K> keySelector)
      Returns associate.
      Parameters:
      keySelector - the keySelector value
      Returns:
      the result of associate
    • associate

      default <K, V> AssociatedEnumerable<K,V> associate(Function<T,K> keySelector, Function<T,V> valueSelector)
      Creates an association that groups element in this Enumerable according to a given key and value selectors.
      Parameters:
      keySelector - the keySelector value
      valueSelector - the valueSelector value
      Returns:
      the result of associate
    • groupBy

      default <K> AssociatedEnumerable<K,Enumerable<T>> groupBy(Function<T,K> groupSelector)
      Creates an association that groups element in this Enumerable according to a given group selector.
      Parameters:
      groupSelector - the groupSelector value
      Returns:
      the result of groupBy
    • collect

      default <R, A> R collect(Collector<? super T,A,R> collector) throws InfiniteEnumerableException
      Applies a Collector to the Enumerable
      Parameters:
      collector - the collector value
      Returns:
      the result of collect
      Throws:
      InfiniteEnumerableException - if the Enumerable is infinite
    • cast

      default <R> Enumerable<R> cast(Class<R> type)
      Transforms each item from type T to type R. An exception will throw if the item is not of type R
      Type Parameters:
      R -
      Parameters:
      type -
      Returns:
    • ofType

      default <R> Enumerable<R> ofType(Class<R> type)
      Transforms each item from type T to type R. Only items of type R will be preserved. No exception will be thrown
      Type Parameters:
      R -
      Parameters:
      type -
      Returns: