Package org.midheaven.collections
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
An
Iterable with fluent stream like transformation methods-
Method Summary
Modifier and TypeMethodDescriptiondefault booleanPerforms allMatch.default booleanany()Performs any.default booleanPerforms anyMatch.default <E extends Enumerable<T>>
Eas(EnumerableExtension<T, E> extension) Performs as.default <K> AssociatedEnumerable<K, T> Returns associate.default <K,V> AssociatedEnumerable <K, V> Creates an association that groups element in thisEnumerableaccording to a given key and value selectors.default <R> Enumerable<R> Transforms each item from type T to type R.default <R,A> R Applies aCollectorto theEnumerabledefault Enumerable<T> concat(Enumerable<T> other) Performs concat.default Intcount()Best effort to count the elements.default Enumerable<T> distinct()Performs distinct.static <X> Enumerable<X> empty()Returns an empty instance.Returns an enumerator over the elements.default Enumerable<T> Performs filter.first()Performs first.default <R> Enumerable<R> flatMap(Function<T, Enumerable<R>> transform) Performs flatMap.static <X> Enumerable<X> Creates an instance from the provided source.static <X> Enumerable<X> Creates an instance from the provided source.static <X> Enumerable<X> Performs generate.default <K> AssociatedEnumerable<K, Enumerable<T>> Creates an association that groups element in thisEnumerableaccording to a given group selector.default booleanisEmpty()Checks whether is Empty.static <X> Enumerable<X> Performs iterate.iterator()Returns an iterator over the elements.default Enumerable<T> limit(long maxCount) Performs limit.default <R> Enumerable<R> Performs map.maximum(Comparator<T> comparator) Performs maximum.minimum(Comparator<T> comparator) Performs minimum.default <R> Enumerable<R> Transforms each item from type T to type R.default Enumerable<T> Performs peek.default <A> Areduce(A seed, BiFunction<A, T, A> accumulator) Reduce theEnumerableto a single value by operating between a seed value and each element.reduce(BiFunction<T, T, T> accumulator) Reduce theEnumerableto a single value by operating between each element.static <X> Enumerable<X> single(X value) Performs single.default Enumerable<T> skip(long minCount) Performs skip.default Enumerable<T> sorted(Comparator<T> comparator) Performs sorted.default Object[]toArray()Creates an array onObjectand copies all elements in this to that array.default T[]toArray(IntFunction<T[]> generator) Returns a typed array containing all elements in @{code this}.default T[]Returns a typed array containing all elements in @{code this}.default DistinctAssortment<T> Returns to Distinct Assortment.Returns aSequencewith the elements in thisEnumerable.default <S extends EditableSequence<T>>
StoSequence(Supplier<S> supplier) Returns to Sequence.default <S> ArithmeticalEnumerable<T, S> with(Arithmetic<T, S> arithmetic) Performs with.default <S,R> Enumerable <R> zip(Enumerable<S> other, BiFunction<T, S, R> transform) Performs zip.Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
empty
Returns an empty instance.- Returns:
- the result of empty
-
generate
Performs generate.- Parameters:
supplier- the supplier value- Returns:
- the result of generate
-
iterate
Performs iterate.- Parameters:
seed- the seed valuesuccessor- the successor value- Returns:
- the result of iterate
-
from
Creates an instance from the provided source.- Parameters:
iterable- the iterable value- Returns:
- the result of from
-
single
Performs single.- Parameters:
value- the value value- Returns:
- the result of single
-
from
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
Returns an iterator over the elements. -
first
Performs first.- Returns:
- the result of first
-
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
Returns aSequencewith the elements in thisEnumerable. TheEnumerablemust be finite or an exception will be thrown- Returns:
- the result of toSequence
- Throws:
IllegalStateException- if theEnumerableis infiniteInfiniteEnumerableException
-
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 theEnumerableis infinite
-
toDistinctAssortment
Returns to Distinct Assortment.- Returns:
- the result of toDistinctAssortment
- Throws:
InfiniteEnumerableException- if theEnumerableis infinite
-
toArray
Creates an array onObjectand copies all elements in this to that array. This operation is only possible if theEnumerableis not infinite and its length is less thanInteger.MAX_VALUE.- Returns:
- an array containing all elements in
this - Throws:
InfiniteEnumerableException- if theEnumerableis infinite
-
toArray
Returns a typed array containing all elements in @{code this}. This operation is only possible if theEnumerableis not infinite and its length is less thanInteger.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 theEnumerableis infinite
-
toArray
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 theEnumerableis infinite
-
anyMatch
Performs anyMatch.- Parameters:
predicate- the predicate value- Returns:
- the result of anyMatch
-
allMatch
Performs allMatch.- Parameters:
predicate- the predicate value- Returns:
- the result of allMatch
- Throws:
InfiniteEnumerableException- if theEnumerableis infinite
-
reduce
Reduce theEnumerableto a single value by operating between a seed value and each element.- Parameters:
seed- the seed valueaccumulator- the accumulator value- Returns:
- the result of reduce
- Throws:
InfiniteEnumerableException- if theEnumerableis infinite
-
reduce
Reduce theEnumerableto a single value by operating between each element.- Parameters:
accumulator- the accumulator value- Returns:
- the result of reduce
- Throws:
InfiniteEnumerableException
-
minimum
Performs minimum.- Parameters:
comparator- the comparator value- Returns:
- the result of minimum
-
maximum
Performs maximum.- Parameters:
comparator- the comparator value- Returns:
- the result of maximum
-
with
Performs with.- Parameters:
arithmetic- the arithmetic value- Returns:
- the result of with
-
as
Performs as.- Parameters:
extension- the extension value- Returns:
- the result of as
-
concat
Performs concat.- Parameters:
other- the other value- Returns:
- the result of concat
-
filter
Performs filter.- Parameters:
predicate- the predicate value- Returns:
- the result of filter
-
map
Performs map.- Parameters:
transform- the transform value- Returns:
- the result of map
-
flatMap
Performs flatMap.- Parameters:
transform- the transform value- Returns:
- the result of flatMap
-
peek
Performs peek.- Parameters:
consumer- the consumer value- Returns:
- the result of peek
-
zip
Performs zip.- Parameters:
other- the other valuetransform- the transform value- Returns:
- the result of zip
-
limit
Performs limit.- Parameters:
maxCount- the maxCount value- Returns:
- the result of limit
-
skip
Performs skip.- Parameters:
minCount- the minCount value- Returns:
- the result of skip
-
distinct
Performs distinct.- Returns:
- the result of distinct
-
sorted
Performs sorted.- Parameters:
comparator- the comparator value- Returns:
- the result of sorted
-
associate
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 thisEnumerableaccording to a given key and value selectors.- Parameters:
keySelector- the keySelector valuevalueSelector- the valueSelector value- Returns:
- the result of associate
-
groupBy
Creates an association that groups element in thisEnumerableaccording to a given group selector.- Parameters:
groupSelector- the groupSelector value- Returns:
- the result of groupBy
-
collect
Applies aCollectorto theEnumerable- Parameters:
collector- the collector value- Returns:
- the result of collect
- Throws:
InfiniteEnumerableException- if theEnumerableis infinite
-
cast
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
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:
-