T
- The type of the elements in the iterable.public class PreparedIterable<T> extends Object implements Elements<T>, Serializable
Iterable
and provides access to
various operations to view and/or transform the wrapped iterable.Constructor and Description |
---|
PreparedIterable(Iterable<T> elements) |
Modifier and Type | Method and Description |
---|---|
PreparedIterable<T> |
append(Iterable<? extends T> trailingElements)
Append several elements.
|
PreparedIterable<T> |
append(T value)
Append one element.
|
List<T> |
collect()
Get the elements as an immutable
List . |
<C extends Collection<T>> |
collectIn(C collection)
Collects the elements in this iterable in the given collection.
|
void |
each(Do<? super T> sideEffect)
Execute a side effect operation for each
containing element.
|
Elements<T> |
eval()
Force-evaluate the current elements, applying all composed functions
on each element.
|
boolean |
exists(Predicate<? super T> predicate)
Decide if an element exist.
|
PreparedIterable<T> |
filter(Predicate<? super T> filter)
Provide a predicate that evaluates which element(s) to be
included.
|
<O> Elements<O> |
flatMap(Fn<? super T,? extends Iterable<O>> fn) |
<P> Map<P,List<T>> |
groupBy(Fn<? super T,P> property)
|
Optional<T> |
head()
Gets the head, or first element, if it exists.
|
Elements<Elem<T>> |
indexed()
Couple each element with its positional index.
|
Elements<Elem<T>> |
indexedFrom(int startIndex)
Couple each element with its positional index,
starting from a given index.
|
boolean |
isEmpty() |
Iterator<T> |
iterator() |
String |
join()
Join all elements to one
String . |
String |
join(String separator)
Join all elements to one
String with all
elements joined with the given separator. |
Optional<T> |
last()
Gets the last element.
|
<O> PreparedIterable<O> |
map(Fn<? super T,O> fn)
Apply a function on any contained element(s), returning the result
in a new mappable container.
|
<P> Map<P,T> |
mapBy(Fn<? super T,P> uniqueProperty)
|
PreparedIterable<T> |
prepend(Iterable<? extends T> leadingElements)
Prepend several elements.
|
PreparedIterable<T> |
prepend(T value)
Prepend one element.
|
<O> O |
reduce(O unit,
Fn2<? super O,? super T,? extends O> reducer)
Reduce the element(s) into one value.
|
Elements<T> |
repeat(int times)
Repeat the contained elements a given amount of times.
|
List<T> |
sorted(Comparator<? super T> comparator)
Get a sorted immutable
List of the contents of this iterable. |
<P extends Comparable<P>> |
sortedBy(Fn<? super T,P> property)
Get a sorted immutable
List of the contents of this iterable. |
PreparedIterable<T> |
tail()
Gets the tail, i.e.
|
PreparedIterable<T> |
take(int amount)
Take only a maximum amount of elements.
|
PreparedIterable<T> |
takeUntil(Predicate<? super T> predicate)
Take elements until a given predicate evaluates to true.
|
PreparedIterable<T> |
takeWhile(Predicate<? super T> predicate)
Take elements as long as a given predicate
evaluates to true.
|
String |
toString()
Textual description of the contents of the iterable.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
forEach, spliterator
each
public Elements<Elem<T>> indexed()
Elements
public Elements<Elem<T>> indexedFrom(int startIndex)
Elements
indexedFrom
in interface Elements<T>
startIndex
- the beginning index to assign to the first element.Elem
s.public PreparedIterable<T> filter(Predicate<? super T> filter)
Filterable
public <O> PreparedIterable<O> map(Fn<? super T,O> fn)
Mappable
public PreparedIterable<T> append(T value)
Appendable
append
in interface Appendable<T>
value
- the element to append.public PreparedIterable<T> append(Iterable<? extends T> trailingElements)
Appendable
append
in interface Appendable<T>
trailingElements
- the elements to append.public PreparedIterable<T> prepend(T value)
Prependable
prepend
in interface Prependable<T>
value
- the element to prepend.public PreparedIterable<T> prepend(Iterable<? extends T> leadingElements)
Prependable
prepend
in interface Prependable<T>
leadingElements
- the elements to prepend.public PreparedIterable<T> take(int amount)
Elements
public PreparedIterable<T> takeWhile(Predicate<? super T> predicate)
Elements
public PreparedIterable<T> takeUntil(Predicate<? super T> predicate)
Elements
public PreparedIterable<T> tail()
HeadAndTail
public Elements<T> repeat(int times)
Repeatable
IllegalArgumentException
(eventually)public Elements<T> eval()
Elements
Elements
.public final <O> O reduce(O unit, Fn2<? super O,? super T,? extends O> reducer)
Reducible
reduce
in interface Reducible<T>
unit
- The start value for the reduction. The unit should in general (but
is not required to) be such that when combined with any element in
the iterable, yield the iterable's element.reducer
- the function which first argument is the accumulated reduction
througout the iteration, and second argument the value to include
in the reduction.public final List<T> collect()
YieldsJavaCollection
List
. This is the
most common way to obtain a regular implementation of a Java
collection.
If you need more control on the returned Collection
implementation, use YieldsJavaCollection.collectIn(Collection)
, e.g. if
you need a mutable collection.collect
in interface YieldsJavaCollection<T>
public final <C extends Collection<T>> C collectIn(C collection)
YieldsJavaCollection
sets
does not allow duplicates, and many implementations
also does not maintain the order of the elements. The collection must obviously
support the add(..)
operation. Unless you
have particular needs for the resulting collection, consider using
the YieldsJavaCollection.collect()
method instead.collectIn
in interface YieldsJavaCollection<T>
collection
- The collection to add the elements to.public final <P extends Comparable<P>> List<T> sortedBy(Fn<? super T,P> property)
YieldsJavaCollection
List
of the contents of this iterable.sortedBy
in interface YieldsJavaCollection<T>
property
- The function to obtain the property to sort by of each element.public final List<T> sorted(Comparator<? super T> comparator)
YieldsJavaCollection
List
of the contents of this iterable.sorted
in interface YieldsJavaCollection<T>
comparator
- The comparator to use when sorting the elements.
Use Iterate.byOrderingOf(Class)
to use the
natural ordering of the contained elements.public void each(Do<? super T> sideEffect)
SideEffectable
each
in interface SideEffectable<T>
sideEffect
- the Do
operation which is
passed each of the containing elements.public <P> Map<P,List<T>> groupBy(Fn<? super T,P> property)
YieldsJavaCollection
Map
where the keys are derived by applying the given
Fn
on all elements. Each key points to the list of elements
which resolves to the key.groupBy
in interface YieldsJavaCollection<T>
property
- the function which resolves the key for elements.public <P> Map<P,T> mapBy(Fn<? super T,P> uniqueProperty)
YieldsJavaCollection
Map
where all keys are derived by applying the given
Fn
on all elements. This is a special case of YieldsJavaCollection.groupBy(Fn)
where the Fn
will yield a unique key for each element.
In the event of multiple elements resolves to the same key, this method
will fail with an exception. If this uniqueness
cannot be guarantied, consider using YieldsJavaCollection.groupBy(Fn)
instead.mapBy
in interface YieldsJavaCollection<T>
uniqueProperty
- the function which resolves the unique key for each elementpublic boolean isEmpty()
public boolean exists(Predicate<? super T> predicate)
Existance
public Optional<T> head()
HeadAndTail
head
in interface Elements<T>
head
in interface HeadAndTail<T>
public String join()
Elements
String
.public String join(String separator)
Elements
String
with all
elements joined with the given separator.public String toString()
toString()
will iterate over the elements to
actually be able to create the description.Copyright © 2016. All Rights Reserved.