Modifier and Type | Method and Description |
---|---|
static <T,A,R> R |
collect(Iterable<T> data,
Collector<? super T,A,R> collector)
Simple implementation reducing the elements of an iterable to a return value
using a
Collector . |
static <X,Y> Iterable<Pair<X,Y>> |
combinations(Iterable<X> iterable,
Iterable<Y> other)
This function returns a new Iterable providing the elements of the Cartesian Product of the elements provided
by
iterable and the elements of the other . |
static <X,Y,Z> Iterable<Z> |
combinations(Iterable<X> iterable,
Iterable<Y> other,
Functions.Function2<? super X,? super Y,? extends Z> merger)
This function returns a new Iterable providing the elements of the Cartesian Product of the elements provided
by
iterable and the elements of the other . |
static <X,Y> Iterable<Pair<X,Y>> |
combinationsWhere(Iterable<X> iterable,
Iterable<Y> other,
BiPredicate<X,Y> where)
This function returns a new Iterable providing the elements of the Cartesian Product of the elements provided
by
iterable and the elements of the other . |
static <X,Y,Z> Iterable<Z> |
combinationsWhere(Iterable<X> iterable,
Iterable<Y> other,
BiPredicate<X,Y> where,
Functions.Function2<? super X,? super Y,? extends Z> merger)
This function returns a new Iterable providing the elements of the Cartesian Product of the elements provided
by
iterable and the elements of the other . |
static ClassGroupingList |
groupIntoListBy(Iterable<?> iterable,
Class<?> firstGroup,
Class<?> secondGroup,
Class<?>... additionalGroups)
Groups the elements in
iterable into lists by the classes given via parameters firstGroup , firstGroup , and additionalGroups . |
static ClassGroupingSet |
groupIntoSetBy(Iterable<?> iterable,
Class<?> firstGroup,
Class<?> secondGroup,
Class<?>... additionalGroups)
Groups the elements in
iterable into sets by the classes given via parameters firstGroup , firstGroup , and additionalGroups . |
static <X,T extends X> |
into(Iterable<T> iterable,
Collection<X>... targets)
This method will add the elements of
iterable to the all of the collection in targets
and then return all those collections in an array. |
static <X,T extends X> |
into(Iterable<T> iterable,
Collection<X> target)
This method will add the elements of
iterable to the target collection
and then return the target collection. |
static <T> DoubleIterable |
mapDouble(Iterable<T> iterable,
ToDoubleFunction<T> mapper)
This function maps an
Iterable to a DoubleIterable , using the
mapper function for each element of the original iterable . |
static <T> IntIterable |
mapInt(Iterable<T> iterable,
ToIntFunction<T> mapper)
This function maps an
Iterable to an IntIterable , using the
mapper function for each element of the original iterable . |
static <T> LongIterable |
mapLong(Iterable<T> iterable,
ToLongFunction<T> mapper)
This function maps an
Iterable to a LongIterable , using the
mapper function for each element of the original iterable . |
static <T> Stream<T> |
parallelStream(Iterable<T> it)
Creates a parallel
Stream instance for processing the elements
of the Iterable it .If the given Iterable is instance of Collection , the
parallelStream method of the Collection interface will
be called. |
static <X,Y> Partition<List<Y>,List<X>> |
partitionBy(Iterable<X> iterable,
Class<Y> selectionClass)
This method partitions the elements in
iterable into elements instance of selectionClass
and elements that are not. |
static <X,Y,S,R> Partition<S,R> |
partitionBy(Iterable<X> iterable,
Class<Y> selectionClass,
Collector<Y,?,S> selectedCollector,
Collector<X,?,R> rejectedCollector)
This method partitions the elements in
iterable into elements instance of selectionClass
and elements that are not. |
static <X> Partition<List<X>,List<X>> |
partitionBy(Iterable<X> iterable,
Predicate<X> partitionPredicate)
This method partitions the elements in
iterable into elements for which partitionPredicate
evaluates to true and elements for which partitionPredicate evaluates to false . |
static <X,AS,AR> Partition<AS,AR> |
partitionBy(Iterable<X> iterable,
Predicate<X> partitionPredicate,
Collector<X,?,AS> selectedCollector,
Collector<X,?,AR> rejectedCollector)
This method partitions the elements in
iterable into aggregated elements for which partitionPredicate
evaluates to true and aggregated elements for which partitionPredicate evaluates to false . |
static <X,AX> Partition<AX,AX> |
partitionBy(Iterable<X> iterable,
Predicate<X> partitionPredicate,
Collector<X,?,AX> collector)
This method partitions the elements in
iterable into aggregated elements for which partitionPredicate
evaluates to true and aggregated elements for which partitionPredicate evaluates to false . |
static <T> Stream<T> |
stream(Iterable<T> it)
Creates a
Stream instance for processing the elements
of the Iterable it .If the given Iterable is instance of Collection , the
stream method of the Collection interface will
be called. |
static <T> Iterable<T> |
withoutAll(Iterable<T> iterable,
Iterable<?> toExclude)
Filters the given
iterable by filtering all elements out that are also included
in the given Iterable toExclude . |
public static <T> IntIterable mapInt(Iterable<T> iterable, ToIntFunction<T> mapper)
Iterable
to an IntIterable
, using the
mapper
function for each element of the original iterable
.
The returned IntIterable
is lazy, only performing
the mapper
function when iterating over the original iterable
object. If the returned iterable will be traversed multiple times the mapper
function will be applied multiple times for each element.T
- type of elements in iterable
, that are mapped to int
s via mapper
.iterable
- the Iterable
of which each element should be mapped to int
values.mapper
- the mapping function, mapping each element of iterable
to an int
value.int
values mapped from the elements of the input iterable
.public static <T> LongIterable mapLong(Iterable<T> iterable, ToLongFunction<T> mapper)
Iterable
to a LongIterable
, using the
mapper
function for each element of the original iterable
.
The returned LongIterable
is lazy, only performing
the mapper
function when iterating over the original iterable
object. If the returned iterable will be traversed multiple times the mapper
function will be applied multiple times for each element.T
- type of elements in iterable
, that are mapped to long
s via mapper
.iterable
- the Iterable
of which each element should be mapped to long
values.mapper
- the mapping function, mapping each element of iterable
to an long
value.long
values mapped from the elements of the input iterable
.public static <T> DoubleIterable mapDouble(Iterable<T> iterable, ToDoubleFunction<T> mapper)
Iterable
to a DoubleIterable
, using the
mapper
function for each element of the original iterable
.
The returned DoubleIterable
is lazy, only performing
the mapper
function when iterating over the original iterable
object. If the returned iterable will be traversed multiple timesT
- type of elements in iterable
, that are mapped to double
s via mapper
.iterable
- the Iterable
of which each element should be mapped to double
values.mapper
- the mapping function, mapping each element of iterable
to an double
value.double
values mapped from the elements of the input iterable
.public static <T> Stream<T> stream(Iterable<T> it)
Stream
instance for processing the elements
of the Iterable it
.Iterable
is instance of Collection
, the
stream
method of the Collection interface will
be called. Otherwise uses StreamSupport
to create a Stream with the
Spliterator created using Iterable.spliterator()
.T
- type of elements in iterable
, that are being provided by the returning stream.it
- from which the returned Stream is createdit
.public static <T> Stream<T> parallelStream(Iterable<T> it)
Stream
instance for processing the elements
of the Iterable it
.Iterable
is instance of Collection
, the
parallelStream
method of the Collection interface will
be called. Otherwise uses StreamSupport
to create the parallel Stream with the
Spliterator created using Iterable.spliterator()
.T
- type of elements in iterable
, that are being provided by the returning stream.it
- from which the returned Stream is createdit
.public static <T,A,R> R collect(Iterable<T> data, Collector<? super T,A,R> collector)
Collector
.T
- type of elements in iterable
A
- type of mutable aggregator element used by collector
R
- type of the final element produced by collector
that is being returned.data
- the iterable elements should be collected.collector
- the collector reducing multiple values into a single result valuecollector
over each element
in the given data
input.public static ClassGroupingSet groupIntoSetBy(Iterable<?> iterable, Class<?> firstGroup, Class<?> secondGroup, Class<?>... additionalGroups)
iterable
into sets by the classes given via parameters firstGroup
, firstGroup
, and additionalGroups
.
The elements will be checked to be instance of the given classes in the
order they appear in the parameter list. So if e.g. classes Object
and String
are passed into the function in this order, an instance of String
will land
in the group of Object
. Also note that objects that are not matching any given class
are simply omitted from the resulting grouping. If you need a group for all objects that
were not matched, just pass in the class of Object
as the last parameter.iterable
- the iterable, that provides the elements to be be grouped into sets by the given classesfirstGroup
- first class elements of iterable
are be grouped bysecondGroup
- first class elements of iterable
are be grouped byadditionalGroups
- further classes to group elements by. This parameter is allowed to be null
.firstGroup
, firstGroup
, and additionalGroups
partitionBy(Iterable, Class)
,
partitionBy(Iterable, Class, Collector, Collector)
public static ClassGroupingList groupIntoListBy(Iterable<?> iterable, Class<?> firstGroup, Class<?> secondGroup, Class<?>... additionalGroups)
iterable
into lists by the classes given via parameters firstGroup
, firstGroup
, and additionalGroups
.
The elements will be checked to be instance of the given classes in the
order they appear in the parameter list. So if e.g. classes Object
and String
are passed into the function in this order, an instance of String
will land
in the group of Object
. Also note that objects that are not matching any given class
are simply omitted from the resulting grouping. If you need a group for all objects that
were not matched, just pass in the class of Object
as the last parameter.iterable
- the iterable, that provides the elements to be be grouped into sets by the given classesfirstGroup
- first class elements of iterable
are be grouped bysecondGroup
- first class elements of iterable
are be grouped byadditionalGroups
- further classes to group elements by. This parameter is allowed to be null
.firstGroup
, firstGroup
, and additionalGroups
.partitionBy(Iterable, Class)
,
partitionBy(Iterable, Class, Collector, Collector)
public static <T> Iterable<T> withoutAll(Iterable<T> iterable, Iterable<?> toExclude)
iterable
by filtering all elements out that are also included
in the given Iterable toExclude
. If an element from iterable
is null
it is removed
if toExclude
also contains a null
value. Otherwise elements e
from
iterable
are only removed, if toExclude
contains an element o
, where e.equals(o)
.T
- Type of elements in iterable
iterable
- the iterable to be filtered. Must not be null
.toExclude
- the elements not to be included in the resulting iterable. Must not be null
.iterable
not containing elements from toExclude
.NullPointerException
- will be thrown if iterable
or toExclude
is null
.public static <X,Y> Iterable<Pair<X,Y>> combinations(Iterable<X> iterable, Iterable<Y> other)
iterable
and the elements of the other
. The
combination of elements of the iterable
and the other
are represented
as Pair
s of the values from both sources.X
- Type of elements in iterable
.Y
- Type of elements provided by other
iterable
- the iterable that's elements are combined with every elements from other
. Must not be null
.other
- the elements to be combined with each element from iterable
. Must not be null
.iterable
with every element of the elements provided by other
.NullPointerException
- is thrown if iterable
or other
is null
public static <X,Y,Z> Iterable<Z> combinations(Iterable<X> iterable, Iterable<Y> other, Functions.Function2<? super X,? super Y,? extends Z> merger)
iterable
and the elements of the other
. The
combination of elements of the iterable
and the other
are computed using the merger
function.X
- Type of elements in iterable
.Y
- Type of elements provided by other
Z
- Type of the merged elementsiterable
- the iterable that's elements are combined with every elements from other
. Must not be null
.other
- the elements to be combined with each element from iterable
. Must not be null
.merger
- the function combining the elements from iterable
and other
.iterable
with every element of the elements provided by other
.NullPointerException
- is thrown if iterable
, or other
, or merger
is null
public static <X,Y> Iterable<Pair<X,Y>> combinationsWhere(Iterable<X> iterable, Iterable<Y> other, BiPredicate<X,Y> where)
iterable
and the elements of the other
. A combination of values from iterable
and
other
will only be included in the resulting iterable, if the where
predicate holds true for
the combination. The combination of elements are represented as Pair
s of the values from both sources.X
- Type of elements in iterable
.Y
- Type of elements provided by other
iterable
- the iterable that's elements are combined with every elements from other
. Must not be null
.other
- the elements to be combined with each element from iterable
. Must not be null
.where
- a filtering predicate to only produce combinations for which this predicate holds true. Must not be null
.iterable
with every element of the elements provided by other
for which the where
predicate holds true.NullPointerException
- is thrown if iterable
, or other
or where
is null
public static <X,Y,Z> Iterable<Z> combinationsWhere(Iterable<X> iterable, Iterable<Y> other, BiPredicate<X,Y> where, Functions.Function2<? super X,? super Y,? extends Z> merger)
iterable
and the elements of the other
. A combination of values from iterable
and
other
will only be included in the resulting iterable, if the where
predicate holds true for
the combination. The combination of elements of the iterable
and the other
are computed using
the merger
function.X
- Type of elements in iterable
.Y
- Type of elements provided by other
Z
- Type of the merged elementsiterable
- the iterable that's elements are combined with every elements from other
. Must not be null
.other
- the elements to be combined with each element from iterable
. Must not be null
.where
- a filtering predicate to only produce combinations for which this predicate holds true. Must not be null
.merger
- the function combining the elements from iterable
and other
.iterable
with every element of the elements provided by other
for which the where
predicate holds true. The elements are a result of the merger
call for each combinationNullPointerException
- is thrown if iterable
, or other
, or where
, or merger
is null
public static <X,Y> Partition<List<Y>,List<X>> partitionBy(Iterable<X> iterable, Class<Y> selectionClass)
iterable
into elements instance of selectionClass
and elements that are not. The returned partition holds the elements instance of selectionClass
in the selected partition and the other elements in the rejected partition. Partitions are Lists of the
elements. The relative order of the elements in iterable
is preserved in the respective partitions.
There is no guarantee about mutability or thread safety of the list partitions. If there is no element
selected or rejected, the respective parts will hold an empty List; the parts are guaranteed to be not null
.X
- Type of elements in iterable
Y
- Type of elements that are part of iterable
and will be put into the resulting selected partition.iterable
- source iterable, that's elements are partitioned based on selectionClass
selectionClass
- the class elements in iterable
are checked to be instance of. Elements
that are instance of selectionClass
will be added to the selected partition of the result.
Elements that are not, will end up in the rejected partition.iterable
, providing the selected elements, that are instance of selectionClass
, and rejected elements
not instance of selectionClass
.NullPointerException
- if iterable
or selectionClass
is null
groupIntoListBy(Iterable, Class, Class,Class[])
,
groupIntoSetBy(Iterable, Class, Class,Class[])
public static <X,Y,S,R> Partition<S,R> partitionBy(Iterable<X> iterable, Class<Y> selectionClass, Collector<Y,?,S> selectedCollector, Collector<X,?,R> rejectedCollector)
iterable
into elements instance of selectionClass
and elements that are not. Elements instance of selectionClass
are aggregated using the selectedCollector
and the result will be available via the selected part of the returned partition. Elements not instance of selectionClass
are aggregated using the rejectedCollector
and provided via the selected part of the returned partition.X
- Type of elements in iterable
Y
- Type of elements that are part of iterable
and will be put into the resulting aggregation of the selected
part of the returned partition.S
- Aggregation result type of the selected part of the returned partition, created by selectedCollector
.R
- Aggregation result type of the rejected part of the returned partition, created by rejectedCollector
.iterable
- source iterable, that's elements are partitioned based on selectionClass
selectionClass
- the class elements in iterable
are checked to be instance of. Elements
that are instance of selectionClass
will be aggregated into the selected partition of the result.
Elements that are not, will end up in the aggregated rejected partition.selectedCollector
- aggregates all elements in iterable
that are instance of selectionClass
. The
aggregation result will be provided by the selected part of the returned partition.rejectedCollector
- aggregates all elements in iterable
that are not instance of selectionClass
. The
aggregation result will be provided by the rejected part of the returned partition.iterable
, providing the aggregation of selected elements, that are instance of selectionClass
,
and the aggregation of rejected elements not instance of selectionClass
.NullPointerException
- if iterable
, selectionClass
, selectedCollector
or rejectedCollector
is null
groupIntoListBy(Iterable, Class, Class,Class[])
,
groupIntoSetBy(Iterable, Class, Class,Class[])
public static <X> Partition<List<X>,List<X>> partitionBy(Iterable<X> iterable, Predicate<X> partitionPredicate)
iterable
into elements for which partitionPredicate
evaluates to true
and elements for which partitionPredicate
evaluates to false
.
The selected part of the returned partition holds the elements for which partitionPredicate
evaluates to true
, the rejected part contains the other elements from iterable
.
Partition parts are Lists of the elements. The relative order of the elements in iterable
is preserved
in the respective partitions. There is no guarantee about mutability or thread safety of the lists.
If there is no element selected or rejected, the respective parts will hold an empty List; the parts are
guaranteed to be not null
.X
- Type of elements in iterable
iterable
- source iterable, that's elements are partitioned based on selectionClass
partitionPredicate
- predicate deciding if an element in iterable
will end up in the
selected or rejected part of the returned partition. Elements for which the test returns true
end up in the selected part, others land in the rejected part.iterable
, providing the selected elements, for which partitionPredicate
evaluates to true
and rejected elements for which partitionPredicate
evaluates to false
.NullPointerException
- if iterable
or partitionPredicate
is null
public static <X,AX> Partition<AX,AX> partitionBy(Iterable<X> iterable, Predicate<X> partitionPredicate, Collector<X,?,AX> collector)
iterable
into aggregated elements for which partitionPredicate
evaluates to true
and aggregated elements for which partitionPredicate
evaluates to false
.
The selected part of the returned partition holds the elements aggregated using the given collector
for which
partitionPredicate
evaluates to true
. The rejected part contains the other elements aggregated using the
given collector
from iterable
.X
- Type of elements in iterable
AX
- Type aggregated elements of returned partitioniterable
- source iterable, that's elements are partitioned based on selectionClass
partitionPredicate
- predicate deciding if an element in iterable
will end up in the
selected or rejected part of the returned partition. Elements for which the test returns true
end up in the selected part, others land in the rejected part.collector
- used for aggregating the selected and rejected elements in the returned partition.iterable
, providing the selected elements, for which partitionPredicate
evaluates to true
aggregated using the given collector
and rejected elements for which partitionPredicate
evaluates to false
aggregated using the given collector
.NullPointerException
- if iterable
, collector
or partitionPredicate
is null
public static <X,AS,AR> Partition<AS,AR> partitionBy(Iterable<X> iterable, Predicate<X> partitionPredicate, Collector<X,?,AS> selectedCollector, Collector<X,?,AR> rejectedCollector)
iterable
into aggregated elements for which partitionPredicate
evaluates to true
and aggregated elements for which partitionPredicate
evaluates to false
.
The selected part of the returned partition holds the elements aggregated using the given selectedCollector
for which
partitionPredicate
evaluates to true
. The rejected part contains the other elements aggregated using the
given rejectedCollector
from iterable
.X
- Type of elements in iterable
AS
- Type of aggregated elements of selected part of returned partitioniterable
- source iterable, that's elements are partitioned based on selectionClass
partitionPredicate
- predicate deciding if an element in iterable
will end up aggregated in the
selected or aggregated in the rejected part of the returned partition. Elements for which the test returns true
end up in the aggregated selected part, others land in the aggregated rejected part.selectedCollector
- used for aggregating the selected elements in the returned partition.rejectedCollector
- used for aggregating the rejected elements in the returned partition.Type
- of aggregated elements of rejected part of returned partitioniterable
, providing the selected elements, for which partitionPredicate
evaluates to true
aggregated using the given collector
and rejected elements for which partitionPredicate
evaluates to false
aggregated using the given collector
.NullPointerException
- if iterable
, selectedCollector
, rejectedCollector
or partitionPredicate
is null
public static <X,T extends X> Collection<X> into(Iterable<T> iterable, Collection<X> target)
iterable
to the target
collection
and then return the target
collection. The elements will be added to target
in the order that is provided by the forEach
method defined on iterable
.target
collection will include the elements of
iterable
. This is intentional and is beneficial if the the elements need to be used
in subsequent statement after calling this method.
vararg overload
will
create may implicitly create an array instance. This is avoided with this
overload.X
- Type of elements of target
. Must be either T
or a super class of T
.T
- Type of elements of iterable
.iterable
- the source of elements to be added to target
. Must not be null
.target
- the collection to which the elements of iterable
are added to. This reference
will also be returned by this method. Must not be null
.target
reference. The elements from iterable
will have been added to it when
being returned.NullPointerException
- if iterable
, selectedCollector
, or target
is null
into(Iterable, Collection[])
public static <X,T extends X> Collection<X>[] into(Iterable<T> iterable, Collection<X>... targets)
iterable
to the all of the collection in targets
and then return all those collections in an array. The elements will be added to the targets
collections
in the order that is provided by the forEach
method defined on iterable
.targets
collections will include the elements of
iterable
. This is intentional and is beneficial if the the elements need to be used
in subsequent statement after calling this method.X
- Type of elements of collections in targets
. Must be either T
or a super class of T
.T
- Type of elements of iterable
.iterable
- the source of elements to be added to the collections in targets
. Must not be null
.targets
- the collections to which the elements of iterable
are added to. An array of the same collections
will also be returned by this method. Must not be null
and no contained collection reference must be null
.targets
. The elements from iterable
will have been added to each of the contained
collections when being returned.NullPointerException
- if iterable
, selectedCollector
, or targets
, or a
collection in target
is null
.into(Iterable, Collection)
Copyright © 2019. All rights reserved.