Package net.sf.freecol.common.util
Class CollectionUtils
- java.lang.Object
-
- net.sf.freecol.common.util.CollectionUtils
-
public class CollectionUtils extends java.lang.ObjectCollection of small static helper methods using Collections.
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.Comparator<java.lang.Double>ascendingDoubleComparatorstatic java.util.Comparator<java.lang.Integer>ascendingIntegerComparatorUseful comparators for mapEntriesBy*static java.util.Comparator<java.util.List<?>>ascendingListLengthComparatorstatic java.util.Comparator<java.lang.Double>descendingDoubleComparatorstatic java.util.Comparator<java.lang.Integer>descendingIntegerComparatorstatic java.util.Comparator<java.util.List<?>>descendingListLengthComparatorstatic java.util.function.BinaryOperator<java.lang.Double>doubleAccumulatorTrivial double accumulator.static java.util.function.BinaryOperator<java.lang.Integer>integerAccumulatorTrivial integer accumulator.private static intMAX_DEFAULTprivate static intMIN_DEFAULTprivate static doublePRODUCT_DEFAULTprivate static intSUM_DEFAULTprivate static doubleSUM_DOUBLE_DEFAULT
-
Constructor Summary
Constructors Constructor Description CollectionUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <K,V>
voidaccumulateMap(java.util.Map<K,V> map1, java.util.Map<K,V> map2, java.util.function.BinaryOperator<V> accumulator)static <K,V>
voidaccumulateToMap(java.util.Map<K,V> map, K key, V value, java.util.function.BinaryOperator<V> accumulator)static <T> booleanall(java.util.Collection<T> c, java.util.function.Predicate<? super T> predicate)Do all members of an collection match a predicate?static <T> booleanall(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate)Do all members of an stream match a predicate?static <T> booleanall(T[] array, java.util.function.Predicate<? super T> predicate)Do all members of an array match a predicate?private static <T> booleanall_internal(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate)Implementation of all().static <T> booleanallSame(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> booleanany(java.util.Collection<T> c)Is a collection non-empty?static <T> booleanany(java.util.Collection<T> c, java.util.function.Predicate<? super T> predicate)Does any member of a collection match a predicate?static <T> booleanany(java.util.stream.Stream<T> stream)Is a stream non-empty?static <T> booleanany(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate)Does any member of a stream match a predicate?static <T> booleanany(T[] array)Is an array non-empty?static <T> booleanany(T[] array, java.util.function.Predicate<? super T> predicate)Does any member of an array match a predicate?private static <T> booleanany_internal(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate)Implementation of any().static <T,K>
voidappendToMapList(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> intcount(java.util.Collection<T> c)Count the number of members of a collection that match a predicate.static <T> intcount(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> intcount(java.util.stream.Stream<T> stream)Count the number of members of a stream.static <T> intcount(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> intcount(T[] array)Count the number of members of an array.static <T> intcount(T[] array, java.util.function.Predicate<? super T> predicate)Count the number of members of an array that match a predicate.private static <T> intcount_internal(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate)Implement count().static voiddump(java.lang.String header, java.util.Collection<?> c)Dump a collection toSystem.err.static voiddump(java.lang.String header, java.util.Map<?,?> map)Dump a map toSystem.err.static voiddump(java.lang.String header, java.util.stream.Stream<?> stream)Dump a stream toSystem.err.static <T> voiddump(java.lang.String header, T[] array)Dump an array toSystem.err.private static voiddump_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> Tfind(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> Tfind(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> Tfind(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> Tfind(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> Tfind(T[] array, java.util.function.Predicate<? super T> predicate)Simple stream search for the first item that matches a predicate.static <T> Tfind(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> Tfind_internal(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate, T fail)Implement find().static <T> Tfirst(java.util.Collection<T> c)Get the first item of a collection.static <T> Tfirst(java.util.stream.Stream<T> stream)Get the first item of a stream.static <T> Tfirst(T[] array)Get the first item of an array.private static <T> Tfirst_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> voidforEach(java.util.Collection<T> c, java.util.function.Consumer<? super T> consumer)Apply a consumer to the members of a collection.static <T> voidforEach(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> voidforEach(java.util.stream.Stream<T> stream, java.util.function.Consumer<? super T> consumer)Apply a consumer to the members of a stream.static <T> voidforEach(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> voidforEach(T[] array, java.util.function.Consumer<? super T> consumer)Apply a consumer to the members of an array.static <T> voidforEach(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> voidforEach_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>
voidforEachMapEntry(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>
voidforEachMapEntry(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> intincrementMapCount(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> booleanlistEquals(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> intmax(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> intmax(java.util.Collection<T> c, java.util.function.ToIntFunction<T> tif)Find the maximum int value in a collection.static <T> intmax(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> intmax(java.util.stream.Stream<T> stream, java.util.function.ToIntFunction<T> tif)Find the maximum int value in a stream.static <T> intmax(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> intmax(T[] array, java.util.function.ToIntFunction<T> tif)Find the maximum int value in an array.private static <T> intmax_internal(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate, java.util.function.ToIntFunction<T> tif)Implement max.static <T> Tmaximize(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> Tmaximize(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> Tmaximize(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> Tmaximize(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> Tmaximize(T[] array, java.util.Comparator<? super T> comparator)Find the selected member of an array that maximizes according to a given comparison.static <T> Tmaximize(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> Tmaximize_internal(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate, java.util.Comparator<? super T> comparator)Implement maximize.static <T> intmin(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> intmin(java.util.Collection<T> c, java.util.function.ToIntFunction<T> tif)Find the minimum int value in a collection.static <T> intmin(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> intmin(java.util.stream.Stream<T> stream, java.util.function.ToIntFunction<T> tif)Find the minimum int value in a stream.static <T> intmin(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> intmin(T[] array, java.util.function.ToIntFunction<T> tif)Find the minimum int value in an array.private static <T> intmin_internal(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate, java.util.function.ToIntFunction<T> tif)Implement min.static <T> Tminimize(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> Tminimize(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> Tminimize(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> Tminimize(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> Tminimize(T[] array, java.util.Comparator<? super T> comparator)Find the selected member of an array that minimizes according to a given comparison.static <T> Tminimize(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> Tminimize_internal(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate, java.util.Comparator<? super T> comparator)Implement minimize.static <T> booleannone(java.util.Collection<T> c)Is a collection empty?static <T> booleannone(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> booleannone(java.util.stream.Stream<T> stream)Is a stream null or empty?static <T> booleannone(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> booleannone(T[] array)Is an array null or empty?static <T> booleannone(T[] array, java.util.function.Predicate<? super T> predicate)Do none of the members of an array match a predicate?private static <T> booleannone_internal(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate)Implementation of none().static <T> doubleproduct(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> doubleproduct(java.util.Collection<T> c, java.util.function.ToDoubleFunction<T> tdf)Take the product of a collection.static <T> doubleproduct(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> doubleproduct(java.util.stream.Stream<T> stream, java.util.function.ToDoubleFunction<T> tdf)Take the product of the members of a stream.static <T> doubleproduct(T[] array, java.util.function.Predicate<? super T> predicate, java.util.function.ToDoubleFunction<T> tdf)Take the product of an array.static <T> doubleproduct(T[] array, java.util.function.ToDoubleFunction<T> tdf)Take the product of an array.private static <T> doubleproduct_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> booleanremoveInPlace(java.util.Collection<T> c, java.util.function.Predicate<? super T> predicate)Special case to remove objects from a collection.static <K,V>
booleanremoveInPlace(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> voidreverse(java.util.List<T> list)Reverse a list.static <T> voidrotate(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> intsum(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> intsum(java.util.Collection<T> c, java.util.function.ToIntFunction<T> tif)Take the sum of the members of a collection.static <T> intsum(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> intsum(java.util.stream.Stream<T> stream, java.util.function.ToIntFunction<T> tif)Take the sum of the members of a stream.static <T> intsum(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> intsum(T[] array, java.util.function.ToIntFunction<T> tif)Take the sum of the members of an array.private static <T> intsum_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> doublesumDouble(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> doublesumDouble(java.util.Collection<T> c, java.util.function.ToDoubleFunction<T> tdf)Take the sum of the members of a collection.static <T> doublesumDouble(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> doublesumDouble(java.util.stream.Stream<T> stream, java.util.function.ToDoubleFunction<T> tdf)Take the sum of the members of a stream.static <T> doublesumDouble(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> doublesumDouble(T[] array, java.util.function.ToDoubleFunction<T> tdf)Take the sum of the members of an array.private static <T> doublesumDouble_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>
Ctransform(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>
Ctransform(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>
Ctransform(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>
Ctransform_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.
-
-
-
Field Detail
-
MAX_DEFAULT
private static final int MAX_DEFAULT
- See Also:
- Constant Field Values
-
MIN_DEFAULT
private static final int MIN_DEFAULT
- See Also:
- Constant Field Values
-
SUM_DEFAULT
private static final int SUM_DEFAULT
- See Also:
- Constant Field Values
-
SUM_DOUBLE_DEFAULT
private static final double SUM_DOUBLE_DEFAULT
- See Also:
- Constant Field Values
-
PRODUCT_DEFAULT
private static final double PRODUCT_DEFAULT
- See Also:
- Constant Field Values
-
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
-
-
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- TheMapto 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- TheCollectionto 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- TheListto 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- TheListto 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 comparetwo- 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- TheMapto 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- TheMapto extract entries from.comparator- AComparatorfor 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- TheMapto 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- TheMapto extract entries from.comparator- AComparatorfor 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- ThePredicateto 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- TheCollectionto test.predicate- ThePredicateto 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- TheStreamto test.predicate- ThePredicateto 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- TheStreamto test.predicate- ThePredicateto 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- ThePredicateto 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- TheCollectionto 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- TheCollectionto test.predicate- ThePredicateto 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- TheStreamto 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- TheStreamto test.predicate- ThePredicateto 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- TheStreamto test.predicate- ThePredicateto 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 ofStream- Parameters:
s0- The firstStream.streams- TheStreams 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- APredicateto 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- TheCollectionto 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- TheCollectionto check.predicate- APredicateto 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- TheStreamto 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- TheStreamto check.predicate- APredicateto 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- TheStreamto check.predicate- APredicateto test with.- Returns:
- The number of items that matched.
-
dump
public static <T> void dump(java.lang.String header, T[] array)Dump an array toSystem.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 toSystem.err.- Parameters:
header- Optional informational string to print first.c- TheCollectionto print.
-
dump
public static void dump(java.lang.String header, java.util.stream.Stream<?> stream)Dump a stream toSystem.err.- Parameters:
header- Optional informational string to print first.stream- TheStreamto 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- TheStreamto print.
-
dump
public static void dump(java.lang.String header, java.util.Map<?,?> map)Dump a map toSystem.err.- Parameters:
header- Optional informational string to print first.map- TheMapto 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- TheFilethat 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- TheFilethat hopefully is a directory.predicate- ThePredicateto 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- APredicateto 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- APredicateto 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- TheCollectionto search.predicate- APredicateto 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- TheCollectionto search.predicate- APredicateto 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- AStreamto search.predicate- APredicateto 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- AStreamto search.predicate- APredicateto 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- AStreamto search.predicate- APredicateto 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- TheCollectionto 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- TheCollectionto 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- TheStreamto 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- TheStreamto 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 mappingFunctionto 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- APredicateto filter the collection with.mapper- A mappingFunctionto 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- TheCollectionto flatten.mapper- A mappingFunctionto 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- TheCollectionto flatten.predicate- APredicateto filter the collection with.mapper- A mappingFunctionto 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- TheStreamto flatten.mapper- A mappingFunctionto 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- TheStreamto flatten.predicate- APredicateto filter the collection with.mapper- A mappingFunctionto 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- TheStreamto flatten.predicate- APredicateto filter the collection with.mapper- A mappingFunctionto 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- TheMapto apply to.consumer- AConsumerto 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- TheMapto apply to.predicate- ThePredicateto match.consumer- AConsumerto 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- AConsumerto 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- APredicateto gate the application.consumer- AConsumerto 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- TheCollectionto apply to.consumer- AConsumerto 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- TheCollectionto apply to.predicate- APredicateto gate the application.consumer- AConsumerto 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- TheStreamto apply to.consumer- AConsumerto 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- TheStreamto apply to.predicate- APredicateto gate the application.consumer- AConsumerto 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- TheStreamto apply to.predicate- APredicateto gate the application.consumer- AConsumerto 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- TheStreamto 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 mappingFunctionto 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- TheCollectionto search.mapper- A mappingFunctionto 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 TR- Generic type R- Parameters:
stream- TheStreamto map.mapper- A mappingFunctionto 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 TR- Generic type R- Parameters:
stream- TheStreamto map.mapper- A mappingFunctionto 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 mapperFunctionto 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 mapperFunctionto 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- AToIntFunctionto 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- APredicateto match with.tif- AToIntFunctionto 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- TheCollectionto check.tif- AToIntFunctionto 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- TheCollectionto check.predicate- APredicateto match with.tif- AToIntFunctionto 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- TheStreamto check.tif- AToIntFunctionto 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- TheStreamto check.predicate- APredicateto match with.tif- AToIntFunctionto 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- TheStreamto check.predicate- APredicateto match with.tif- AToIntFunctionto 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- AComparatorto 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- APredicateto match with.comparator- AComparatorto 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- TheCollectionto maximize from.comparator- AComparatorto 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- TheCollectionto maximize from.predicate- APredicateto match with.comparator- AComparatorto 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- TheStreamto maximize from.comparator- AComparatorto 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- TheStreamto maximize from.predicate- APredicateto match with.comparator- AComparatorto 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- TheStreamto maximize from.predicate- APredicateto match with.comparator- AComparatorto 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- AToIntFunctionto 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- APredicateto match with.tif- AToIntFunctionto 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- TheCollectionto check.tif- AToIntFunctionto 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- TheCollectionto check.predicate- APredicateto match with.tif- AToIntFunctionto 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- TheStreamto check.tif- AToIntFunctionto 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- TheStreamto check.predicate- APredicateto match with.tif- AToIntFunctionto 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- TheStreamto check.predicate- APredicateto match with.tif- AToIntFunctionto 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- AComparatorto 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- APredicateto match with.comparator- AComparatorto 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- TheCollectionto minimize from.comparator- AComparatorto 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- TheCollectionto minimize from.predicate- APredicateto match with.comparator- AComparatorto 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- TheStreamto minimize from.comparator- AComparatorto 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- TheStreamto minimize from.predicate- APredicateto match with.comparator- AComparatorto 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- TheStreamto minimize from.predicate- APredicateto match with.comparator- AComparatorto 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- ThePredicateto 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- TheCollectionto 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- TheCollectionto test.predicate- ThePredicateto 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- TheStreamto 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- TheStreamto test.predicate- ThePredicateto 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- TheStreamto test.predicate- ThePredicateto 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- AToDoubleFunctionto 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- APredicateto match with.tdf- AToDoubleFunctionto 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- TheCollectionto multiply.tdf- AToDoubleFunctionto 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- TheCollectionto multiply.predicate- APredicateto match with.tdf- AToDoubleFunctionto 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- TheStreamto multiply.tdf- AToDoubleFunctionto 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- TheStreamto multiply.predicate- APredicateto match with.tdf- AToDoubleFunctionto 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- APredicateto match with.stream- TheStreamto multiply.tdf- AToDoubleFunctionto 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- TheCollectionto remove from.predicate- APredicateto 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- TheMapto remove entries from.predicate- APredicateto 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- AComparatorto 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- TheCollectionto 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- TheCollectionto convert.comparator- AComparatorto 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- TheStreamto 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- TheStreamto collect.comparator- AComparatorto 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- TheStreamto collect.comparator- AComparatorto 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- AToIntFunctionto 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- APredicateto match with.tif- AToIntFunctionto 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- TheCollectionto sum.tif- AToIntFunctionto 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- TheCollectionto sum.predicate- APredicateto match with.tif- AToIntFunctionto 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- TheStreamto sum.tif- AToIntFunctionto 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- TheStreamto sum.predicate- APredicateto match with.tif- AToIntFunctionto 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- TheStreamto sum.predicate- APredicateto match with.tif- AToIntFunctionto 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- AToDoubleFunctionto 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- APredicateto match with.tdf- AToDoubleFunctionto 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- TheCollectionto sum.tdf- AToDoubleFunctionto 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- TheCollectionto sum.predicate- APredicateto match with.tdf- AToDoubleFunctionto 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- TheStreamto sum.tdf- AToDoubleFunctionto 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- TheStreamto sum.predicate- APredicateto select members.tdf- AToIntFunctionto 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- TheStreamto sum.predicate- APredicateto select members.tdf- AToIntFunctionto 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- TheCollectionto 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- TheStreamto 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- TheStreamto 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- AStream- Parameters:
iterator- TheIteratorto 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- AStream- Parameters:
iterable- TheIterableto 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- APredicateto 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- APredicateto 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- APredicateto select the items.mapper- A function to transform the selected items.collector- ACollectorto 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- APredicateto select the items.mapper- A function to transform the selected items.comparator- AComparatorto 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- TheCollectionto transform.predicate- APredicateto 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- TheCollectionto transform.predicate- APredicateto 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- TheCollectionto transform.predicate- APredicateto select the items.mapper- A function to transform the selected items.comparator- AComparatorto 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- TheCollectionto transform.predicate- APredicateto select the items.mapper- A function to transform the selected items.collector- ACollectorto 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- TheStreamto transform.predicate- APredicateto 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- TheStreamto transform.predicate- APredicateto 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- TheStreamto transform.predicate- APredicateto select the items.mapper- A function to transform the selected items.comparator- AComparatorto 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- TheStreamto transform.predicate- APredicateto select the items.mapper- A function to transform the selected items.collector- ACollectorto 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- TheStreamto transform.predicate- APredicateto select the items.mapper- A function to transform the selected items.comparator- An optionalComparatorto sort the results.collector- ACollectorto aggregate the results.- Returns:
- The result of collecting the mapped predicate matches.
-
-