public class ManIterableExt extends Object
Constructor and Description |
---|
ManIterableExt() |
Modifier and Type | Method and Description |
---|---|
static <T> int |
count(Iterable<T> thiz)
Returns the number of elements in thiz collection.
|
static <T> int |
count(Iterable<T> thiz,
Predicate<T> predicate)
Returns the number of elements matching the given
predicate . |
static <T,K> List<T> |
distinctBy(Iterable<T> thiz,
Function<T,K> selector)
Returns a list containing only elements from the given collection
having distinct keys returned by the given
selector function. |
static <T> List<T> |
distinctList(Iterable<T> thiz)
Returns a list containing only distinct elements from the given collection.
|
static <T,C extends Collection<? super T>> |
filterIndexedTo(Iterable<T> thiz,
C destination,
IndexedPredicate<T> predicate)
Appends all elements matching the given
predicate to the given destination . |
static <T> List<T> |
filterIndexedToList(Iterable<T> thiz,
IndexedPredicate<T> predicate)
Returns a list containing only elements matching the given
predicate . |
static <T,C extends Collection<? super T>> |
filterNotTo(Iterable<T> thiz,
C destination,
Predicate<T> predicate)
Appends all elements not matching the given
predicate to the given destination . |
static <T> List<T> |
filterNotToList(Iterable<T> thiz,
Predicate<T> predicate)
Returns a list containing all elements not matching the given
predicate . |
static <T,C extends Collection<? super T>> |
filterTo(Iterable<T> thiz,
C destination,
Predicate<T> predicate)
Appends all elements matching the given
predicate to the given destination . |
static <T> List<T> |
filterToList(Iterable<T> thiz,
Predicate<T> predicate)
Returns a list containing all elements matching the given
predicate . |
static <T> T |
first(Iterable<T> thiz)
Returns first element.
|
static <T> T |
first(Iterable<T> thiz,
Predicate<T> predicate)
Returns the first element matching the given
predicate . |
static <T> T |
firstOrNull(Iterable<T> thiz)
Returns the first element, or null if the collection is empty.
|
static <T> T |
firstOrNull(Iterable<T> thiz,
Predicate<T> predicate)
Returns the first element matching the given
predicate , or null if element was not found. |
static <T,R> List<R> |
flatMap(Iterable<T> thiz,
Function<T,Iterable<R>> transform)
Returns a single list of all elements yielded from results of
transform function being invoked on each element of original collection. |
static <T,R,C extends Collection<R>> |
flatMapTo(Iterable<T> thiz,
C destination,
Function<T,Iterable<R>> transform)
Appends all elements yielded from results of
transform function being invoked on each element of original collection, to the given destination . |
static <T,R> R |
fold(Iterable<T> thiz,
R initial,
BiFunction<R,T,R> operation)
Accumulates value starting with
demo value and applying operation from left to right to current accumulator value and each element. |
static <T> void |
forEachIndexed(Iterable<T> thiz,
IndexedConsumer<T> action)
Performs the given
action on each element, providing sequential index with the element. |
static <T> int |
indexOfFirst(Iterable<T> thiz,
Predicate<T> predicate)
Returns index of the first element matching the given
predicate , or -1 if the collection does not contain such element. |
static <T> int |
indexOfLast(Iterable<T> thiz,
Predicate<T> predicate)
Returns index of the last element matching the given
predicate , or -1 if the collection does not contain such element. |
static <T> Set<T> |
intersect(Iterable<T> thiz,
Iterable<T> other)
Returns a set containing all elements that are contained by both thiz set and the specified collection.
|
static <T,A extends Appendable> |
joinTo(Iterable<T> thiz,
A buffer,
CharSequence separator)
Append the elements to
buffer separated by separator . |
static <T> String |
joinToString(Iterable<T> thiz,
CharSequence separator)
Join the elements together in a String separated by
separator . |
static <T> T |
last(Iterable<T> thiz)
Returns the last element.
|
static <T> T |
last(Iterable<T> thiz,
Predicate<T> predicate)
Returns the last element matching the given
predicate . |
static <T> T |
lastOrNull(Iterable<T> thiz)
Returns the last element, or
null if the collection is empty. |
static <T> T |
lastOrNull(Iterable<T> thiz,
Predicate<T> predicate)
Returns the last element matching the given
predicate , or null if no such element was found. |
static <T,R> List<R> |
mapIndexed(Iterable<T> thiz,
IndexedFunction<T,R> transform)
Deprecated.
Use
mapIndexedToList(Iterable, IndexedFunction) instead. |
static <T,R> List<R> |
mapIndexedNotNull(Iterable<T> thiz,
IndexedFunction<T,R> transform)
Deprecated.
Use
mapIndexedNotNullToList(Iterable, IndexedFunction) instead. |
static <T,R,C extends Collection<? super R>> |
mapIndexedNotNullTo(Iterable<T> thiz,
C destination,
IndexedFunction<T,R> transform)
Applies the given
transform function to each element and its index in the original collection
and appends only the non-null results to the given destination . |
static <T,R> List<R> |
mapIndexedNotNullToList(Iterable<T> thiz,
IndexedFunction<T,R> transform)
Returns a list containing only the non-null results of applying the given
transform function
to each element and its index in the original collection. |
static <T,R,C extends Collection<? super R>> |
mapIndexedTo(Iterable<T> thiz,
C destination,
IndexedFunction<T,R> transform)
Applies the given
transform function to each element and its index in the original collection
and appends the results to the given destination . |
static <T,R> List<R> |
mapIndexedToList(Iterable<T> thiz,
IndexedFunction<T,R> transform)
Returns a list containing the results of applying the given
transform function
to each element and its index in the original collection. |
static <T,R> List<R> |
mapNotNull(Iterable<T> thiz,
Function<T,R> transform)
Deprecated.
Use
mapNotNullToList(Iterable, Function) instead. |
static <T,R,C extends Collection<? super R>> |
mapNotNullTo(Iterable<T> thiz,
C destination,
Function<T,R> transform)
Applies the given
transform function to each element in the original collection
and appends only the non-null results to the given destination . |
static <T,R> List<R> |
mapNotNullToList(Iterable<T> thiz,
Function<T,R> transform)
Returns a list containing only the non-null results of applying the given
transform function
to each element in the original collection. |
static <T,R,C extends Collection<? super R>> |
mapTo(Iterable<T> thiz,
C destination,
Function<T,R> transform)
Applies the given
transform function to each element of the original collection
and appends the results to the given destination . |
static <T,R> List<R> |
mapToList(Iterable<T> thiz,
Function<T,R> transform)
Returns a list containing the results of applying the given
transform function
to each element in the original collection. |
static <T> T |
maxWith(Iterable<T> thiz,
Comparator<T> comparator)
Returns the first element having the largest value according to the provided
comparator or null if there are no elements. |
static <T> T |
minWith(Iterable<T> thiz,
Comparator<T> comparator)
Returns the first element having the smallest value according to the provided
comparator or null if there are no elements. |
static <T> manifold.rt.api.util.Pair<List<T>,List<T>> |
partition(Iterable<T> thiz,
Predicate<T> predicate)
Splits the original collection into pair of lists,
where first list contains elements for which
predicate yielded true ,
while second list contains elements for which predicate yielded false . |
static <T> Collection<T> |
reversed(Iterable<T> thiz)
Returns a collection with elements in reversed order.
|
static <T> T |
single(Iterable<T> thiz)
Returns the single element, or throws an exception if the collection is empty or has more than one element.
|
static <T> T |
single(Iterable<T> thiz,
Predicate<T> predicate)
Returns the single element matching the given
predicate , or throws exception if there is no or more than one matching element. |
static <T> T |
singleOrNull(Iterable<T> thiz)
Returns single element, or
null if the collection is empty or has more than one element. |
static <T> T |
singleOrNull(Iterable<T> thiz,
Predicate<T> predicate)
Returns the single element matching the given
predicate , or null if element was not found or more than one element was found. |
static <T> List<T> |
subList(Iterable<T> thiz,
int fromIndex)
Returns a list containing all the elmeents from
fromIndex (inclusive) |
static <T> List<T> |
subList(Iterable<T> thiz,
int fromIndex,
int toIndex)
Returns a list containing the elmeents
fromIndex (inclusive) to toIndex (exclusive) |
static <T> Set<T> |
subtract(Iterable<T> thiz,
Iterable<T> other)
Returns a set containing all elements that are contained by thiz collection and not contained by the specified collection.
|
static <T> List<T> |
toList(Iterable<T> thiz)
Returns a
List containing all elements. |
static <T> Set<T> |
toSet(Iterable<T> thiz)
Returns a
Set containing all unique elements. |
static <T> Set<T> |
union(Iterable<T> thiz,
Iterable<T> other)
Returns a set containing all distinct elements from both collections.
|
public static <T> T first(Iterable<T> thiz)
NoSuchElementException
- if the collection is empty.public static <T> T first(Iterable<T> thiz, Predicate<T> predicate)
predicate
.{@code
- NoSuchElementException} if no such element is found.public static <T> int indexOfFirst(Iterable<T> thiz, Predicate<T> predicate)
predicate
, or -1 if the collection does not contain such element.public static <T> T firstOrNull(Iterable<T> thiz)
public static <T> T firstOrNull(Iterable<T> thiz, Predicate<T> predicate)
predicate
, or null
if element was not found.public static <T> T last(Iterable<T> thiz)
NoSuchElementException
- if the collection is empty.public static <T> T last(Iterable<T> thiz, Predicate<T> predicate)
predicate
.NoSuchElementException
- if no such element is found.public static <T> int indexOfLast(Iterable<T> thiz, Predicate<T> predicate)
predicate
, or -1 if the collection does not contain such element.public static <T> T lastOrNull(Iterable<T> thiz)
null
if the collection is empty.public static <T> T lastOrNull(Iterable<T> thiz, Predicate<T> predicate)
predicate
, or null
if no such element was found.public static <T> T single(Iterable<T> thiz)
public static <T> T single(Iterable<T> thiz, Predicate<T> predicate)
predicate
, or throws exception if there is no or more than one matching element.public static <T> T singleOrNull(Iterable<T> thiz)
null
if the collection is empty or has more than one element.public static <T> T singleOrNull(Iterable<T> thiz, Predicate<T> predicate)
predicate
, or null
if element was not found or more than one element was found.public static <T> List<T> filterToList(Iterable<T> thiz, Predicate<T> predicate)
predicate
.public static <T,C extends Collection<? super T>> C filterTo(Iterable<T> thiz, C destination, Predicate<T> predicate)
predicate
to the given destination
.public static <T> List<T> filterIndexedToList(Iterable<T> thiz, IndexedPredicate<T> predicate)
predicate
.predicate
- function that takes the index of an element and the element itself
and returns the result of predicate evaluation on the element.public static <T,C extends Collection<? super T>> C filterIndexedTo(Iterable<T> thiz, C destination, IndexedPredicate<T> predicate)
predicate
to the given destination
.predicate
- function that takes the index of an element and the element itself
and returns the result of predicate evaluation on the element.public static <T> List<T> filterNotToList(Iterable<T> thiz, Predicate<T> predicate)
predicate
.public static <T,C extends Collection<? super T>> C filterNotTo(Iterable<T> thiz, C destination, Predicate<T> predicate)
predicate
to the given destination
.public static <T> Collection<T> reversed(Iterable<T> thiz)
SequencedCollection#reversed()
and List#reversed()
.These new methods provide the same functionality, but only for SequencedCollection.public static <T> Set<T> toSet(Iterable<T> thiz)
Set
containing all unique elements.
The returned set preserves the element iteration order of the original collection.
public static <T,R> List<R> flatMap(Iterable<T> thiz, Function<T,Iterable<R>> transform)
transform
function being invoked on each element of original collection.public static <T,R,C extends Collection<R>> C flatMapTo(Iterable<T> thiz, C destination, Function<T,Iterable<R>> transform)
transform
function being invoked on each element of original collection, to the given destination
.public static <T> List<T> distinctList(Iterable<T> thiz)
The elements in the resulting list are in the same order as they were in the source collection.
public static <T,K> List<T> distinctBy(Iterable<T> thiz, Function<T,K> selector)
selector
function.
The elements in the resulting list are in the same order as they were in the source collection.
public static <T> Set<T> intersect(Iterable<T> thiz, Iterable<T> other)
The returned set preserves the element iteration order of the original collection.
public static <T> Set<T> subtract(Iterable<T> thiz, Iterable<T> other)
The returned set preserves the element iteration order of the original collection.
public static <T> Set<T> union(Iterable<T> thiz, Iterable<T> other)
The returned set preserves the element iteration order of the original collection.
Those elements of the other
collection that are unique are iterated in the end
in the order of the other
collection.
public static <T> int count(Iterable<T> thiz)
public static <T> int count(Iterable<T> thiz, Predicate<T> predicate)
predicate
.public static <T> T maxWith(Iterable<T> thiz, Comparator<T> comparator)
comparator
or null
if there are no elements.public static <T> T minWith(Iterable<T> thiz, Comparator<T> comparator)
comparator
or null
if there are no elements.public static <T> manifold.rt.api.util.Pair<List<T>,List<T>> partition(Iterable<T> thiz, Predicate<T> predicate)
predicate
yielded true
,
while second list contains elements for which predicate
yielded false
.public static <T,R> List<R> mapToList(Iterable<T> thiz, Function<T,R> transform)
transform
function
to each element in the original collection.@Deprecated public static <T,R> List<R> mapIndexed(Iterable<T> thiz, IndexedFunction<T,R> transform)
mapIndexedToList(Iterable, IndexedFunction)
instead.transform
function
to each element and its index in the original collection.transform
- function that takes the index of an element and the element itself
and returns the result of the transform applied to the element.public static <T,R> List<R> mapIndexedToList(Iterable<T> thiz, IndexedFunction<T,R> transform)
transform
function
to each element and its index in the original collection.transform
- function that takes the index of an element and the element itself
and returns the result of the transform applied to the element.@Deprecated public static <T,R> List<R> mapIndexedNotNull(Iterable<T> thiz, IndexedFunction<T,R> transform)
mapIndexedNotNullToList(Iterable, IndexedFunction)
instead.transform
function
to each element and its index in the original collection.transform
- function that takes the index of an element and the element itself
and returns the result of the transform applied to the element.public static <T,R> List<R> mapIndexedNotNullToList(Iterable<T> thiz, IndexedFunction<T,R> transform)
transform
function
to each element and its index in the original collection.transform
- function that takes the index of an element and the element itself
and returns the result of the transform applied to the element.public static <T,R,C extends Collection<? super R>> C mapIndexedNotNullTo(Iterable<T> thiz, C destination, IndexedFunction<T,R> transform)
transform
function to each element and its index in the original collection
and appends only the non-null results to the given destination
.transform
- function that takes the index of an element and the element itself
and returns the result of the transform applied to the element.public static <T,R,C extends Collection<? super R>> C mapIndexedTo(Iterable<T> thiz, C destination, IndexedFunction<T,R> transform)
transform
function to each element and its index in the original collection
and appends the results to the given destination
.transform
- function that takes the index of an element and the element itself
and returns the result of the transform applied to the element.@Deprecated public static <T,R> List<R> mapNotNull(Iterable<T> thiz, Function<T,R> transform)
mapNotNullToList(Iterable, Function)
instead.transform
function
to each element in the original collection.public static <T,R> List<R> mapNotNullToList(Iterable<T> thiz, Function<T,R> transform)
transform
function
to each element in the original collection.public static <T,R,C extends Collection<? super R>> C mapNotNullTo(Iterable<T> thiz, C destination, Function<T,R> transform)
transform
function to each element in the original collection
and appends only the non-null results to the given destination
.public static <T,R,C extends Collection<? super R>> C mapTo(Iterable<T> thiz, C destination, Function<T,R> transform)
transform
function to each element of the original collection
and appends the results to the given destination
.public static <T> List<T> subList(Iterable<T> thiz, int fromIndex)
fromIndex
(inclusive)public static <T> List<T> subList(Iterable<T> thiz, int fromIndex, int toIndex)
fromIndex
(inclusive) to toIndex
(exclusive)public static <T> void forEachIndexed(Iterable<T> thiz, IndexedConsumer<T> action)
action
on each element, providing sequential index with the element.action
- function that takes the index of an element and the element itself
and performs the desired action on the element.public static <T> String joinToString(Iterable<T> thiz, CharSequence separator)
separator
.public static <T,A extends Appendable> A joinTo(Iterable<T> thiz, A buffer, CharSequence separator)
buffer
separated by separator
.public static <T,R> R fold(Iterable<T> thiz, R initial, BiFunction<R,T,R> operation)
demo
value and applying operation
from left to right to current accumulator value and each element.
The operation is terminal.
Copyright © 2024. All rights reserved.