Class 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> 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>>
      C
      filterIndexedTo​(Iterable<T> thiz, C destination, manifold.ext.rt.api.IndexedPredicate<T> predicate)
      Appends all elements matching the given predicate to the given destination.
      static <T> List<T> filterIndexedToList​(Iterable<T> thiz, manifold.ext.rt.api.IndexedPredicate<T> predicate)
      Returns a list containing only elements matching the given predicate.
      static <T,​C extends Collection<? super T>>
      C
      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>>
      C
      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>>
      C
      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, manifold.ext.rt.api.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>
      A
      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, manifold.ext.rt.api.IndexedFunction<T,​R> transform)
      static <T,​R>
      List<R>
      mapIndexedNotNull​(Iterable<T> thiz, manifold.ext.rt.api.IndexedFunction<T,​R> transform)
      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 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, manifold.ext.rt.api.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>>
      C
      mapIndexedTo​(Iterable<T> thiz, C destination, manifold.ext.rt.api.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, manifold.ext.rt.api.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.
      static <T,​R,​C extends Collection<? super R>>
      C
      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>>
      C
      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.
    • Constructor Detail

      • ManIterableExt

        public ManIterableExt()
    • Method Detail

      • first

        public static <T> T first​(Iterable<T> thiz,
                                  Predicate<T> predicate)
        Returns the first element matching the given predicate.
      • indexOfFirst

        public 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.
      • 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 given predicate, or null if element was not found.
      • last

        public static <T> T last​(Iterable<T> thiz,
                                 Predicate<T> predicate)
        Returns the last element matching the given predicate.
        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 given predicate, or -1 if the collection does not contain such element.
      • lastOrNull

        public static <T> T lastOrNull​(Iterable<T> thiz)
        Returns the last element, or null if the collection is empty.
      • lastOrNull

        public 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.
      • 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 given predicate, 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, or null if 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 given predicate, or null if 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 given predicate.
      • filterTo

        public static <T,​C extends Collection<? super T>> C filterTo​(Iterable<T> thiz,
                                                                           C destination,
                                                                           Predicate<T> predicate)
        Appends all elements matching the given predicate to the given destination.
      • 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 given predicate.
        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 given predicate to the given destination.
        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 given predicate.
      • 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 given predicate to the given destination.
      • 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() and List#reversed().These new methods provide the same functionality, but only for SequencedCollection.

      • toList

        public static <T> List<T> toList​(Iterable<T> thiz)
        Returns a List containing all elements.
      • toSet

        public static <T> Set<T> toSet​(Iterable<T> thiz)
        Returns a Set containing 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 of transform function 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 of transform function being invoked on each element of original collection, to the given destination.
      • 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 given selector function.

        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 other collection that are unique are iterated in the end in the order of the other collection.

      • 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 given predicate.
      • maxWith

        public 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.
      • minWith

        public 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.
      • 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 which predicate yielded true, while second list contains elements for which predicate yielded false.
      • mapToList

        public 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.
      • mapIndexed

        @Deprecated
        public static <T,​R> List<R> mapIndexed​(Iterable<T> thiz,
                                                     manifold.ext.rt.api.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.
        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 given transform function 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)
        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.
        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 given transform function 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 given transform function to each element and its index in the original collection and appends only the non-null results to the given destination.
        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 given transform function to each element and its index in the original collection and appends the results to the given destination.
        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.
      • 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 given transform function 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 given transform function to each element in the original collection and appends only the non-null results to the given destination.
      • mapTo

        public static <T,​R,​C extends Collection<? super R>> C 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.
      • subList

        public static <T> List<T> subList​(Iterable<T> thiz,
                                          int fromIndex)
        Returns a list containing all the elmeents from fromIndex (inclusive)
      • subList

        public static <T> List<T> subList​(Iterable<T> thiz,
                                          int fromIndex,
                                          int toIndex)
        Returns a list containing the elmeents fromIndex (inclusive) to toIndex (exclusive)
      • forEachIndexed

        public static <T> void forEachIndexed​(Iterable<T> thiz,
                                              manifold.ext.rt.api.IndexedConsumer<T> action)
        Performs the given action on 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 by separator.
      • joinTo

        public static <T,​A extends Appendable> A joinTo​(Iterable<T> thiz,
                                                              A buffer,
                                                              CharSequence separator)
        Append the elements to buffer separated by separator.
      • fold

        public 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.

        The operation is terminal.