Class ManIterableExt
- java.lang.Object
-
- manifold.collections.extensions.java.lang.Iterable.ManIterableExt
-
public class ManIterableExt extends Object
-
-
Constructor Summary
Constructors Constructor Description ManIterableExt()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static <T> intcount(Iterable<T> thiz)Returns the number of elements in thiz collection.static <T> intcount(Iterable<T> thiz, Predicate<T> predicate)Returns the number of elements matching the givenpredicate.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 givenselectorfunction.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>>
CfilterIndexedTo(Iterable<T> thiz, C destination, manifold.ext.rt.api.IndexedPredicate<T> predicate)Appends all elements matching the givenpredicateto the givendestination.static <T> List<T>filterIndexedToList(Iterable<T> thiz, manifold.ext.rt.api.IndexedPredicate<T> predicate)Returns a list containing only elements matching the givenpredicate.static <T,C extends Collection<? super T>>
CfilterNotTo(Iterable<T> thiz, C destination, Predicate<T> predicate)Appends all elements not matching the givenpredicateto the givendestination.static <T> List<T>filterNotToList(Iterable<T> thiz, Predicate<T> predicate)Returns a list containing all elements not matching the givenpredicate.static <T,C extends Collection<? super T>>
CfilterTo(Iterable<T> thiz, C destination, Predicate<T> predicate)Appends all elements matching the givenpredicateto the givendestination.static <T> List<T>filterToList(Iterable<T> thiz, Predicate<T> predicate)Returns a list containing all elements matching the givenpredicate.static <T> Tfirst(Iterable<T> thiz)Returns first element.static <T> Tfirst(Iterable<T> thiz, Predicate<T> predicate)Returns the first element matching the givenpredicate.static <T> TfirstOrNull(Iterable<T> thiz)Returns the first element, or null if the collection is empty.static <T> TfirstOrNull(Iterable<T> thiz, Predicate<T> predicate)Returns the first element matching the givenpredicate, ornullif 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 oftransformfunction being invoked on each element of original collection.static <T,R,C extends Collection<R>>
CflatMapTo(Iterable<T> thiz, C destination, Function<T,Iterable<R>> transform)Appends all elements yielded from results oftransformfunction being invoked on each element of original collection, to the givendestination.static <T,R>
Rfold(Iterable<T> thiz, R initial, BiFunction<R,T,R> operation)Accumulates value starting withdemovalue and applyingoperationfrom left to right to current accumulator value and each element.static <T> voidforEachIndexed(Iterable<T> thiz, manifold.ext.rt.api.IndexedConsumer<T> action)Performs the givenactionon each element, providing sequential index with the element.static <T> intindexOfFirst(Iterable<T> thiz, Predicate<T> predicate)Returns index of the first element matching the givenpredicate, or -1 if the collection does not contain such element.static <T> intindexOfLast(Iterable<T> thiz, Predicate<T> predicate)Returns index of the last element matching the givenpredicate, 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>
AjoinTo(Iterable<T> thiz, A buffer, CharSequence separator)Append the elements tobufferseparated byseparator.static <T> StringjoinToString(Iterable<T> thiz, CharSequence separator)Join the elements together in a String separated byseparator.static <T> Tlast(Iterable<T> thiz)Returns the last element.static <T> Tlast(Iterable<T> thiz, Predicate<T> predicate)Returns the last element matching the givenpredicate.static <T> TlastOrNull(Iterable<T> thiz)Returns the last element, ornullif the collection is empty.static <T> TlastOrNull(Iterable<T> thiz, Predicate<T> predicate)Returns the last element matching the givenpredicate, ornullif no such element was found.static <T,R>
List<R>mapIndexed(Iterable<T> thiz, manifold.ext.rt.api.IndexedFunction<T,R> transform)Deprecated.UsemapIndexedToList(Iterable, IndexedFunction)instead.static <T,R>
List<R>mapIndexedNotNull(Iterable<T> thiz, manifold.ext.rt.api.IndexedFunction<T,R> transform)Deprecated.UsemapIndexedNotNullToList(Iterable, IndexedFunction)instead.static <T,R,C extends Collection<? super R>>
CmapIndexedNotNullTo(Iterable<T> thiz, C destination, manifold.ext.rt.api.IndexedFunction<T,R> transform)Applies the giventransformfunction to each element and its index in the original collection and appends only the non-null results to the givendestination.static <T,R>
List<R>mapIndexedNotNullToList(Iterable<T> thiz, manifold.ext.rt.api.IndexedFunction<T,R> transform)Returns a list containing only the non-null results of applying the giventransformfunction to each element and its index in the original collection.static <T,R,C extends Collection<? super R>>
CmapIndexedTo(Iterable<T> thiz, C destination, manifold.ext.rt.api.IndexedFunction<T,R> transform)Applies the giventransformfunction to each element and its index in the original collection and appends the results to the givendestination.static <T,R>
List<R>mapIndexedToList(Iterable<T> thiz, manifold.ext.rt.api.IndexedFunction<T,R> transform)Returns a list containing the results of applying the giventransformfunction to each element and its index in the original collection.static <T,R>
List<R>mapNotNull(Iterable<T> thiz, Function<T,R> transform)Deprecated.UsemapNotNullToList(Iterable, Function)instead.static <T,R,C extends Collection<? super R>>
CmapNotNullTo(Iterable<T> thiz, C destination, Function<T,R> transform)Applies the giventransformfunction to each element in the original collection and appends only the non-null results to the givendestination.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 giventransformfunction to each element in the original collection.static <T,R,C extends Collection<? super R>>
CmapTo(Iterable<T> thiz, C destination, Function<T,R> transform)Applies the giventransformfunction to each element of the original collection and appends the results to the givendestination.static <T,R>
List<R>mapToList(Iterable<T> thiz, Function<T,R> transform)Returns a list containing the results of applying the giventransformfunction to each element in the original collection.static <T> TmaxWith(Iterable<T> thiz, Comparator<T> comparator)Returns the first element having the largest value according to the providedcomparatorornullif there are no elements.static <T> TminWith(Iterable<T> thiz, Comparator<T> comparator)Returns the first element having the smallest value according to the providedcomparatorornullif 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 whichpredicateyieldedtrue, while second list contains elements for whichpredicateyieldedfalse.static <T> Collection<T>reversed(Iterable<T> thiz)Returns a collection with elements in reversed order.static <T> Tsingle(Iterable<T> thiz)Returns the single element, or throws an exception if the collection is empty or has more than one element.static <T> Tsingle(Iterable<T> thiz, Predicate<T> predicate)Returns the single element matching the givenpredicate, or throws exception if there is no or more than one matching element.static <T> TsingleOrNull(Iterable<T> thiz)Returns single element, ornullif the collection is empty or has more than one element.static <T> TsingleOrNull(Iterable<T> thiz, Predicate<T> predicate)Returns the single element matching the givenpredicate, ornullif 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 fromfromIndex(inclusive)static <T> List<T>subList(Iterable<T> thiz, int fromIndex, int toIndex)Returns a list containing the elmeentsfromIndex(inclusive) totoIndex(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 aListcontaining all elements.static <T> Set<T>toSet(Iterable<T> thiz)Returns aSetcontaining all unique elements.static <T> Set<T>union(Iterable<T> thiz, Iterable<T> other)Returns a set containing all distinct elements from both collections.
-
-
-
Method Detail
-
first
public static <T> T first(Iterable<T> thiz)
Returns first element.- Throws:
NoSuchElementException- if the collection is empty.
-
first
public static <T> T first(Iterable<T> thiz, Predicate<T> predicate)
Returns the first element matching the givenpredicate.
-
indexOfFirst
public static <T> int indexOfFirst(Iterable<T> thiz, Predicate<T> predicate)
Returns index of the first element matching the givenpredicate, or -1 if the collection does not contain such element.
-
firstOrNull
public static <T> T firstOrNull(Iterable<T> thiz)
Returns the first element, or null if the collection is empty.
-
firstOrNull
public static <T> T firstOrNull(Iterable<T> thiz, Predicate<T> predicate)
Returns the first element matching the givenpredicate, ornullif element was not found.
-
last
public static <T> T last(Iterable<T> thiz)
Returns the last element.- Throws:
NoSuchElementException- if the collection is empty.
-
last
public static <T> T last(Iterable<T> thiz, Predicate<T> predicate)
Returns the last element matching the givenpredicate.- Throws:
NoSuchElementException- if no such element is found.
-
indexOfLast
public static <T> int indexOfLast(Iterable<T> thiz, Predicate<T> predicate)
Returns index of the last element matching the givenpredicate, or -1 if the collection does not contain such element.
-
lastOrNull
public static <T> T lastOrNull(Iterable<T> thiz)
Returns the last element, ornullif the collection is empty.
-
lastOrNull
public static <T> T lastOrNull(Iterable<T> thiz, Predicate<T> predicate)
Returns the last element matching the givenpredicate, ornullif no such element was found.
-
single
public 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.
-
single
public static <T> T single(Iterable<T> thiz, Predicate<T> predicate)
Returns the single element matching the givenpredicate, or throws exception if there is no or more than one matching element.
-
singleOrNull
public static <T> T singleOrNull(Iterable<T> thiz)
Returns single element, ornullif the collection is empty or has more than one element.
-
singleOrNull
public static <T> T singleOrNull(Iterable<T> thiz, Predicate<T> predicate)
Returns the single element matching the givenpredicate, ornullif element was not found or more than one element was found.
-
filterToList
public static <T> List<T> filterToList(Iterable<T> thiz, Predicate<T> predicate)
Returns a list containing all elements matching the givenpredicate.
-
filterTo
public static <T,C extends Collection<? super T>> C filterTo(Iterable<T> thiz, C destination, Predicate<T> predicate)
Appends all elements matching the givenpredicateto the givendestination.
-
filterIndexedToList
public static <T> List<T> filterIndexedToList(Iterable<T> thiz, manifold.ext.rt.api.IndexedPredicate<T> predicate)
Returns a list containing only elements matching the givenpredicate.- Parameters:
predicate- function that takes the index of an element and the element itself and returns the result of predicate evaluation on the element.
-
filterIndexedTo
public static <T,C extends Collection<? super T>> C filterIndexedTo(Iterable<T> thiz, C destination, manifold.ext.rt.api.IndexedPredicate<T> predicate)
Appends all elements matching the givenpredicateto the givendestination.- Parameters:
predicate- function that takes the index of an element and the element itself and returns the result of predicate evaluation on the element.
-
filterNotToList
public static <T> List<T> filterNotToList(Iterable<T> thiz, Predicate<T> predicate)
Returns a list containing all elements not matching the givenpredicate.
-
filterNotTo
public static <T,C extends Collection<? super T>> C filterNotTo(Iterable<T> thiz, C destination, Predicate<T> predicate)
Appends all elements not matching the givenpredicateto the givendestination.
-
reversed
public static <T> Collection<T> reversed(Iterable<T> thiz)
Returns a collection with elements in reversed order. Note, this method expires with JDK 21 because it interferes with new methods:SequencedCollection#reversed()andList#reversed().These new methods provide the same functionality, but only for SequencedCollection.
-
toSet
public static <T> Set<T> toSet(Iterable<T> thiz)
Returns aSetcontaining all unique elements.The returned set preserves the element iteration order of the original collection.
-
flatMap
public static <T,R> List<R> flatMap(Iterable<T> thiz, Function<T,Iterable<R>> transform)
Returns a single list of all elements yielded from results oftransformfunction being invoked on each element of original collection.
-
flatMapTo
public static <T,R,C extends Collection<R>> C flatMapTo(Iterable<T> thiz, C destination, Function<T,Iterable<R>> transform)
Appends all elements yielded from results oftransformfunction being invoked on each element of original collection, to the givendestination.
-
distinctList
public static <T> List<T> distinctList(Iterable<T> thiz)
Returns a list containing only distinct elements from the given collection.The elements in the resulting list are in the same order as they were in the source collection.
-
distinctBy
public 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 givenselectorfunction.The elements in the resulting list are in the same order as they were in the source collection.
-
intersect
public 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.The returned set preserves the element iteration order of the original collection.
-
subtract
public 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.The returned set preserves the element iteration order of the original collection.
-
union
public static <T> Set<T> union(Iterable<T> thiz, Iterable<T> other)
Returns a set containing all distinct elements from both collections.The returned set preserves the element iteration order of the original collection. Those elements of the
othercollection that are unique are iterated in the end in the order of theothercollection.
-
count
public static <T> int count(Iterable<T> thiz)
Returns the number of elements in thiz collection.
-
count
public static <T> int count(Iterable<T> thiz, Predicate<T> predicate)
Returns the number of elements matching the givenpredicate.
-
maxWith
public static <T> T maxWith(Iterable<T> thiz, Comparator<T> comparator)
Returns the first element having the largest value according to the providedcomparatorornullif there are no elements.
-
minWith
public static <T> T minWith(Iterable<T> thiz, Comparator<T> comparator)
Returns the first element having the smallest value according to the providedcomparatorornullif there are no elements.
-
partition
public 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 whichpredicateyieldedtrue, while second list contains elements for whichpredicateyieldedfalse.
-
mapToList
public static <T,R> List<R> mapToList(Iterable<T> thiz, Function<T,R> transform)
Returns a list containing the results of applying the giventransformfunction to each element in the original collection.
-
mapIndexed
@Deprecated public static <T,R> List<R> mapIndexed(Iterable<T> thiz, manifold.ext.rt.api.IndexedFunction<T,R> transform)
Deprecated.UsemapIndexedToList(Iterable, IndexedFunction)instead.Returns a list containing the results of applying the giventransformfunction to each element and its index in the original collection.- Parameters:
transform- function that takes the index of an element and the element itself and returns the result of the transform applied to the element.
-
mapIndexedToList
public static <T,R> List<R> mapIndexedToList(Iterable<T> thiz, manifold.ext.rt.api.IndexedFunction<T,R> transform)
Returns a list containing the results of applying the giventransformfunction to each element and its index in the original collection.- Parameters:
transform- function that takes the index of an element and the element itself and returns the result of the transform applied to the element.
-
mapIndexedNotNull
@Deprecated public static <T,R> List<R> mapIndexedNotNull(Iterable<T> thiz, manifold.ext.rt.api.IndexedFunction<T,R> transform)
Deprecated.UsemapIndexedNotNullToList(Iterable, IndexedFunction)instead.Returns a list containing only the non-null results of applying the giventransformfunction to each element and its index in the original collection.- Parameters:
transform- function that takes the index of an element and the element itself and returns the result of the transform applied to the element.
-
mapIndexedNotNullToList
public static <T,R> List<R> mapIndexedNotNullToList(Iterable<T> thiz, manifold.ext.rt.api.IndexedFunction<T,R> transform)
Returns a list containing only the non-null results of applying the giventransformfunction to each element and its index in the original collection.- Parameters:
transform- function that takes the index of an element and the element itself and returns the result of the transform applied to the element.
-
mapIndexedNotNullTo
public static <T,R,C extends Collection<? super R>> C mapIndexedNotNullTo(Iterable<T> thiz, C destination, manifold.ext.rt.api.IndexedFunction<T,R> transform)
Applies the giventransformfunction to each element and its index in the original collection and appends only the non-null results to the givendestination.- Parameters:
transform- function that takes the index of an element and the element itself and returns the result of the transform applied to the element.
-
mapIndexedTo
public static <T,R,C extends Collection<? super R>> C mapIndexedTo(Iterable<T> thiz, C destination, manifold.ext.rt.api.IndexedFunction<T,R> transform)
Applies the giventransformfunction to each element and its index in the original collection and appends the results to the givendestination.- Parameters:
transform- function that takes the index of an element and the element itself and returns the result of the transform applied to the element.
-
mapNotNull
@Deprecated public static <T,R> List<R> mapNotNull(Iterable<T> thiz, Function<T,R> transform)
Deprecated.UsemapNotNullToList(Iterable, Function)instead.Returns a list containing only the non-null results of applying the giventransformfunction to each element in the original collection.
-
mapNotNullToList
public 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 giventransformfunction to each element in the original collection.
-
mapNotNullTo
public static <T,R,C extends Collection<? super R>> C mapNotNullTo(Iterable<T> thiz, C destination, Function<T,R> transform)
Applies the giventransformfunction to each element in the original collection and appends only the non-null results to the givendestination.
-
mapTo
public static <T,R,C extends Collection<? super R>> C mapTo(Iterable<T> thiz, C destination, Function<T,R> transform)
Applies the giventransformfunction to each element of the original collection and appends the results to the givendestination.
-
subList
public static <T> List<T> subList(Iterable<T> thiz, int fromIndex)
Returns a list containing all the elmeents fromfromIndex(inclusive)
-
subList
public static <T> List<T> subList(Iterable<T> thiz, int fromIndex, int toIndex)
Returns a list containing the elmeentsfromIndex(inclusive) totoIndex(exclusive)
-
forEachIndexed
public static <T> void forEachIndexed(Iterable<T> thiz, manifold.ext.rt.api.IndexedConsumer<T> action)
Performs the givenactionon each element, providing sequential index with the element.- Parameters:
action- function that takes the index of an element and the element itself and performs the desired action on the element.
-
joinToString
public static <T> String joinToString(Iterable<T> thiz, CharSequence separator)
Join the elements together in a String separated byseparator.
-
joinTo
public static <T,A extends Appendable> A joinTo(Iterable<T> thiz, A buffer, CharSequence separator)
Append the elements tobufferseparated byseparator.
-
fold
public static <T,R> R fold(Iterable<T> thiz, R initial, BiFunction<R,T,R> operation)
Accumulates value starting withdemovalue and applyingoperationfrom left to right to current accumulator value and each element.The operation is terminal.
-
-