Class CollectionUtils


  • public class CollectionUtils
    extends java.lang.Object
    Collection of small static helper methods using Collections.
    • Constructor Summary

      Constructors 
      Constructor Description
      CollectionUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <K,​V>
      void
      accumulateMap​(java.util.Map<K,​V> map1, java.util.Map<K,​V> map2, java.util.function.BinaryOperator<V> accumulator)  
      static <K,​V>
      void
      accumulateToMap​(java.util.Map<K,​V> map, K key, V value, java.util.function.BinaryOperator<V> accumulator)  
      static <T> boolean all​(java.util.Collection<T> c, java.util.function.Predicate<? super T> predicate)
      Do all members of an collection match a predicate?
      static <T> boolean all​(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate)
      Do all members of an stream match a predicate?
      static <T> boolean all​(T[] array, java.util.function.Predicate<? super T> predicate)
      Do all members of an array match a predicate?
      private static <T> boolean all_internal​(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate)
      Implementation of all().
      static <T> boolean allSame​(java.util.Collection<T> c)
      Are all members of a collection the same (in the sense of ==).
      static <T> java.util.function.Predicate<T> alwaysTrue()
      Helper to create a predicate which is always true.
      static <T> boolean any​(java.util.Collection<T> c)
      Is a collection non-empty?
      static <T> boolean any​(java.util.Collection<T> c, java.util.function.Predicate<? super T> predicate)
      Does any member of a collection match a predicate?
      static <T> boolean any​(java.util.stream.Stream<T> stream)
      Is a stream non-empty?
      static <T> boolean any​(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate)
      Does any member of a stream match a predicate?
      static <T> boolean any​(T[] array)
      Is an array non-empty?
      static <T> boolean any​(T[] array, java.util.function.Predicate<? super T> predicate)
      Does any member of an array match a predicate?
      private static <T> boolean any_internal​(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate)
      Implementation of any().
      static <T,​K>
      void
      appendToMapList​(java.util.Map<K,​java.util.List<T>> map, K key, T value)
      Appends a value to a list member of a map with a given key.
      static <T> java.util.Map<T,​T> asMap​(T... values)
      Make a map from a flat list of key,value pairs.
      static <T> java.util.function.ToDoubleFunction<T> cacheDouble​(java.util.function.Function<T,​java.lang.Double> f)
      Helper to create a caching ToDoubleFunction.
      static <T> java.util.function.ToIntFunction<T> cacheInt​(java.util.function.Function<T,​java.lang.Integer> f)
      Helper to create a caching ToIntFunction.
      static <T> java.util.Comparator<T> cachingDoubleComparator​(java.util.function.Function<T,​java.lang.Double> f)
      Helper to create a caching comparator.
      static <T> java.util.Comparator<T> cachingIntComparator​(java.util.function.Function<T,​java.lang.Integer> f)
      Helper to create a caching comparator.
      static <T> java.util.stream.Stream<T> concat​(java.util.stream.Stream<T> s0, java.util.stream.Stream<T>... streams)
      Concatenate streams.
      static <T> int count​(java.util.Collection<T> c)
      Count the number of members of a collection that match a predicate.
      static <T> int count​(java.util.Collection<T> c, java.util.function.Predicate<? super T> predicate)
      Count the number of members of a collection that match a predicate.
      static <T> int count​(java.util.stream.Stream<T> stream)
      Count the number of members of a stream.
      static <T> int count​(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate)
      Count the number of members of a stream that match a predicate.
      static <T> int count​(T[] array)
      Count the number of members of an array.
      static <T> int count​(T[] array, java.util.function.Predicate<? super T> predicate)
      Count the number of members of an array that match a predicate.
      private static <T> int count_internal​(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate)
      Implement count().
      static void dump​(java.lang.String header, java.util.Collection<?> c)
      Dump a collection to System.err.
      static void dump​(java.lang.String header, java.util.Map<?,​?> map)
      Dump a map to System.err.
      static void dump​(java.lang.String header, java.util.stream.Stream<?> stream)
      Dump a stream to System.err.
      static <T> void dump​(java.lang.String header, T[] array)
      Dump an array to System.err.
      private static void dump_internal​(java.lang.String header, java.util.stream.Stream<?> stream)
      Implement dump().
      static java.util.stream.Stream<java.io.File> fileStream​(java.io.File dir)
      Create a stream of files from a directory.
      static java.util.stream.Stream<java.io.File> fileStream​(java.io.File dir, java.util.function.Predicate<? super java.io.File> predicate)
      Create a stream of files from a directory, that each match a predicate.
      static <T> T find​(java.util.Collection<T> c, java.util.function.Predicate<? super T> predicate)
      Simple stream search for the first item that matches a predicate.
      static <T> T find​(java.util.Collection<T> c, java.util.function.Predicate<? super T> predicate, T fail)
      Simple stream search for the first item that matches a predicate.
      static <T> T find​(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate)
      Simple stream search for the first item that matches a predicate.
      static <T> T find​(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate, T fail)
      Simple stream search for the first item that matches a predicate.
      static <T> T find​(T[] array, java.util.function.Predicate<? super T> predicate)
      Simple stream search for the first item that matches a predicate.
      static <T> T find​(T[] array, java.util.function.Predicate<? super T> predicate, T fail)
      Simple stream search for the first item that matches a predicate.
      private static <T> T find_internal​(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate, T fail)
      Implement find().
      static <T> T first​(java.util.Collection<T> c)
      Get the first item of a collection.
      static <T> T first​(java.util.stream.Stream<T> stream)
      Get the first item of a stream.
      static <T> T first​(T[] array)
      Get the first item of an array.
      private static <T> T first_internal​(java.util.stream.Stream<T> stream, T fail)
      Implement first().
      static <T,​R>
      java.util.stream.Stream<R>
      flatten​(java.util.Collection<T> c, java.util.function.Function<? super T,​? extends java.util.stream.Stream<? extends R>> mapper)
      Flatten a collection into a stream derived from its component streams.
      static <T,​R>
      java.util.stream.Stream<R>
      flatten​(java.util.Collection<T> c, java.util.function.Predicate<? super T> predicate, java.util.function.Function<? super T,​? extends java.util.stream.Stream<? extends R>> mapper)
      Flatten a collection into a stream derived from its component streams.
      static <T,​R>
      java.util.stream.Stream<R>
      flatten​(java.util.stream.Stream<T> stream, java.util.function.Function<? super T,​? extends java.util.stream.Stream<? extends R>> mapper)
      Flatten the members of a stream.
      static <T,​R>
      java.util.stream.Stream<R>
      flatten​(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate, java.util.function.Function<? super T,​? extends java.util.stream.Stream<? extends R>> mapper)
      Flatten the members of a stream.
      static <T,​R>
      java.util.stream.Stream<R>
      flatten​(T[] array, java.util.function.Function<? super T,​? extends java.util.stream.Stream<? extends R>> mapper)
      Flatten an array into a stream derived from its component streams.
      static <T,​R>
      java.util.stream.Stream<R>
      flatten​(T[] array, java.util.function.Predicate<? super T> predicate, java.util.function.Function<? super T,​? extends java.util.stream.Stream<? extends R>> mapper)
      Flatten an array into a stream derived from its component streams.
      private static <T,​R>
      java.util.stream.Stream<R>
      flatten_internal​(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate, java.util.function.Function<? super T,​? extends java.util.stream.Stream<? extends R>> mapper)
      Flatten the members of a stream.
      static <T> void forEach​(java.util.Collection<T> c, java.util.function.Consumer<? super T> consumer)
      Apply a consumer to the members of a collection.
      static <T> void forEach​(java.util.Collection<T> c, java.util.function.Predicate<? super T> predicate, java.util.function.Consumer<? super T> consumer)
      Apply a consumer to the members of a collection that match a predicate.
      static <T> void forEach​(java.util.stream.Stream<T> stream, java.util.function.Consumer<? super T> consumer)
      Apply a consumer to the members of a stream.
      static <T> void forEach​(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate, java.util.function.Consumer<? super T> consumer)
      Apply a consumer to the members of a stream that match a predicate.
      static <T> void forEach​(T[] array, java.util.function.Consumer<? super T> consumer)
      Apply a consumer to the members of an array.
      static <T> void forEach​(T[] array, java.util.function.Predicate<? super T> predicate, java.util.function.Consumer<? super T> consumer)
      Apply a consumer to the members of an array that match a predicate.
      private static <T> void forEach_internal​(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate, java.util.function.Consumer<? super T> consumer)
      Implement forEach.
      static <K,​V>
      void
      forEachMapEntry​(java.util.Map<K,​V> map, java.util.function.Consumer<java.util.Map.Entry<K,​V>> consumer)
      Apply a consumer to the entries of a map.
      static <K,​V>
      void
      forEachMapEntry​(java.util.Map<K,​V> map, java.util.function.Predicate<java.util.Map.Entry<K,​V>> predicate, java.util.function.Consumer<java.util.Map.Entry<K,​V>> consumer)
      Apply a consumer to the entries of a map that match a predicate.
      static <T> java.lang.Iterable<java.util.List<T>> getPermutations​(java.util.List<T> l)
      Given a list, return an iterable that yields all permutations of the original list.
      static <K> int incrementMapCount​(java.util.Map<K,​java.lang.Integer> map, K key)
      Increment the count in an integer valued map for a given key.
      static <T> java.util.function.Predicate<T> isNotNull()
      Create a predicate for a type that returns true if the argument is not null.
      static <T,​V>
      java.util.function.Predicate<T>
      isNotNull​(java.util.function.Function<? super T,​V> mapper)
      Create a predicate for a type that returns true if the argument is not null.
      static <T> java.util.function.Predicate<T> isNull()
      Create a predicate for a type that returns true if the argument is null.
      static <T,​V>
      java.util.function.Predicate<T>
      isNull​(java.util.function.Function<? super T,​V> mapper)
      Create a predicate for a type that returns true if the argument is not null.
      static <T> java.lang.Iterable<T> iterable​(java.util.stream.Stream<T> stream)
      Convenience function to convert a stream to an iterable.
      static <T> boolean listEquals​(java.util.List<T> one, java.util.List<T> two)
      Check if two lists contents are equal but also checks for null.
      static <T> java.util.List<T> makeUnmodifiableList​(T... members)
      Make an unmodifiable list with specified members.
      static <K,​V>
      java.util.Map<K,​V>
      makeUnmodifiableMap​(K[] keys, V[] values)
      Make an unmodifiable map with member pairs specified in two arrays.
      static <T> java.util.Set<T> makeUnmodifiableSet​(T... members)
      Make an unmodifiable set with specified members.
      static <T,​R>
      java.util.stream.Stream<R>
      map​(java.util.Collection<T> c, java.util.function.Function<? super T,​? extends R> mapper)
      Create a stream from a collection and an immediate mapping transform.
      static <T,​R>
      java.util.stream.Stream<R>
      map​(java.util.stream.Stream<T> stream, java.util.function.Function<? super T,​? extends R> mapper)
      Apply a mapping to a stream.
      static <T,​R>
      java.util.stream.Stream<R>
      map​(T[] array, java.util.function.Function<? super T,​? extends R> mapper)
      Create a stream from an array and an immediate mapping transform.
      private static <T,​R>
      java.util.stream.Stream<R>
      map_internal​(java.util.stream.Stream<T> stream, java.util.function.Function<? super T,​? extends R> mapper)
      Implement map.
      static <K extends java.lang.Comparable<? super K>,​V>
      java.util.List<java.util.Map.Entry<K,​V>>
      mapEntriesByKey​(java.util.Map<K,​V> map)
      Get the entries in a map in a sorted order.
      static <K,​V>
      java.util.List<java.util.Map.Entry<K,​V>>
      mapEntriesByKey​(java.util.Map<K,​V> map, java.util.Comparator<K> comparator)
      Get the entries in a map in a sorted order.
      static <K,​V extends java.lang.Comparable<? super V>>
      java.util.List<java.util.Map.Entry<K,​V>>
      mapEntriesByValue​(java.util.Map<K,​V> map)
      Get the entries in a map in a sorted order.
      static <K,​V>
      java.util.List<java.util.Map.Entry<K,​V>>
      mapEntriesByValue​(java.util.Map<K,​V> map, java.util.Comparator<V> comparator)
      Get the entries in a map in a sorted order.
      static <T,​K>
      java.util.function.Predicate<T>
      matchKey​(K key, java.util.function.Function<T,​K> mapper)
      Create a predicate for a type that returns true if a mapper applied to it causes it to equal a key.
      static <T> java.util.function.Predicate<T> matchKey​(T key)
      Create a predicate for a type that returns true if it equals a key.
      static <T,​K>
      java.util.function.Predicate<T>
      matchKeyEquals​(K key, java.util.function.Function<T,​K> mapper)
      Create a predicate for a type that returns true if a mapper applied to it causes it to equal a key.
      static <T> java.util.function.Predicate<T> matchKeyEquals​(T key)
      Create a predicate for a type that returns true if it equals a key in the sense of "equals".
      static <T> int max​(java.util.Collection<T> c, java.util.function.Predicate<? super T> predicate, java.util.function.ToIntFunction<T> tif)
      Find the maximum int value in a collection.
      static <T> int max​(java.util.Collection<T> c, java.util.function.ToIntFunction<T> tif)
      Find the maximum int value in a collection.
      static <T> int max​(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate, java.util.function.ToIntFunction<T> tif)
      Find the maximum int value in a stream.
      static <T> int max​(java.util.stream.Stream<T> stream, java.util.function.ToIntFunction<T> tif)
      Find the maximum int value in a stream.
      static <T> int max​(T[] array, java.util.function.Predicate<? super T> predicate, java.util.function.ToIntFunction<T> tif)
      Find the maximum int value in an array.
      static <T> int max​(T[] array, java.util.function.ToIntFunction<T> tif)
      Find the maximum int value in an array.
      private static <T> int max_internal​(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate, java.util.function.ToIntFunction<T> tif)
      Implement max.
      static <T> T maximize​(java.util.Collection<T> c, java.util.Comparator<? super T> comparator)
      Find the selected member of a collection that maximizes according to a given comparison.
      static <T> T maximize​(java.util.Collection<T> c, java.util.function.Predicate<? super T> predicate, java.util.Comparator<? super T> comparator)
      Find the selected member of a collection that maximizes according to a given comparison.
      static <T> T maximize​(java.util.stream.Stream<T> stream, java.util.Comparator<? super T> comparator)
      Find the selected member of a stream that maximizes according to a given comparison.
      static <T> T maximize​(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate, java.util.Comparator<? super T> comparator)
      Find the selected member of a stream that maximizes according to a given comparison.
      static <T> T maximize​(T[] array, java.util.Comparator<? super T> comparator)
      Find the selected member of an array that maximizes according to a given comparison.
      static <T> T maximize​(T[] array, java.util.function.Predicate<? super T> predicate, java.util.Comparator<? super T> comparator)
      Find the selected member of a collection that maximizes according to a given comparison.
      private static <T> T maximize_internal​(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate, java.util.Comparator<? super T> comparator)
      Implement maximize.
      static <T> int min​(java.util.Collection<T> c, java.util.function.Predicate<? super T> predicate, java.util.function.ToIntFunction<T> tif)
      Find the minimum int value in a collection.
      static <T> int min​(java.util.Collection<T> c, java.util.function.ToIntFunction<T> tif)
      Find the minimum int value in a collection.
      static <T> int min​(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate, java.util.function.ToIntFunction<T> tif)
      Find the minimum int value in a stream.
      static <T> int min​(java.util.stream.Stream<T> stream, java.util.function.ToIntFunction<T> tif)
      Find the minimum int value in a stream.
      static <T> int min​(T[] array, java.util.function.Predicate<? super T> predicate, java.util.function.ToIntFunction<T> tif)
      Find the minimum int value in an array.
      static <T> int min​(T[] array, java.util.function.ToIntFunction<T> tif)
      Find the minimum int value in an array.
      private static <T> int min_internal​(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate, java.util.function.ToIntFunction<T> tif)
      Implement min.
      static <T> T minimize​(java.util.Collection<T> c, java.util.Comparator<? super T> comparator)
      Find the selected member of a collection that minimizes according to a given comparison.
      static <T> T minimize​(java.util.Collection<T> c, java.util.function.Predicate<? super T> predicate, java.util.Comparator<? super T> comparator)
      Find the selected member of a collection that minimizes according to a given comparison.
      static <T> T minimize​(java.util.stream.Stream<T> stream, java.util.Comparator<? super T> comparator)
      Find the selected member of a stream that minimizes according to a given comparison.
      static <T> T minimize​(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate, java.util.Comparator<? super T> comparator)
      Find the selected member of a stream that minimizes according to a given comparison.
      static <T> T minimize​(T[] array, java.util.Comparator<? super T> comparator)
      Find the selected member of an array that minimizes according to a given comparison.
      static <T> T minimize​(T[] array, java.util.function.Predicate<? super T> predicate, java.util.Comparator<? super T> comparator)
      Find the selected member of a collection that minimizes according to a given comparison.
      private static <T> T minimize_internal​(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate, java.util.Comparator<? super T> comparator)
      Implement minimize.
      static <T> boolean none​(java.util.Collection<T> c)
      Is a collection empty?
      static <T> boolean none​(java.util.Collection<T> c, java.util.function.Predicate<? super T> predicate)
      Do none of the members of a collection match a predicate?
      static <T> boolean none​(java.util.stream.Stream<T> stream)
      Is a stream null or empty?
      static <T> boolean none​(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate)
      Do none of the members of a stream match a predicate?
      static <T> boolean none​(T[] array)
      Is an array null or empty?
      static <T> boolean none​(T[] array, java.util.function.Predicate<? super T> predicate)
      Do none of the members of an array match a predicate?
      private static <T> boolean none_internal​(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate)
      Implementation of none().
      static <T> double product​(java.util.Collection<T> c, java.util.function.Predicate<? super T> predicate, java.util.function.ToDoubleFunction<T> tdf)
      Take the product of a collection.
      static <T> double product​(java.util.Collection<T> c, java.util.function.ToDoubleFunction<T> tdf)
      Take the product of a collection.
      static <T> double product​(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate, java.util.function.ToDoubleFunction<T> tdf)
      Take the product of the members of a stream.
      static <T> double product​(java.util.stream.Stream<T> stream, java.util.function.ToDoubleFunction<T> tdf)
      Take the product of the members of a stream.
      static <T> double product​(T[] array, java.util.function.Predicate<? super T> predicate, java.util.function.ToDoubleFunction<T> tdf)
      Take the product of an array.
      static <T> double product​(T[] array, java.util.function.ToDoubleFunction<T> tdf)
      Take the product of an array.
      private static <T> double product_internal​(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate, java.util.function.ToDoubleFunction<T> tdf)
      Take the product of the members of a stream.
      static <T> boolean removeInPlace​(java.util.Collection<T> c, java.util.function.Predicate<? super T> predicate)
      Special case to remove objects from a collection.
      static <K,​V>
      boolean
      removeInPlace​(java.util.Map<K,​V> map, java.util.function.Predicate<java.util.Map.Entry<K,​V>> predicate)
      Special case to remove objects from a map.
      static <T> void reverse​(java.util.List<T> list)
      Reverse a list.
      static <T> void rotate​(java.util.List<T> list, int n)
      Rotate a list by N places.
      static <T extends java.lang.Comparable<? super T>>
      java.util.List<T>
      sort​(java.util.Collection<T> c)
      Convenience function to convert a collection to a sorted list.
      static <T> java.util.List<T> sort​(java.util.Collection<T> c, java.util.Comparator<? super T> comparator)
      Convenience function to convert a collection to a map.
      static <T extends java.lang.Comparable<? super T>>
      java.util.List<T>
      sort​(java.util.stream.Stream<T> stream)
      Convenience function to collect a stream to a list.
      static <T> java.util.List<T> sort​(java.util.stream.Stream<T> stream, java.util.Comparator<? super T> comparator)
      Convenience function to collect a stream to a list.
      static <T extends java.lang.Comparable<? super T>>
      java.util.List<T>
      sort​(T[] array)
      Convenience function to convert an array to a sorted list.
      static <T> java.util.List<T> sort​(T[] array, java.util.Comparator<? super T> comparator)
      Convenience function to convert an array to a sorted list.
      private static <T> java.util.List<T> sort_internal​(java.util.stream.Stream<T> stream, java.util.Comparator<? super T> comparator)
      Implement sort.
      static <T> int sum​(java.util.Collection<T> c, java.util.function.Predicate<? super T> predicate, java.util.function.ToIntFunction<T> tif)
      Take the sum of the members of a collection.
      static <T> int sum​(java.util.Collection<T> c, java.util.function.ToIntFunction<T> tif)
      Take the sum of the members of a collection.
      static <T> int sum​(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate, java.util.function.ToIntFunction<T> tif)
      Take the sum of the members of a stream.
      static <T> int sum​(java.util.stream.Stream<T> stream, java.util.function.ToIntFunction<T> tif)
      Take the sum of the members of a stream.
      static <T> int sum​(T[] array, java.util.function.Predicate<? super T> predicate, java.util.function.ToIntFunction<T> tif)
      Take the sum of the members of an array.
      static <T> int sum​(T[] array, java.util.function.ToIntFunction<T> tif)
      Take the sum of the members of an array.
      private static <T> int sum_internal​(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate, java.util.function.ToIntFunction<T> tif)
      Take the sum of the members of a stream.
      static <T> double sumDouble​(java.util.Collection<T> c, java.util.function.Predicate<? super T> predicate, java.util.function.ToDoubleFunction<T> tdf)
      Take the sum of the members of a collection.
      static <T> double sumDouble​(java.util.Collection<T> c, java.util.function.ToDoubleFunction<T> tdf)
      Take the sum of the members of a collection.
      static <T> double sumDouble​(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate, java.util.function.ToDoubleFunction<T> tdf)
      Take the sum of the members of a stream.
      static <T> double sumDouble​(java.util.stream.Stream<T> stream, java.util.function.ToDoubleFunction<T> tdf)
      Take the sum of the members of a stream.
      static <T> double sumDouble​(T[] array, java.util.function.Predicate<? super T> predicate, java.util.function.ToDoubleFunction<T> tdf)
      Take the sum of the members of an array.
      static <T> double sumDouble​(T[] array, java.util.function.ToDoubleFunction<T> tdf)
      Take the sum of the members of an array.
      private static <T> double sumDouble_internal​(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate, java.util.function.ToDoubleFunction<T> tdf)
      Take the sum of the members of a stream.
      static <T> java.util.stream.Collector<java.util.List<T>,​?,​java.util.List<T>> toAppendedList()
      Make a collector that takes lists and appends them.
      static <T> java.util.List<T> toList​(java.util.Collection<T> c)
      Convenience function to convert a collection to a list.
      static <T> java.util.List<T> toList​(java.util.stream.Stream<T> stream)
      Convenience function to collect a stream to a list.
      static <T> java.util.List<T> toList​(T[] array)
      Convenience function to convert an array to a list.
      private static <T> java.util.List<T> toList_internal​(java.util.stream.Stream<T> stream)
      Implement toList.
      static <T> java.util.stream.Collector<T,​?,​java.util.List<T>> toListNoNulls()
      Create a new collector that accumulates to a list but excludes null members.
      static <T> java.util.stream.Stream<T> toStream​(java.lang.Iterable<T> iterable)
      Convert an iterable to a stream.
      static <T> java.util.stream.Stream<T> toStream​(java.util.Iterator<T> iterator)
      Convert an iterator to a stream.
      static <T> java.util.List<T> transform​(java.util.Collection<T> c, java.util.function.Predicate<? super T> predicate)
      Transform the contents of a collection.
      static <T,​R>
      java.util.List<R>
      transform​(java.util.Collection<T> c, java.util.function.Predicate<? super T> predicate, java.util.function.Function<? super T,​? extends R> mapper)
      Transform the contents of a collection.
      static <T,​R>
      java.util.List<R>
      transform​(java.util.Collection<T> c, java.util.function.Predicate<? super T> predicate, java.util.function.Function<? super T,​? extends R> mapper, java.util.Comparator<? super R> comparator)
      Transform the contents of a collection and sort the result.
      static <T,​R,​C>
      C
      transform​(java.util.Collection<T> c, java.util.function.Predicate<? super T> predicate, java.util.function.Function<? super T,​? extends R> mapper, java.util.stream.Collector<R,​?,​C> collector)
      Transform the contents of a collection.
      static <T> java.util.List<T> transform​(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate)
      Transform the contents of a stream.
      static <T,​R>
      java.util.List<R>
      transform​(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate, java.util.function.Function<? super T,​? extends R> mapper)
      Transform the contents of a stream.
      static <T,​R>
      java.util.List<R>
      transform​(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate, java.util.function.Function<? super T,​? extends R> mapper, java.util.Comparator<? super R> comparator)
      Transform the contents of a stream.
      static <T,​R,​C>
      C
      transform​(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate, java.util.function.Function<? super T,​? extends R> mapper, java.util.stream.Collector<R,​?,​C> collector)
      Transform the contents of a stream.
      static <T> java.util.List<T> transform​(T[] array, java.util.function.Predicate<? super T> predicate)
      Transform the contents of an array.
      static <T,​R>
      java.util.List<R>
      transform​(T[] array, java.util.function.Predicate<? super T> predicate, java.util.function.Function<? super T,​? extends R> mapper)
      Transform the contents of an array.
      static <T,​R>
      java.util.List<R>
      transform​(T[] array, java.util.function.Predicate<? super T> predicate, java.util.function.Function<? super T,​? extends R> mapper, java.util.Comparator<? super R> comparator)
      Transform the contents of an array and sort the result.
      static <T,​R,​C>
      C
      transform​(T[] array, java.util.function.Predicate<? super T> predicate, java.util.function.Function<? super T,​? extends R> mapper, java.util.stream.Collector<R,​?,​C> collector)
      Transform the contents of an array.
      private static <T,​R,​C>
      C
      transform_internal​(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate, java.util.function.Function<? super T,​? extends R> mapper, java.util.Comparator<? super R> comparator, java.util.stream.Collector<R,​?,​C> collector)
      Underlying implementation for the transform functions.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • integerAccumulator

        public static final java.util.function.BinaryOperator<java.lang.Integer> integerAccumulator
        Trivial integer accumulator.
      • doubleAccumulator

        public static final java.util.function.BinaryOperator<java.lang.Double> doubleAccumulator
        Trivial double accumulator.
      • ascendingIntegerComparator

        public static final java.util.Comparator<java.lang.Integer> ascendingIntegerComparator
        Useful comparators for mapEntriesBy*
      • descendingIntegerComparator

        public static final java.util.Comparator<java.lang.Integer> descendingIntegerComparator
      • ascendingDoubleComparator

        public static final java.util.Comparator<java.lang.Double> ascendingDoubleComparator
      • descendingDoubleComparator

        public static final java.util.Comparator<java.lang.Double> descendingDoubleComparator
      • ascendingListLengthComparator

        public static final java.util.Comparator<java.util.List<?>> ascendingListLengthComparator
      • descendingListLengthComparator

        public static final java.util.Comparator<java.util.List<?>> descendingListLengthComparator
    • Constructor Detail

      • CollectionUtils

        public CollectionUtils()
    • Method Detail

      • makeUnmodifiableSet

        @SafeVarargs
        public static <T> java.util.Set<T> makeUnmodifiableSet​(T... members)
        Make an unmodifiable set with specified members.
        Type Parameters:
        T - The type of the set members.
        Parameters:
        members - The set members.
        Returns:
        An unmodifiable set containing the members.
      • makeUnmodifiableList

        @SafeVarargs
        public static <T> java.util.List<T> makeUnmodifiableList​(T... members)
        Make an unmodifiable list with specified members.
        Type Parameters:
        T - The type of the list members.
        Parameters:
        members - The list members.
        Returns:
        An unmodifiable list containing the members.
      • makeUnmodifiableMap

        public static <K,​V> java.util.Map<K,​V> makeUnmodifiableMap​(K[] keys,
                                                                               V[] values)
        Make an unmodifiable map with member pairs specified in two arrays. The array lengths *must* match.
        Type Parameters:
        K - The type of the keys.
        V - The type of the values.
        Parameters:
        keys - The array of keys.
        values - The array of values.
        Returns:
        An unmodifiable map containing the specified members.
      • asMap

        @SafeVarargs
        public static <T> java.util.Map<T,​T> asMap​(T... values)
        Make a map from a flat list of key,value pairs. Tolerates odd lists. Perhaps this should be an error.
        Type Parameters:
        T - The value type.
        Parameters:
        values - The list of values.
        Returns:
        A map derived from the values.
      • appendToMapList

        public static <T,​K> void appendToMapList​(java.util.Map<K,​java.util.List<T>> map,
                                                       K key,
                                                       T value)
        Appends a value to a list member of a map with a given key.
        Type Parameters:
        T - The map value collection member type.
        K - The map key type.
        Parameters:
        map - The Map to add to.
        key - The key with which to look up the list in the map.
        value - The value to append.
      • accumulateToMap

        public static <K,​V> void accumulateToMap​(java.util.Map<K,​V> map,
                                                       K key,
                                                       V value,
                                                       java.util.function.BinaryOperator<V> accumulator)
      • accumulateMap

        public static <K,​V> void accumulateMap​(java.util.Map<K,​V> map1,
                                                     java.util.Map<K,​V> map2,
                                                     java.util.function.BinaryOperator<V> accumulator)
      • incrementMapCount

        public static <K> int incrementMapCount​(java.util.Map<K,​java.lang.Integer> map,
                                                K key)
        Increment the count in an integer valued map for a given key.
        Type Parameters:
        K - The map key type.
        Parameters:
        map - The map to increment within.
        key - The key to increment the value for.
        Returns:
        The new count associated with the key.
      • getPermutations

        public static <T> java.lang.Iterable<java.util.List<T>> getPermutations​(java.util.List<T> l)
        Given a list, return an iterable that yields all permutations of the original list. Obviously combinatorial explosion will occur, so use with caution only on lists that are known to be short.
        Type Parameters:
        T - The list member type.
        Parameters:
        l - The original list.
        Returns:
        A iterable yielding all the permutations of the original list.
      • allSame

        public static <T> boolean allSame​(java.util.Collection<T> c)
        Are all members of a collection the same (in the sense of ==).
        Type Parameters:
        T - The collection member type.
        Parameters:
        c - The Collection to examine.
        Returns:
        True if all members are the same.
      • rotate

        public static <T> void rotate​(java.util.List<T> list,
                                      int n)
        Rotate a list by N places.
        Type Parameters:
        T - The list member type.
        Parameters:
        list - The List to rotate.
        n - The number of places to rotate by (positive or negative).
      • reverse

        public static <T> void reverse​(java.util.List<T> list)
        Reverse a list.
        Type Parameters:
        T - The list member type.
        Parameters:
        list - The List to reverse.
      • listEquals

        public static <T> boolean listEquals​(java.util.List<T> one,
                                             java.util.List<T> two)
        Check if two lists contents are equal but also checks for null.
        Type Parameters:
        T - The list member type.
        Parameters:
        one - First list to compare
        two - Second list to compare
        Returns:
        True if the list contents are all either both null or equal in the sense of their equals() method.
      • mapEntriesByKey

        public static <K extends java.lang.Comparable<? super K>,​V> java.util.List<java.util.Map.Entry<K,​V>> mapEntriesByKey​(java.util.Map<K,​V> map)
        Get the entries in a map in a sorted order.
        Type Parameters:
        K - The map key type.
        V - The map value type.
        Parameters:
        map - The Map to extract entries from.
        Returns:
        A list of entries from the map sorted by key.
      • mapEntriesByKey

        public static <K,​V> java.util.List<java.util.Map.Entry<K,​V>> mapEntriesByKey​(java.util.Map<K,​V> map,
                                                                                                 java.util.Comparator<K> comparator)
        Get the entries in a map in a sorted order.
        Type Parameters:
        K - The map key type.
        V - The map value type.
        Parameters:
        map - The Map to extract entries from.
        comparator - A Comparator for the values.
        Returns:
        A list of entries from the map sorted by key.
      • mapEntriesByValue

        public static <K,​V extends java.lang.Comparable<? super V>> java.util.List<java.util.Map.Entry<K,​V>> mapEntriesByValue​(java.util.Map<K,​V> map)
        Get the entries in a map in a sorted order.
        Type Parameters:
        K - The map key type.
        V - The map value type.
        Parameters:
        map - The Map to extract entries from.
        Returns:
        A list of entries from the map sorted by key.
      • mapEntriesByValue

        public static <K,​V> java.util.List<java.util.Map.Entry<K,​V>> mapEntriesByValue​(java.util.Map<K,​V> map,
                                                                                                   java.util.Comparator<V> comparator)
        Get the entries in a map in a sorted order.
        Type Parameters:
        K - The map key type.
        V - The map value type.
        Parameters:
        map - The Map to extract entries from.
        comparator - A Comparator for the values.
        Returns:
        A list of entries from the map sorted by value.
      • all

        public static <T> boolean all​(T[] array,
                                      java.util.function.Predicate<? super T> predicate)
        Do all members of an array match a predicate?
        Type Parameters:
        T - The array member type.
        Parameters:
        array - The array to test.
        predicate - The Predicate to test with.
        Returns:
        True if all members pass the predicate test.
      • all

        public static <T> boolean all​(java.util.Collection<T> c,
                                      java.util.function.Predicate<? super T> predicate)
        Do all members of an collection match a predicate?
        Type Parameters:
        T - The collection member type.
        Parameters:
        c - The Collection to test.
        predicate - The Predicate to test with.
        Returns:
        True if all members pass the predicate test.
      • all

        public static <T> boolean all​(java.util.stream.Stream<T> stream,
                                      java.util.function.Predicate<? super T> predicate)
        Do all members of an stream match a predicate?
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - The Stream to test.
        predicate - The Predicate to test with.
        Returns:
        True if all members pass the predicate test.
      • all_internal

        private static <T> boolean all_internal​(java.util.stream.Stream<T> stream,
                                                java.util.function.Predicate<? super T> predicate)
        Implementation of all().
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - The Stream to test.
        predicate - The Predicate to test with.
        Returns:
        True if all members pass the predicate test.
      • alwaysTrue

        public static <T> java.util.function.Predicate<T> alwaysTrue()
        Helper to create a predicate which is always true.
        Type Parameters:
        T - The stream member type.
        Returns:
        The always valid predicate for the stream type.
      • any

        public static <T> boolean any​(T[] array)
        Is an array non-empty?
        Type Parameters:
        T - The array member type.
        Parameters:
        array - The array to test.
        Returns:
        True if the array is non-empty.
      • any

        public static <T> boolean any​(T[] array,
                                      java.util.function.Predicate<? super T> predicate)
        Does any member of an array match a predicate?
        Type Parameters:
        T - The array member type.
        Parameters:
        array - The array to test.
        predicate - The Predicate to test with.
        Returns:
        True if any member passes the predicate test.
      • any

        public static <T> boolean any​(java.util.Collection<T> c)
        Is a collection non-empty?
        Type Parameters:
        T - The collection member type.
        Parameters:
        c - The Collection to test.
        Returns:
        True if the collection is non-empty.
      • any

        public static <T> boolean any​(java.util.Collection<T> c,
                                      java.util.function.Predicate<? super T> predicate)
        Does any member of a collection match a predicate?
        Type Parameters:
        T - The collection member type.
        Parameters:
        c - The Collection to test.
        predicate - The Predicate to test with.
        Returns:
        True if any member passes the predicate test.
      • any

        public static <T> boolean any​(java.util.stream.Stream<T> stream)
        Is a stream non-empty?
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - The Stream to test.
        Returns:
        True if the stream is non-empty.
      • any

        public static <T> boolean any​(java.util.stream.Stream<T> stream,
                                      java.util.function.Predicate<? super T> predicate)
        Does any member of a stream match a predicate?
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - The Stream to test.
        predicate - The Predicate to test with.
        Returns:
        True if any member passes the predicate test.
      • any_internal

        private static <T> boolean any_internal​(java.util.stream.Stream<T> stream,
                                                java.util.function.Predicate<? super T> predicate)
        Implementation of any().
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - The Stream to test.
        predicate - The Predicate to test with.
        Returns:
        True if any member passes the predicate test.
      • cacheInt

        public static <T> java.util.function.ToIntFunction<T> cacheInt​(java.util.function.Function<T,​java.lang.Integer> f)
        Helper to create a caching ToIntFunction.
        Type Parameters:
        T - The argument type to be converted to int.
        Parameters:
        f - The integer valued function to cache.
        Returns:
        A caching ToIntFunction.
      • cachingIntComparator

        public static <T> java.util.Comparator<T> cachingIntComparator​(java.util.function.Function<T,​java.lang.Integer> f)
        Helper to create a caching comparator.
        Type Parameters:
        T - The argument type to be converted to int.
        Parameters:
        f - The integer valued function to use in comparison.
        Returns:
        A caching Comparator.
      • cacheDouble

        public static <T> java.util.function.ToDoubleFunction<T> cacheDouble​(java.util.function.Function<T,​java.lang.Double> f)
        Helper to create a caching ToDoubleFunction.
        Type Parameters:
        T - The argument type to be converted to double.
        Parameters:
        f - The double valued function to cache.
        Returns:
        A caching ToDoubleFunction.
      • cachingDoubleComparator

        public static <T> java.util.Comparator<T> cachingDoubleComparator​(java.util.function.Function<T,​java.lang.Double> f)
        Helper to create a caching comparator.
        Type Parameters:
        T - The argument type to be converted to double.
        Parameters:
        f - The double valued function to use in comparison.
        Returns:
        A caching Comparator.
      • concat

        @SafeVarargs
        public static <T> java.util.stream.Stream<T> concat​(java.util.stream.Stream<T> s0,
                                                            java.util.stream.Stream<T>... streams)
        Concatenate streams.
        Type Parameters:
        T - Generic type of Stream
        Parameters:
        s0 - The first Stream.
        streams - The Streams to concatenate (nulls ignored).
        Returns:
        The concatenated stream.
      • count

        public static <T> int count​(T[] array)
        Count the number of members of an array.
        Type Parameters:
        T - The array member type.
        Parameters:
        array - The array to check.
        Returns:
        The number of items that matched.
      • count

        public static <T> int count​(T[] array,
                                    java.util.function.Predicate<? super T> predicate)
        Count the number of members of an array that match a predicate.
        Type Parameters:
        T - The array member type.
        Parameters:
        array - The array to check.
        predicate - A Predicate to test with.
        Returns:
        The number of items that matched.
      • count

        public static <T> int count​(java.util.Collection<T> c)
        Count the number of members of a collection that match a predicate.
        Type Parameters:
        T - The collection member type.
        Parameters:
        c - The Collection to check.
        Returns:
        The number of items that matched.
      • count

        public static <T> int count​(java.util.Collection<T> c,
                                    java.util.function.Predicate<? super T> predicate)
        Count the number of members of a collection that match a predicate.
        Type Parameters:
        T - The collection member type.
        Parameters:
        c - The Collection to check.
        predicate - A Predicate to test with.
        Returns:
        The number of items that matched.
      • count

        public static <T> int count​(java.util.stream.Stream<T> stream)
        Count the number of members of a stream.
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - The Stream to check.
        Returns:
        The number of items that matched.
      • count

        public static <T> int count​(java.util.stream.Stream<T> stream,
                                    java.util.function.Predicate<? super T> predicate)
        Count the number of members of a stream that match a predicate.
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - The Stream to check.
        predicate - A Predicate to test with.
        Returns:
        The number of items that matched.
      • count_internal

        private static <T> int count_internal​(java.util.stream.Stream<T> stream,
                                              java.util.function.Predicate<? super T> predicate)
        Implement count().
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - The Stream to check.
        predicate - A Predicate to test with.
        Returns:
        The number of items that matched.
      • dump

        public static <T> void dump​(java.lang.String header,
                                    T[] array)
        Dump an array to System.err.
        Type Parameters:
        T - The collection to dump
        Parameters:
        header - Optional informational string to print first.
        array - The array to dump.
      • dump

        public static void dump​(java.lang.String header,
                                java.util.Collection<?> c)
        Dump a collection to System.err.
        Parameters:
        header - Optional informational string to print first.
        c - The Collection to print.
      • dump

        public static void dump​(java.lang.String header,
                                java.util.stream.Stream<?> stream)
        Dump a stream to System.err.
        Parameters:
        header - Optional informational string to print first.
        stream - The Stream to print.
      • dump_internal

        private static void dump_internal​(java.lang.String header,
                                          java.util.stream.Stream<?> stream)
        Implement dump().
        Parameters:
        header - Optional informational string to print first.
        stream - The Stream to print.
      • dump

        public static void dump​(java.lang.String header,
                                java.util.Map<?,​?> map)
        Dump a map to System.err.
        Parameters:
        header - Optional informational string to print first.
        map - The Map to print.
      • fileStream

        public static java.util.stream.Stream<java.io.File> fileStream​(java.io.File dir)
        Create a stream of files from a directory.
        Parameters:
        dir - The File that hopefully is a directory.
        Returns:
        A stream of Files.
      • fileStream

        public static java.util.stream.Stream<java.io.File> fileStream​(java.io.File dir,
                                                                       java.util.function.Predicate<? super java.io.File> predicate)
        Create a stream of files from a directory, that each match a predicate.
        Parameters:
        dir - The File that hopefully is a directory.
        predicate - The Predicate to match with.
        Returns:
        A stream of matching Files.
      • find

        public static <T> T find​(T[] array,
                                 java.util.function.Predicate<? super T> predicate)
        Simple stream search for the first item that matches a predicate.
        Type Parameters:
        T - The array member type.
        Parameters:
        array - The array to search.
        predicate - A Predicate to match with.
        Returns:
        The item found, or null if not found.
      • find

        public static <T> T find​(T[] array,
                                 java.util.function.Predicate<? super T> predicate,
                                 T fail)
        Simple stream search for the first item that matches a predicate.
        Type Parameters:
        T - The array member type.
        Parameters:
        array - The array to search.
        predicate - A Predicate to match with.
        fail - The result to return on failure.
        Returns:
        The item found, or fail if not found.
      • find

        public static <T> T find​(java.util.Collection<T> c,
                                 java.util.function.Predicate<? super T> predicate)
        Simple stream search for the first item that matches a predicate.
        Type Parameters:
        T - The collection member type.
        Parameters:
        c - The Collection to search.
        predicate - A Predicate to match with.
        Returns:
        The item found, or null if not found.
      • find

        public static <T> T find​(java.util.Collection<T> c,
                                 java.util.function.Predicate<? super T> predicate,
                                 T fail)
        Simple stream search for the first item that matches a predicate.
        Type Parameters:
        T - The collection member type.
        Parameters:
        c - The Collection to search.
        predicate - A Predicate to match with.
        fail - The value to return if nothing is found.
        Returns:
        The item found, or fail if not found.
      • find

        public static <T> T find​(java.util.stream.Stream<T> stream,
                                 java.util.function.Predicate<? super T> predicate)
        Simple stream search for the first item that matches a predicate.
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - A Stream to search.
        predicate - A Predicate to match with.
        Returns:
        The item found, or null if not found.
      • find

        public static <T> T find​(java.util.stream.Stream<T> stream,
                                 java.util.function.Predicate<? super T> predicate,
                                 T fail)
        Simple stream search for the first item that matches a predicate.
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - A Stream to search.
        predicate - A Predicate to match with.
        fail - The value to return if nothing is found.
        Returns:
        The item found, or fail if not found.
      • find_internal

        private static <T> T find_internal​(java.util.stream.Stream<T> stream,
                                           java.util.function.Predicate<? super T> predicate,
                                           T fail)
        Implement find().
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - A Stream to search.
        predicate - A Predicate to match with.
        fail - The value to return if nothing is found.
        Returns:
        The item found, or fail if not found.
      • first

        public static <T> T first​(T[] array)
        Get the first item of an array.
        Type Parameters:
        T - The array member type.
        Parameters:
        array - The Collection to search.
        Returns:
        The first item, or null on failure.
      • first

        public static <T> T first​(java.util.Collection<T> c)
        Get the first item of a collection.
        Type Parameters:
        T - Generic type T
        Parameters:
        c - The Collection to search.
        Returns:
        The first item, or null on failure.
      • first

        public static <T> T first​(java.util.stream.Stream<T> stream)
        Get the first item of a stream.
        Type Parameters:
        T - Generic type T
        Parameters:
        stream - The Stream to search.
        Returns:
        The first item, or null on failure.
      • first_internal

        private static <T> T first_internal​(java.util.stream.Stream<T> stream,
                                            T fail)
        Implement first().
        Type Parameters:
        T - Generic type T
        Parameters:
        stream - The Stream to search.
        fail - The value to return on failure.
        Returns:
        The first item, or fail on failure.
      • flatten

        public static <T,​R> java.util.stream.Stream<R> flatten​(T[] array,
                                                                     java.util.function.Function<? super T,​? extends java.util.stream.Stream<? extends R>> mapper)
        Flatten an array into a stream derived from its component streams.
        Type Parameters:
        T - The array member type.
        R - The resulting stream member type.
        Parameters:
        array - The array to flatten.
        mapper - A mapping Function to apply.
        Returns:
        A stream of the mapped collection.
      • flatten

        public static <T,​R> java.util.stream.Stream<R> flatten​(T[] array,
                                                                     java.util.function.Predicate<? super T> predicate,
                                                                     java.util.function.Function<? super T,​? extends java.util.stream.Stream<? extends R>> mapper)
        Flatten an array into a stream derived from its component streams.
        Type Parameters:
        T - The array member type.
        R - The resulting stream member type.
        Parameters:
        array - The array to flatten.
        predicate - A Predicate to filter the collection with.
        mapper - A mapping Function to apply.
        Returns:
        A stream of the mapped collection.
      • flatten

        public static <T,​R> java.util.stream.Stream<R> flatten​(java.util.Collection<T> c,
                                                                     java.util.function.Function<? super T,​? extends java.util.stream.Stream<? extends R>> mapper)
        Flatten a collection into a stream derived from its component streams.
        Type Parameters:
        T - The collection member type.
        R - The resulting stream member type.
        Parameters:
        c - The Collection to flatten.
        mapper - A mapping Function to apply.
        Returns:
        A stream of the mapped collection.
      • flatten

        public static <T,​R> java.util.stream.Stream<R> flatten​(java.util.Collection<T> c,
                                                                     java.util.function.Predicate<? super T> predicate,
                                                                     java.util.function.Function<? super T,​? extends java.util.stream.Stream<? extends R>> mapper)
        Flatten a collection into a stream derived from its component streams.
        Type Parameters:
        T - The collection member type.
        R - The resulting stream member type.
        Parameters:
        c - The Collection to flatten.
        predicate - A Predicate to filter the collection with.
        mapper - A mapping Function to apply.
        Returns:
        A stream of the mapped collection.
      • flatten

        public static <T,​R> java.util.stream.Stream<R> flatten​(java.util.stream.Stream<T> stream,
                                                                     java.util.function.Function<? super T,​? extends java.util.stream.Stream<? extends R>> mapper)
        Flatten the members of a stream.
        Type Parameters:
        T - The stream member type.
        R - The resulting stream member type.
        Parameters:
        stream - The Stream to flatten.
        mapper - A mapping Function to apply.
        Returns:
        A stream of the mapped stream.
      • flatten

        public static <T,​R> java.util.stream.Stream<R> flatten​(java.util.stream.Stream<T> stream,
                                                                     java.util.function.Predicate<? super T> predicate,
                                                                     java.util.function.Function<? super T,​? extends java.util.stream.Stream<? extends R>> mapper)
        Flatten the members of a stream.
        Type Parameters:
        T - The stream member type.
        R - The resulting stream member type.
        Parameters:
        stream - The Stream to flatten.
        predicate - A Predicate to filter the collection with.
        mapper - A mapping Function to apply.
        Returns:
        A stream of the mapped stream.
      • flatten_internal

        private static <T,​R> java.util.stream.Stream<R> flatten_internal​(java.util.stream.Stream<T> stream,
                                                                               java.util.function.Predicate<? super T> predicate,
                                                                               java.util.function.Function<? super T,​? extends java.util.stream.Stream<? extends R>> mapper)
        Flatten the members of a stream.
        Type Parameters:
        T - The stream member type.
        R - The resulting stream member type.
        Parameters:
        stream - The Stream to flatten.
        predicate - A Predicate to filter the collection with.
        mapper - A mapping Function to apply.
        Returns:
        A stream of the mapped stream.
      • forEachMapEntry

        public static <K,​V> void forEachMapEntry​(java.util.Map<K,​V> map,
                                                       java.util.function.Consumer<java.util.Map.Entry<K,​V>> consumer)
        Apply a consumer to the entries of a map.
        Type Parameters:
        K - The map key type.
        V - The map value type.
        Parameters:
        map - The Map to apply to.
        consumer - A Consumer to apply.
      • forEachMapEntry

        public static <K,​V> void forEachMapEntry​(java.util.Map<K,​V> map,
                                                       java.util.function.Predicate<java.util.Map.Entry<K,​V>> predicate,
                                                       java.util.function.Consumer<java.util.Map.Entry<K,​V>> consumer)
        Apply a consumer to the entries of a map that match a predicate.
        Type Parameters:
        K - The map key type.
        V - The map value type.
        Parameters:
        map - The Map to apply to.
        predicate - The Predicate to match.
        consumer - A Consumer to apply.
      • forEach

        public static <T> void forEach​(T[] array,
                                       java.util.function.Consumer<? super T> consumer)
        Apply a consumer to the members of an array.
        Type Parameters:
        T - The array member type.
        Parameters:
        array - The array to apply to.
        consumer - A Consumer to apply.
      • forEach

        public static <T> void forEach​(T[] array,
                                       java.util.function.Predicate<? super T> predicate,
                                       java.util.function.Consumer<? super T> consumer)
        Apply a consumer to the members of an array that match a predicate.
        Type Parameters:
        T - The array member type.
        Parameters:
        array - The array to apply to.
        predicate - A Predicate to gate the application.
        consumer - A Consumer to apply.
      • forEach

        public static <T> void forEach​(java.util.Collection<T> c,
                                       java.util.function.Consumer<? super T> consumer)
        Apply a consumer to the members of a collection.
        Type Parameters:
        T - The collection member type.
        Parameters:
        c - The Collection to apply to.
        consumer - A Consumer to apply.
      • forEach

        public static <T> void forEach​(java.util.Collection<T> c,
                                       java.util.function.Predicate<? super T> predicate,
                                       java.util.function.Consumer<? super T> consumer)
        Apply a consumer to the members of a collection that match a predicate.
        Type Parameters:
        T - The collection member type.
        Parameters:
        c - The Collection to apply to.
        predicate - A Predicate to gate the application.
        consumer - A Consumer to apply.
      • forEach

        public static <T> void forEach​(java.util.stream.Stream<T> stream,
                                       java.util.function.Consumer<? super T> consumer)
        Apply a consumer to the members of a stream.
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - The Stream to apply to.
        consumer - A Consumer to apply.
      • forEach

        public static <T> void forEach​(java.util.stream.Stream<T> stream,
                                       java.util.function.Predicate<? super T> predicate,
                                       java.util.function.Consumer<? super T> consumer)
        Apply a consumer to the members of a stream that match a predicate.
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - The Stream to apply to.
        predicate - A Predicate to gate the application.
        consumer - A Consumer to apply.
      • forEach_internal

        private static <T> void forEach_internal​(java.util.stream.Stream<T> stream,
                                                 java.util.function.Predicate<? super T> predicate,
                                                 java.util.function.Consumer<? super T> consumer)
        Implement forEach.
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - The Stream to apply to.
        predicate - A Predicate to gate the application.
        consumer - A Consumer to apply.
      • isNotNull

        public static <T> java.util.function.Predicate<T> isNotNull()
        Create a predicate for a type that returns true if the argument is not null.
        Type Parameters:
        T - The input type.
        Returns:
        A suitable Predicate.
      • isNotNull

        public static <T,​V> java.util.function.Predicate<T> isNotNull​(java.util.function.Function<? super T,​V> mapper)
        Create a predicate for a type that returns true if the argument is not null.
        Type Parameters:
        T - The input type.
        V - A type to transform to.
        Parameters:
        mapper - A function to transform the input type.
        Returns:
        A suitable Predicate.
      • isNull

        public static <T> java.util.function.Predicate<T> isNull()
        Create a predicate for a type that returns true if the argument is null.
        Type Parameters:
        T - The input type.
        Returns:
        A suitable Predicate.
      • isNull

        public static <T,​V> java.util.function.Predicate<T> isNull​(java.util.function.Function<? super T,​V> mapper)
        Create a predicate for a type that returns true if the argument is not null.
        Type Parameters:
        T - The input type.
        V - A type to transform to.
        Parameters:
        mapper - A function to transform the input type.
        Returns:
        A suitable Predicate.
      • iterable

        public static <T> java.lang.Iterable<T> iterable​(java.util.stream.Stream<T> stream)
        Convenience function to convert a stream to an iterable.
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - The Stream to convert.
        Returns:
        The suitable Iterable.
      • map

        public static <T,​R> java.util.stream.Stream<R> map​(T[] array,
                                                                 java.util.function.Function<? super T,​? extends R> mapper)
        Create a stream from an array and an immediate mapping transform.
        Type Parameters:
        T - The array member type.
        R - The resulting stream member type.
        Parameters:
        array - The array to search.
        mapper - A mapping Function to apply.
        Returns:
        The resulting Stream.
      • map

        public static <T,​R> java.util.stream.Stream<R> map​(java.util.Collection<T> c,
                                                                 java.util.function.Function<? super T,​? extends R> mapper)
        Create a stream from a collection and an immediate mapping transform.
        Type Parameters:
        T - The collection member type.
        R - The resulting stream member type.
        Parameters:
        c - The Collection to search.
        mapper - A mapping Function to apply.
        Returns:
        The resulting Stream.
      • map

        public static <T,​R> java.util.stream.Stream<R> map​(java.util.stream.Stream<T> stream,
                                                                 java.util.function.Function<? super T,​? extends R> mapper)
        Apply a mapping to a stream.
        Type Parameters:
        T - Generic type T
        R - Generic type R
        Parameters:
        stream - The Stream to map.
        mapper - A mapping Function to apply.
        Returns:
        The resulting Stream.
      • map_internal

        private static <T,​R> java.util.stream.Stream<R> map_internal​(java.util.stream.Stream<T> stream,
                                                                           java.util.function.Function<? super T,​? extends R> mapper)
        Implement map.
        Type Parameters:
        T - Generic type T
        R - Generic type R
        Parameters:
        stream - The Stream to map.
        mapper - A mapping Function to apply.
        Returns:
        The resulting Stream.
      • matchKey

        public static <T> java.util.function.Predicate<T> matchKey​(T key)
        Create a predicate for a type that returns true if it equals a key.
        Type Parameters:
        T - The input type.
        Parameters:
        key - The key to match.
        Returns:
        A suitable Predicate.
      • matchKeyEquals

        public static <T> java.util.function.Predicate<T> matchKeyEquals​(T key)
        Create a predicate for a type that returns true if it equals a key in the sense of "equals".
        Type Parameters:
        T - The input type.
        Parameters:
        key - The key to match.
        Returns:
        A suitable Predicate.
      • matchKey

        public static <T,​K> java.util.function.Predicate<T> matchKey​(K key,
                                                                           java.util.function.Function<T,​K> mapper)
        Create a predicate for a type that returns true if a mapper applied to it causes it to equal a key.
        Type Parameters:
        T - The input type.
        K - The key type.
        Parameters:
        key - The key to match.
        mapper - The mapper Function to apply.
        Returns:
        A suitable Predicate.
      • matchKeyEquals

        public static <T,​K> java.util.function.Predicate<T> matchKeyEquals​(K key,
                                                                                 java.util.function.Function<T,​K> mapper)
        Create a predicate for a type that returns true if a mapper applied to it causes it to equal a key.
        Type Parameters:
        T - The input type.
        K - The key type.
        Parameters:
        key - The key to match.
        mapper - The mapper Function to apply.
        Returns:
        A suitable Predicate.
      • max

        public static <T> int max​(T[] array,
                                  java.util.function.ToIntFunction<T> tif)
        Find the maximum int value in an array.
        Type Parameters:
        T - The collection member type.
        Parameters:
        array - The array to check.
        tif - A ToIntFunction to map the stream to int with.
        Returns:
        The maximum value found, or zero if the input is empty.
      • max

        public static <T> int max​(T[] array,
                                  java.util.function.Predicate<? super T> predicate,
                                  java.util.function.ToIntFunction<T> tif)
        Find the maximum int value in an array.
        Type Parameters:
        T - The collection member type.
        Parameters:
        array - The array to check.
        predicate - A Predicate to match with.
        tif - A ToIntFunction to map the stream to int with.
        Returns:
        The maximum value found, or zero if the input is empty.
      • max

        public static <T> int max​(java.util.Collection<T> c,
                                  java.util.function.ToIntFunction<T> tif)
        Find the maximum int value in a collection.
        Type Parameters:
        T - The collection member type.
        Parameters:
        c - The Collection to check.
        tif - A ToIntFunction to map the stream to int with.
        Returns:
        The maximum value found, or zero if the input is empty.
      • max

        public static <T> int max​(java.util.Collection<T> c,
                                  java.util.function.Predicate<? super T> predicate,
                                  java.util.function.ToIntFunction<T> tif)
        Find the maximum int value in a collection.
        Type Parameters:
        T - The collection member type.
        Parameters:
        c - The Collection to check.
        predicate - A Predicate to match with.
        tif - A ToIntFunction to map the stream to int with.
        Returns:
        The maximum value found, or zero if the input is empty.
      • max

        public static <T> int max​(java.util.stream.Stream<T> stream,
                                  java.util.function.ToIntFunction<T> tif)
        Find the maximum int value in a stream.
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - The Stream to check.
        tif - A ToIntFunction to map the stream to int with.
        Returns:
        The maximum value found, or zero if the input is empty.
      • max

        public static <T> int max​(java.util.stream.Stream<T> stream,
                                  java.util.function.Predicate<? super T> predicate,
                                  java.util.function.ToIntFunction<T> tif)
        Find the maximum int value in a stream.
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - The Stream to check.
        predicate - A Predicate to match with.
        tif - A ToIntFunction to map the stream to int with.
        Returns:
        The maximum value found, or zero if the input is empty.
      • max_internal

        private static <T> int max_internal​(java.util.stream.Stream<T> stream,
                                            java.util.function.Predicate<? super T> predicate,
                                            java.util.function.ToIntFunction<T> tif)
        Implement max.
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - The Stream to check.
        predicate - A Predicate to match with.
        tif - A ToIntFunction to map the stream to int with.
        Returns:
        The maximum value found, or zero if the input is empty.
      • maximize

        public static <T> T maximize​(T[] array,
                                     java.util.Comparator<? super T> comparator)
        Find the selected member of an array that maximizes according to a given comparison.
        Type Parameters:
        T - The collection member type.
        Parameters:
        array - The array to maximize from.
        comparator - A Comparator to compare with.
        Returns:
        The maximal value found, or null if none present.
      • maximize

        public static <T> T maximize​(T[] array,
                                     java.util.function.Predicate<? super T> predicate,
                                     java.util.Comparator<? super T> comparator)
        Find the selected member of a collection that maximizes according to a given comparison.
        Type Parameters:
        T - The collection member type.
        Parameters:
        array - The array to maximize from.
        predicate - A Predicate to match with.
        comparator - A Comparator to compare with.
        Returns:
        The maximal value found, or null if none present.
      • maximize

        public static <T> T maximize​(java.util.Collection<T> c,
                                     java.util.Comparator<? super T> comparator)
        Find the selected member of a collection that maximizes according to a given comparison.
        Type Parameters:
        T - The collection member type.
        Parameters:
        c - The Collection to maximize from.
        comparator - A Comparator to compare with.
        Returns:
        The maximal value found, or null if none present.
      • maximize

        public static <T> T maximize​(java.util.Collection<T> c,
                                     java.util.function.Predicate<? super T> predicate,
                                     java.util.Comparator<? super T> comparator)
        Find the selected member of a collection that maximizes according to a given comparison.
        Type Parameters:
        T - The collection member type.
        Parameters:
        c - The Collection to maximize from.
        predicate - A Predicate to match with.
        comparator - A Comparator to compare with.
        Returns:
        The maximal value found, or null if none present.
      • maximize

        public static <T> T maximize​(java.util.stream.Stream<T> stream,
                                     java.util.Comparator<? super T> comparator)
        Find the selected member of a stream that maximizes according to a given comparison.
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - The Stream to maximize from.
        comparator - A Comparator to compare with.
        Returns:
        The maximal value found, or null if none present.
      • maximize

        public static <T> T maximize​(java.util.stream.Stream<T> stream,
                                     java.util.function.Predicate<? super T> predicate,
                                     java.util.Comparator<? super T> comparator)
        Find the selected member of a stream that maximizes according to a given comparison.
        Type Parameters:
        T - The collection member type.
        Parameters:
        stream - The Stream to maximize from.
        predicate - A Predicate to match with.
        comparator - A Comparator to compare with.
        Returns:
        The maximal value found, or null if none present.
      • maximize_internal

        private static <T> T maximize_internal​(java.util.stream.Stream<T> stream,
                                               java.util.function.Predicate<? super T> predicate,
                                               java.util.Comparator<? super T> comparator)
        Implement maximize.
        Type Parameters:
        T - The collection member type.
        Parameters:
        stream - The Stream to maximize from.
        predicate - A Predicate to match with.
        comparator - A Comparator to compare with.
        Returns:
        The maximal value found, or null if none present.
      • min

        public static <T> int min​(T[] array,
                                  java.util.function.ToIntFunction<T> tif)
        Find the minimum int value in an array.
        Type Parameters:
        T - The collection member type.
        Parameters:
        array - The array to minimize from.
        tif - A ToIntFunction to map the stream to int with.
        Returns:
        The minimum value found, or zero if the input is empty.
      • min

        public static <T> int min​(T[] array,
                                  java.util.function.Predicate<? super T> predicate,
                                  java.util.function.ToIntFunction<T> tif)
        Find the minimum int value in an array.
        Type Parameters:
        T - The collection member type.
        Parameters:
        array - The array to minimize from.
        predicate - A Predicate to match with.
        tif - A ToIntFunction to map the stream to int with.
        Returns:
        The minimum value found, or zero if the input is empty.
      • min

        public static <T> int min​(java.util.Collection<T> c,
                                  java.util.function.ToIntFunction<T> tif)
        Find the minimum int value in a collection.
        Type Parameters:
        T - The collection member type.
        Parameters:
        c - The Collection to check.
        tif - A ToIntFunction to map the stream to int with.
        Returns:
        The minimum value found, or zero if the input is empty.
      • min

        public static <T> int min​(java.util.Collection<T> c,
                                  java.util.function.Predicate<? super T> predicate,
                                  java.util.function.ToIntFunction<T> tif)
        Find the minimum int value in a collection.
        Type Parameters:
        T - The collection member type.
        Parameters:
        c - The Collection to check.
        predicate - A Predicate to match with.
        tif - A ToIntFunction to map the stream to int with.
        Returns:
        The minimum value found, or zero if the input is empty.
      • min

        public static <T> int min​(java.util.stream.Stream<T> stream,
                                  java.util.function.ToIntFunction<T> tif)
        Find the minimum int value in a stream.
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - The Stream to check.
        tif - A ToIntFunction to map the stream to int with.
        Returns:
        The minimum value found, or zero if the input is empty.
      • min

        public static <T> int min​(java.util.stream.Stream<T> stream,
                                  java.util.function.Predicate<? super T> predicate,
                                  java.util.function.ToIntFunction<T> tif)
        Find the minimum int value in a stream.
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - The Stream to check.
        predicate - A Predicate to match with.
        tif - A ToIntFunction to map the stream to int with.
        Returns:
        The minimum value found, or zero if the input is empty.
      • min_internal

        private static <T> int min_internal​(java.util.stream.Stream<T> stream,
                                            java.util.function.Predicate<? super T> predicate,
                                            java.util.function.ToIntFunction<T> tif)
        Implement min.
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - The Stream to check.
        predicate - A Predicate to match with.
        tif - A ToIntFunction to map the stream to int with.
        Returns:
        The minimum value found, or zero if the input is empty.
      • minimize

        public static <T> T minimize​(T[] array,
                                     java.util.Comparator<? super T> comparator)
        Find the selected member of an array that minimizes according to a given comparison.
        Type Parameters:
        T - The collection member type.
        Parameters:
        array - The array to minimize from.
        comparator - A Comparator to compare with.
        Returns:
        The minimal value found, or null if none present.
      • minimize

        public static <T> T minimize​(T[] array,
                                     java.util.function.Predicate<? super T> predicate,
                                     java.util.Comparator<? super T> comparator)
        Find the selected member of a collection that minimizes according to a given comparison.
        Type Parameters:
        T - The collection member type.
        Parameters:
        array - The array to minimize from.
        predicate - A Predicate to match with.
        comparator - A Comparator to compare with.
        Returns:
        The minimal value found, or null if none present.
      • minimize

        public static <T> T minimize​(java.util.Collection<T> c,
                                     java.util.Comparator<? super T> comparator)
        Find the selected member of a collection that minimizes according to a given comparison.
        Type Parameters:
        T - The collection member type.
        Parameters:
        c - The Collection to minimize from.
        comparator - A Comparator to compare with.
        Returns:
        The minimal value found, or null if none present.
      • minimize

        public static <T> T minimize​(java.util.Collection<T> c,
                                     java.util.function.Predicate<? super T> predicate,
                                     java.util.Comparator<? super T> comparator)
        Find the selected member of a collection that minimizes according to a given comparison.
        Type Parameters:
        T - The collection member type.
        Parameters:
        c - The Collection to minimize from.
        predicate - A Predicate to match with.
        comparator - A Comparator to compare with.
        Returns:
        The minimal value found, or null if none present.
      • minimize

        public static <T> T minimize​(java.util.stream.Stream<T> stream,
                                     java.util.Comparator<? super T> comparator)
        Find the selected member of a stream that minimizes according to a given comparison.
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - The Stream to minimize from.
        comparator - A Comparator to compare with.
        Returns:
        The minimal value found, or null if none present.
      • minimize

        public static <T> T minimize​(java.util.stream.Stream<T> stream,
                                     java.util.function.Predicate<? super T> predicate,
                                     java.util.Comparator<? super T> comparator)
        Find the selected member of a stream that minimizes according to a given comparison.
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - The Stream to minimize from.
        predicate - A Predicate to match with.
        comparator - A Comparator to compare with.
        Returns:
        The minimal value found, or null if none present.
      • minimize_internal

        private static <T> T minimize_internal​(java.util.stream.Stream<T> stream,
                                               java.util.function.Predicate<? super T> predicate,
                                               java.util.Comparator<? super T> comparator)
        Implement minimize.
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - The Stream to minimize from.
        predicate - A Predicate to match with.
        comparator - A Comparator to compare with.
        Returns:
        The minimal value found, or null if none present.
      • none

        public static <T> boolean none​(T[] array)
        Is an array null or empty?
        Type Parameters:
        T - The array member type.
        Parameters:
        array - The array to test.
        Returns:
        True if an array is null or empty.
      • none

        public static <T> boolean none​(T[] array,
                                       java.util.function.Predicate<? super T> predicate)
        Do none of the members of an array match a predicate?
        Type Parameters:
        T - The array member type.
        Parameters:
        array - The array to test.
        predicate - The Predicate to test with.
        Returns:
        True if no member passes the predicate test.
      • none

        public static <T> boolean none​(java.util.Collection<T> c)
        Is a collection empty?
        Type Parameters:
        T - The collection member type.
        Parameters:
        c - The Collection to test.
        Returns:
        True if the collection is null or empty.
      • none

        public static <T> boolean none​(java.util.Collection<T> c,
                                       java.util.function.Predicate<? super T> predicate)
        Do none of the members of a collection match a predicate?
        Type Parameters:
        T - The collection member type.
        Parameters:
        c - The Collection to test.
        predicate - The Predicate to test with.
        Returns:
        True if no member passes the predicate test.
      • none

        public static <T> boolean none​(java.util.stream.Stream<T> stream)
        Is a stream null or empty?
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - The Stream to test.
        Returns:
        True if the stream is null or empty.
      • none

        public static <T> boolean none​(java.util.stream.Stream<T> stream,
                                       java.util.function.Predicate<? super T> predicate)
        Do none of the members of a stream match a predicate?
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - The Stream to test.
        predicate - The Predicate to test with.
        Returns:
        True if no member passes the predicate test.
      • none_internal

        private static <T> boolean none_internal​(java.util.stream.Stream<T> stream,
                                                 java.util.function.Predicate<? super T> predicate)
        Implementation of none().
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - The Stream to test.
        predicate - The Predicate to test with.
        Returns:
        True if no member passes the predicate test.
      • product

        public static <T> double product​(T[] array,
                                         java.util.function.ToDoubleFunction<T> tdf)
        Take the product of an array.
        Type Parameters:
        T - The array member type.
        Parameters:
        array - The array to multiply.
        tdf - A ToDoubleFunction to convert members to double.
        Returns:
        The product of the values found.
      • product

        public static <T> double product​(T[] array,
                                         java.util.function.Predicate<? super T> predicate,
                                         java.util.function.ToDoubleFunction<T> tdf)
        Take the product of an array.
        Type Parameters:
        T - The array member type.
        Parameters:
        array - The array to multiply.
        predicate - A Predicate to match with.
        tdf - A ToDoubleFunction to convert members to double.
        Returns:
        The product of the values found.
      • product

        public static <T> double product​(java.util.Collection<T> c,
                                         java.util.function.ToDoubleFunction<T> tdf)
        Take the product of a collection.
        Type Parameters:
        T - The stream member type.
        Parameters:
        c - The Collection to multiply.
        tdf - A ToDoubleFunction to convert members to double.
        Returns:
        The product of the values found.
      • product

        public static <T> double product​(java.util.Collection<T> c,
                                         java.util.function.Predicate<? super T> predicate,
                                         java.util.function.ToDoubleFunction<T> tdf)
        Take the product of a collection.
        Type Parameters:
        T - The stream member type.
        Parameters:
        c - The Collection to multiply.
        predicate - A Predicate to match with.
        tdf - A ToDoubleFunction to convert members to double.
        Returns:
        The product of the values found.
      • product

        public static <T> double product​(java.util.stream.Stream<T> stream,
                                         java.util.function.ToDoubleFunction<T> tdf)
        Take the product of the members of a stream.
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - The Stream to multiply.
        tdf - A ToDoubleFunction to convert members to double.
        Returns:
        The product of the values found.
      • product

        public static <T> double product​(java.util.stream.Stream<T> stream,
                                         java.util.function.Predicate<? super T> predicate,
                                         java.util.function.ToDoubleFunction<T> tdf)
        Take the product of the members of a stream.
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - The Stream to multiply.
        predicate - A Predicate to match with.
        tdf - A ToDoubleFunction to convert members to double.
        Returns:
        The product of the values found.
      • product_internal

        private static <T> double product_internal​(java.util.stream.Stream<T> stream,
                                                   java.util.function.Predicate<? super T> predicate,
                                                   java.util.function.ToDoubleFunction<T> tdf)
        Take the product of the members of a stream.
        Type Parameters:
        T - The stream member type.
        Parameters:
        predicate - A Predicate to match with.
        stream - The Stream to multiply.
        tdf - A ToDoubleFunction to convert members to double.
        Returns:
        The product of the values found.
      • removeInPlace

        public static <T> boolean removeInPlace​(java.util.Collection<T> c,
                                                java.util.function.Predicate<? super T> predicate)
        Special case to remove objects from a collection.
        Type Parameters:
        T - The collection member type.
        Parameters:
        c - The Collection to remove from.
        predicate - A Predicate to match with.
        Returns:
        True if anything was removed.
      • removeInPlace

        public static <K,​V> boolean removeInPlace​(java.util.Map<K,​V> map,
                                                        java.util.function.Predicate<java.util.Map.Entry<K,​V>> predicate)
        Special case to remove objects from a map.
        Type Parameters:
        K - The map key type.
        V - The map value type.
        Parameters:
        map - The Map to remove entries from.
        predicate - A Predicate to match map entries with.
        Returns:
        True if anything was removed.
      • sort

        public static <T extends java.lang.Comparable<? super T>> java.util.List<T> sort​(T[] array)
        Convenience function to convert an array to a sorted list.
        Type Parameters:
        T - The array member type.
        Parameters:
        array - The array to convert.
        Returns:
        A list of the stream contents.
      • sort

        public static <T> java.util.List<T> sort​(T[] array,
                                                 java.util.Comparator<? super T> comparator)
        Convenience function to convert an array to a sorted list.
        Type Parameters:
        T - The array member type.
        Parameters:
        array - The array to convert.
        comparator - A Comparator to sort with.
        Returns:
        A list of the stream contents.
      • sort

        public static <T extends java.lang.Comparable<? super T>> java.util.List<T> sort​(java.util.Collection<T> c)
        Convenience function to convert a collection to a sorted list.
        Type Parameters:
        T - The collection member type.
        Parameters:
        c - The Collection to convert.
        Returns:
        A list of the stream contents.
      • sort

        public static <T> java.util.List<T> sort​(java.util.Collection<T> c,
                                                 java.util.Comparator<? super T> comparator)
        Convenience function to convert a collection to a map.
        Type Parameters:
        T - The collection member type.
        Parameters:
        c - The Collection to convert.
        comparator - A Comparator to sort with.
        Returns:
        A map of the stream contents.
      • sort

        public static <T extends java.lang.Comparable<? super T>> java.util.List<T> sort​(java.util.stream.Stream<T> stream)
        Convenience function to collect a stream to a list.
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - The Stream to collect.
        Returns:
        A list of the stream contents.
      • sort

        public static <T> java.util.List<T> sort​(java.util.stream.Stream<T> stream,
                                                 java.util.Comparator<? super T> comparator)
        Convenience function to collect a stream to a list.
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - The Stream to collect.
        comparator - A Comparator to sort with.
        Returns:
        A list of the stream contents.
      • sort_internal

        private static <T> java.util.List<T> sort_internal​(java.util.stream.Stream<T> stream,
                                                           java.util.Comparator<? super T> comparator)
        Implement sort.
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - The Stream to collect.
        comparator - A Comparator to sort with.
        Returns:
        A list of the stream contents.
      • sum

        public static <T> int sum​(T[] array,
                                  java.util.function.ToIntFunction<T> tif)
        Take the sum of the members of an array.
        Type Parameters:
        T - The collection member type.
        Parameters:
        array - The array to sum.
        tif - A ToIntFunction to convert members to an int.
        Returns:
        The sum of the values found.
      • sum

        public static <T> int sum​(T[] array,
                                  java.util.function.Predicate<? super T> predicate,
                                  java.util.function.ToIntFunction<T> tif)
        Take the sum of the members of an array.
        Type Parameters:
        T - The collection member type.
        Parameters:
        array - The array to sum.
        predicate - A Predicate to match with.
        tif - A ToIntFunction to convert members to an int.
        Returns:
        The sum of the values found.
      • sum

        public static <T> int sum​(java.util.Collection<T> c,
                                  java.util.function.ToIntFunction<T> tif)
        Take the sum of the members of a collection.
        Type Parameters:
        T - The collection member type.
        Parameters:
        c - The Collection to sum.
        tif - A ToIntFunction to convert members to an int.
        Returns:
        The sum of the values found.
      • sum

        public static <T> int sum​(java.util.Collection<T> c,
                                  java.util.function.Predicate<? super T> predicate,
                                  java.util.function.ToIntFunction<T> tif)
        Take the sum of the members of a collection.
        Type Parameters:
        T - The collection member type.
        Parameters:
        c - The Collection to sum.
        predicate - A Predicate to match with.
        tif - A ToIntFunction to map the stream to int with.
        Returns:
        The sum of the values found.
      • sum

        public static <T> int sum​(java.util.stream.Stream<T> stream,
                                  java.util.function.ToIntFunction<T> tif)
        Take the sum of the members of a stream.
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - The Stream to sum.
        tif - A ToIntFunction to convert members to an int.
        Returns:
        The sum of the values found.
      • sum

        public static <T> int sum​(java.util.stream.Stream<T> stream,
                                  java.util.function.Predicate<? super T> predicate,
                                  java.util.function.ToIntFunction<T> tif)
        Take the sum of the members of a stream.
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - The Stream to sum.
        predicate - A Predicate to match with.
        tif - A ToIntFunction to convert members to an int.
        Returns:
        The sum of the values found.
      • sum_internal

        private static <T> int sum_internal​(java.util.stream.Stream<T> stream,
                                            java.util.function.Predicate<? super T> predicate,
                                            java.util.function.ToIntFunction<T> tif)
        Take the sum of the members of a stream.
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - The Stream to sum.
        predicate - A Predicate to match with.
        tif - A ToIntFunction to convert members to an int.
        Returns:
        The sum of the values found.
      • sumDouble

        public static <T> double sumDouble​(T[] array,
                                           java.util.function.ToDoubleFunction<T> tdf)
        Take the sum of the members of an array.
        Type Parameters:
        T - The collection member type.
        Parameters:
        array - The array to sum.
        tdf - A ToDoubleFunction to convert members to a double.
        Returns:
        The sum of the values found.
      • sumDouble

        public static <T> double sumDouble​(T[] array,
                                           java.util.function.Predicate<? super T> predicate,
                                           java.util.function.ToDoubleFunction<T> tdf)
        Take the sum of the members of an array.
        Type Parameters:
        T - The collection member type.
        Parameters:
        array - The array to sum.
        predicate - A Predicate to match with.
        tdf - A ToDoubleFunction to map the stream to double with.
        Returns:
        The sum of the values found.
      • sumDouble

        public static <T> double sumDouble​(java.util.Collection<T> c,
                                           java.util.function.ToDoubleFunction<T> tdf)
        Take the sum of the members of a collection.
        Type Parameters:
        T - The collection member type.
        Parameters:
        c - The Collection to sum.
        tdf - A ToDoubleFunction to convert members to a double.
        Returns:
        The sum of the values found.
      • sumDouble

        public static <T> double sumDouble​(java.util.Collection<T> c,
                                           java.util.function.Predicate<? super T> predicate,
                                           java.util.function.ToDoubleFunction<T> tdf)
        Take the sum of the members of a collection.
        Type Parameters:
        T - The collection member type.
        Parameters:
        c - The Collection to sum.
        predicate - A Predicate to match with.
        tdf - A ToDoubleFunction to map the stream to double with.
        Returns:
        The sum of the values found.
      • sumDouble

        public static <T> double sumDouble​(java.util.stream.Stream<T> stream,
                                           java.util.function.ToDoubleFunction<T> tdf)
        Take the sum of the members of a stream.
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - The Stream to sum.
        tdf - A ToDoubleFunction to convert members to a double.
        Returns:
        The sum of the values found.
      • sumDouble

        public static <T> double sumDouble​(java.util.stream.Stream<T> stream,
                                           java.util.function.Predicate<? super T> predicate,
                                           java.util.function.ToDoubleFunction<T> tdf)
        Take the sum of the members of a stream.
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - The Stream to sum.
        predicate - A Predicate to select members.
        tdf - A ToIntFunction to convert members to a double.
        Returns:
        The sum of the values found.
      • sumDouble_internal

        private static <T> double sumDouble_internal​(java.util.stream.Stream<T> stream,
                                                     java.util.function.Predicate<? super T> predicate,
                                                     java.util.function.ToDoubleFunction<T> tdf)
        Take the sum of the members of a stream.
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - The Stream to sum.
        predicate - A Predicate to select members.
        tdf - A ToIntFunction to convert members to a double.
        Returns:
        The sum of the values found.
      • toAppendedList

        public static <T> java.util.stream.Collector<java.util.List<T>,​?,​java.util.List<T>> toAppendedList()
        Make a collector that takes lists and appends them.
        Type Parameters:
        T - The list member type.
        Returns:
        A list appending collector.
      • toList

        public static <T> java.util.List<T> toList​(T[] array)
        Convenience function to convert an array to a list.
        Type Parameters:
        T - The array member type.
        Parameters:
        array - The array to convert.
        Returns:
        A map of the stream contents.
      • toList

        public static <T> java.util.List<T> toList​(java.util.Collection<T> c)
        Convenience function to convert a collection to a list.
        Type Parameters:
        T - The collection member type.
        Parameters:
        c - The Collection to convert.
        Returns:
        A map of the stream contents.
      • toList

        public static <T> java.util.List<T> toList​(java.util.stream.Stream<T> stream)
        Convenience function to collect a stream to a list.
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - The Stream to collect.
        Returns:
        A list of the stream contents.
      • toList_internal

        private static <T> java.util.List<T> toList_internal​(java.util.stream.Stream<T> stream)
        Implement toList.
        Type Parameters:
        T - The stream member type.
        Parameters:
        stream - The Stream to collect.
        Returns:
        A list of the stream contents.
      • toListNoNulls

        public static <T> java.util.stream.Collector<T,​?,​java.util.List<T>> toListNoNulls()
        Create a new collector that accumulates to a list but excludes null members.
        Type Parameters:
        T - The stream member type.
        Returns:
        A list collectors.
      • toStream

        public static <T> java.util.stream.Stream<T> toStream​(java.util.Iterator<T> iterator)
        Convert an iterator to a stream.
        Type Parameters:
        T - A Stream
        Parameters:
        iterator - The Iterator to convert.
        Returns:
        The resulting Stream.
      • toStream

        public static <T> java.util.stream.Stream<T> toStream​(java.lang.Iterable<T> iterable)
        Convert an iterable to a stream.
        Type Parameters:
        T - A Stream
        Parameters:
        iterable - The Iterable to convert.
        Returns:
        The resulting Stream.
      • transform

        public static <T> java.util.List<T> transform​(T[] array,
                                                      java.util.function.Predicate<? super T> predicate)
        Transform the contents of an array.
        Type Parameters:
        T - The array member type.
        Parameters:
        array - The array to transform.
        predicate - A Predicate to select the items.
        Returns:
        The result of collecting the predicate matches.
      • transform

        public static <T,​R> java.util.List<R> transform​(T[] array,
                                                              java.util.function.Predicate<? super T> predicate,
                                                              java.util.function.Function<? super T,​? extends R> mapper)
        Transform the contents of an array.
        Type Parameters:
        T - The array member type.
        R - The resulting collection member type.
        Parameters:
        array - The array to transform.
        predicate - A Predicate to select the items.
        mapper - A function to transform the selected items.
        Returns:
        The result of collecting the mapped predicate matches.
      • transform

        public static <T,​R,​C> C transform​(T[] array,
                                                      java.util.function.Predicate<? super T> predicate,
                                                      java.util.function.Function<? super T,​? extends R> mapper,
                                                      java.util.stream.Collector<R,​?,​C> collector)
        Transform the contents of an array.
        Type Parameters:
        T - The array member type.
        R - The resulting collection member type.
        C - The resulting collection type.
        Parameters:
        array - The array to transform.
        predicate - A Predicate to select the items.
        mapper - A function to transform the selected items.
        collector - A Collector to collect the items.
        Returns:
        The result of collecting the mapped predicate matches.
      • transform

        public static <T,​R> java.util.List<R> transform​(T[] array,
                                                              java.util.function.Predicate<? super T> predicate,
                                                              java.util.function.Function<? super T,​? extends R> mapper,
                                                              java.util.Comparator<? super R> comparator)
        Transform the contents of an array and sort the result.
        Type Parameters:
        T - The array member type.
        R - The resulting collection member type.
        Parameters:
        array - The array to transform.
        predicate - A Predicate to select the items.
        mapper - A function to transform the selected items.
        comparator - A Comparator to sort the items.
        Returns:
        A list of sorted mapped predicate matches.
      • transform

        public static <T> java.util.List<T> transform​(java.util.Collection<T> c,
                                                      java.util.function.Predicate<? super T> predicate)
        Transform the contents of a collection.
        Type Parameters:
        T - The collection member type.
        Parameters:
        c - The Collection to transform.
        predicate - A Predicate to select the items.
        Returns:
        The result of collecting the predicate matches.
      • transform

        public static <T,​R> java.util.List<R> transform​(java.util.Collection<T> c,
                                                              java.util.function.Predicate<? super T> predicate,
                                                              java.util.function.Function<? super T,​? extends R> mapper)
        Transform the contents of a collection.
        Type Parameters:
        T - The collection member type.
        R - The resulting collection member type.
        Parameters:
        c - The Collection to transform.
        predicate - A Predicate to select the items.
        mapper - A function to transform the selected items.
        Returns:
        The result of collecting the mapped predicate matches.
      • transform

        public static <T,​R> java.util.List<R> transform​(java.util.Collection<T> c,
                                                              java.util.function.Predicate<? super T> predicate,
                                                              java.util.function.Function<? super T,​? extends R> mapper,
                                                              java.util.Comparator<? super R> comparator)
        Transform the contents of a collection and sort the result.
        Type Parameters:
        T - The collection member type.
        R - The resulting collection member type.
        Parameters:
        c - The Collection to transform.
        predicate - A Predicate to select the items.
        mapper - A function to transform the selected items.
        comparator - A Comparator to sort the results.
        Returns:
        A list of sorted mapped predicate matches.
      • transform

        public static <T,​R,​C> C transform​(java.util.Collection<T> c,
                                                      java.util.function.Predicate<? super T> predicate,
                                                      java.util.function.Function<? super T,​? extends R> mapper,
                                                      java.util.stream.Collector<R,​?,​C> collector)
        Transform the contents of a collection.
        Type Parameters:
        T - The collection member type.
        R - The resulting collection member type.
        C - The resulting collection type.
        Parameters:
        c - The Collection to transform.
        predicate - A Predicate to select the items.
        mapper - A function to transform the selected items.
        collector - A Collector to aggregate the results.
        Returns:
        The result of collecting the mapped predicate matches.
      • transform

        public static <T> java.util.List<T> transform​(java.util.stream.Stream<T> stream,
                                                      java.util.function.Predicate<? super T> predicate)
        Transform the contents of a stream.
        Type Parameters:
        T - The stream type.
        Parameters:
        stream - The Stream to transform.
        predicate - A Predicate to select the items.
        Returns:
        The result of collecting the predicate matches.
      • transform

        public static <T,​R> java.util.List<R> transform​(java.util.stream.Stream<T> stream,
                                                              java.util.function.Predicate<? super T> predicate,
                                                              java.util.function.Function<? super T,​? extends R> mapper)
        Transform the contents of a stream.
        Type Parameters:
        T - The stream member type.
        R - The resulting collection member type.
        Parameters:
        stream - The Stream to transform.
        predicate - A Predicate to select the items.
        mapper - A function to transform the selected items.
        Returns:
        The result of collecting the mapped predicate matches.
      • transform

        public static <T,​R> java.util.List<R> transform​(java.util.stream.Stream<T> stream,
                                                              java.util.function.Predicate<? super T> predicate,
                                                              java.util.function.Function<? super T,​? extends R> mapper,
                                                              java.util.Comparator<? super R> comparator)
        Transform the contents of a stream.
        Type Parameters:
        T - The collection member type.
        R - The resulting collection member type.
        Parameters:
        stream - The Stream to transform.
        predicate - A Predicate to select the items.
        mapper - A function to transform the selected items.
        comparator - A Comparator to sort the results.
        Returns:
        A list of sorted mapped predicate matches.
      • transform

        public static <T,​R,​C> C transform​(java.util.stream.Stream<T> stream,
                                                      java.util.function.Predicate<? super T> predicate,
                                                      java.util.function.Function<? super T,​? extends R> mapper,
                                                      java.util.stream.Collector<R,​?,​C> collector)
        Transform the contents of a stream.
        Type Parameters:
        T - The collection member type.
        R - The resulting collection member type.
        C - The resulting collection type.
        Parameters:
        stream - The Stream to transform.
        predicate - A Predicate to select the items.
        mapper - A function to transform the selected items.
        collector - A Collector to aggregate the results.
        Returns:
        The result of collecting the mapped predicate matches.
      • transform_internal

        private static <T,​R,​C> C transform_internal​(java.util.stream.Stream<T> stream,
                                                                java.util.function.Predicate<? super T> predicate,
                                                                java.util.function.Function<? super T,​? extends R> mapper,
                                                                java.util.Comparator<? super R> comparator,
                                                                java.util.stream.Collector<R,​?,​C> collector)
        Underlying implementation for the transform functions.
        Type Parameters:
        T - The stream member type.
        R - The resulting collection member type.
        C - The resulting collection type.
        Parameters:
        stream - The Stream to transform.
        predicate - A Predicate to select the items.
        mapper - A function to transform the selected items.
        comparator - An optional Comparator to sort the results.
        collector - A Collector to aggregate the results.
        Returns:
        The result of collecting the mapped predicate matches.