public final class TransformUtils
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static <T,U,C extends java.util.Collection<U>> |
flatMap(java.util.Collection<T> objects,
org.perro.functions.mapper.FlatMapCollector<T,U,C> flatMapCollector)
Given a collection of elements of type <T>, and an object that represents a transformer
Function<T, Collection<U>> along with a Collector<U, ?, C>, this
method collects all of those individual collections into one resulting Collection of type <C>,
consisting of all of the elements. |
static <T,U> java.util.List<U> |
flatMap(java.util.Collection<T> objects,
java.util.function.Function<T,java.util.Collection<U>> function)
Given a collection of elements of type <T>, and a
Function that transforms each of those
elements into collections of type <U>, this method collects all of those individual collections into one
resulting List consisting of all of the elements. |
static <T,U,C extends java.util.Collection<U>> |
flatMapAndThen(java.util.function.Function<T,java.util.Collection<U>> flatMapper,
java.util.stream.Collector<U,?,C> collector)
Given a
Function<T, Collection<U>>, and a Collector<U, ?, C>, this
method builds an object consisting of both of those parameters. |
static <T,U> java.util.List<U> |
flatMapDistinct(java.util.Collection<T> objects,
java.util.function.Function<T,java.util.Collection<U>> function)
Given a collection of elements of type <T>, and a
Function that transforms each of those
elements into collections of type <U>, this method collects all of those individual collections into one
resulting List consisting of all of the distinct elements of type <U> (according to
Object.equals(Object)). |
static <T,R> java.util.Set<R> |
flatMapToSet(java.util.Collection<T> objects,
java.util.function.Function<T,java.util.Collection<R>> function)
Given a collection of elements of type <T>, and a
Function that transforms each of those
elements into collections of type <R>, this method collects all of those individual collections into one
resulting Set consisting of all of the elements. |
static <T,R> java.util.List<R> |
transform(java.util.Collection<T> objects,
java.util.function.Function<T,R> transformer)
Given a collection of elements of type <T>, and a transformer function that converts those elements to
objects of type <R>, this method transforms the given collection to a
List<R>. |
static <T,U,C extends java.util.Collection<U>> |
transform(java.util.Collection<T> objects,
org.perro.functions.mapper.TransformerCollector<T,U,C> transformerCollector)
Given a collection of elements of type <T>, and an object that represents a transformer
Function<T, U> along with a Collector<U, ?, C>, this method transforms the
given collection to one of type <C>, with elements of type <U>. |
static <T,U,C extends java.util.Collection<U>> |
transformAndThen(java.util.function.Function<T,U> transformer,
java.util.stream.Collector<U,?,C> collector)
Given a
Function<T, U>, and a Collector<U, ?, C>, this method builds an
object consisting of both of those parameters. |
static <T,R> java.util.List<R> |
transformDistinct(java.util.Collection<T> objects,
java.util.function.Function<T,R> transformer)
Given a collection of elements of type <T>, and a transformer function that converts those elements to
objects of type <R>, this method transforms the given collection to a
List<R> of
distinct elements (according to Object.equals(Object)). |
static <T,K,V> java.util.Map<K,V> |
transformToMap(java.util.Collection<T> objects,
org.perro.functions.mapper.KeyValueMapper<T,K,V> keyValueMapper)
Given a collection of elements of type <T>, and an object that represents a transformer of those elements
into
Map keys and values, of type <K> and <V> respectively, this method transforms that
collection into a Map<K, V>. |
static <T,R> java.util.Set<R> |
transformToSet(java.util.Collection<T> objects,
java.util.function.Function<T,R> transformer)
Given a collection of elements of type <T>, and a transformer function that converts those elements to
objects of type <R>, this method transforms the given collection to a
Set<R>. |
public static <T,R> java.util.List<R> transform(java.util.Collection<T> objects,
java.util.function.Function<T,R> transformer)
List<R>.T - The type of the elements of the passed objects Collection.R - The type of the elements in the resulting List.objects - A collection of elements of type <T>.transformer - A transformer Function from objects of type <T>, to objects of type <R>.public static <T,R> java.util.Set<R> transformToSet(java.util.Collection<T> objects,
java.util.function.Function<T,R> transformer)
Set<R>.T - The type of the elements of the passed objects Collection.R - The type of the elements in the resulting Set.objects - A collection of elements of type <T>.transformer - A transformer Function from objects of type <T>, to objects of type <R>.public static <T,R> java.util.List<R> transformDistinct(java.util.Collection<T> objects,
java.util.function.Function<T,R> transformer)
List<R> of
distinct elements (according to Object.equals(Object)).T - The type of the elements of the passed objects Collection.R - The type of the elements in the resulting List.objects - A collection of elements of type <T>.transformer - A transformer Function from objects of type <T>, to objects of type <R>.public static <T,U,C extends java.util.Collection<U>> C transform(java.util.Collection<T> objects,
org.perro.functions.mapper.TransformerCollector<T,U,C> transformerCollector)
Function<T, U> along with a Collector<U, ?, C>, this method transforms the
given collection to one of type <C>, with elements of type <U>.T - The type of the elements in the passed objects Collection.U - The type of the elements in the resulting collection.C - The type of the resulting Collection.objects - A collection of elements of type <T>.transformerCollector - An object that represents a transformer Function<T, U> along with
a Collector<U, ?, C>.public static <T,K,V> java.util.Map<K,V> transformToMap(java.util.Collection<T> objects,
org.perro.functions.mapper.KeyValueMapper<T,K,V> keyValueMapper)
Map keys and values, of type <K> and <V> respectively, this method transforms that
collection into a Map<K, V>.T - The type of the elements in the passed objects Collection.K - The type of the keys in the resulting Map.V - The type of the values in the resulting Map.objects - A collection of elements of type <T>.keyValueMapper - An object consisting of a pair of functions, one transforming an element of type <T>
into a key value of type <K>, and the other transforming <T> into a value of
<V>.public static <T,U> java.util.List<U> flatMap(java.util.Collection<T> objects,
java.util.function.Function<T,java.util.Collection<U>> function)
Function that transforms each of those
elements into collections of type <U>, this method collects all of those individual collections into one
resulting List consisting of all of the elements.T - The type of the elements in the passed objects Collection.U - The type of the elements in the resulting collection.objects - A collection of elements of type <T>.function - A transformer Function from objects of type <T>, to a Collection of elements
of type <U>.public static <T,R> java.util.Set<R> flatMapToSet(java.util.Collection<T> objects,
java.util.function.Function<T,java.util.Collection<R>> function)
Function that transforms each of those
elements into collections of type <R>, this method collects all of those individual collections into one
resulting Set consisting of all of the elements.T - The type of the elements in the passed objects Collection.R - The type of the elements in the resulting collection.objects - A collection of elements of type <T>.function - A transformer Function from objects of type <T>, to objects of type <R>.public static <T,U> java.util.List<U> flatMapDistinct(java.util.Collection<T> objects,
java.util.function.Function<T,java.util.Collection<U>> function)
Function that transforms each of those
elements into collections of type <U>, this method collects all of those individual collections into one
resulting List consisting of all of the distinct elements of type <U> (according to
Object.equals(Object)).T - The type of the elements in the passed objects Collection.U - The type of the elements in the resulting collection.objects - A collection of elements of type <T>.function - A transformer Function from objects of type <T>, to objects of type <U>.public static <T,U,C extends java.util.Collection<U>> C flatMap(java.util.Collection<T> objects,
org.perro.functions.mapper.FlatMapCollector<T,U,C> flatMapCollector)
Function<T, Collection<U>> along with a Collector<U, ?, C>, this
method collects all of those individual collections into one resulting Collection of type <C>,
consisting of all of the elements.T - The type of the elements in the passed objects Collection.U - The type of the elements in the resulting collection.C - The type of the resulting Collection.objects - A collection of elements of type <T>.flatMapCollector - An object that represents a transformer Function<T,
Collection<U>> along with a Collector<U, ?, C>.public static <T,U,C extends java.util.Collection<U>> org.perro.functions.mapper.TransformerCollector<T,U,C> transformAndThen(java.util.function.Function<T,U> transformer,
java.util.stream.Collector<U,?,C> collector)
Function<T, U>, and a Collector<U, ?, C>, this method builds an
object consisting of both of those parameters. This method is meant to build the second parameter of the
transform(Collection, TransformerCollector) method. For example, suppose you want to retrieve an
EnumSet consisting of all the unique ProductLine enumerated values in the line items of
an order:
private Set<ProductLine> getUniqueProductLines(Order order) {
return TransformUtils.transform(order.getLineItems(),
TransformUtils.transformAndThen(LineItem::getProductLine, CollectorUtils.toEnumSet(ProductLine.class)));
}
Or, using static imports:
private Set<ProductLine> getUniqueProductLines(Order order) {
return transform(order.getLineItems(), transformAndThen(LineItem::getProductLine, toEnumSet(ProductLine.class)));
}
T - The type of the target element to be passed into the transformer function.U - The type of the return value of the transformer function.C - The type of the resulting collection of the passed Collector.transformer - A transformer Function from objects of type <T>, to objects of type <U>.collector - A Collector<U, ?, C> to return a Collection of elements of type <C>.public static <T,U,C extends java.util.Collection<U>> org.perro.functions.mapper.FlatMapCollector<T,U,C> flatMapAndThen(java.util.function.Function<T,java.util.Collection<U>> flatMapper,
java.util.stream.Collector<U,?,C> collector)
Function<T, Collection<U>>, and a Collector<U, ?, C>, this
method builds an object consisting of both of those parameters. This method is meant to build the second parameter of the
flatMap(Collection, FlatMapCollector) method. For example, suppose you want to retrieve an
EnumSet consisting of all the unique ProductLine enumerated values for a
Collection of customer orders:
private Set<ProductLine> getUniqueProductLines(Collection<Order> customerOrders) {
return TransformUtils.flatMap(order.getLineItems(),
TransformUtils.flatMapAndThen(Order::getProductLines, CollectorUtils.toEnumSet(ProductLine.class)));
}
Or, using static imports:
private Set<ProductLine> getUniqueProductLines(Collection<Order> customerOrders) {
return flatMap(order.getLineItems(), flatMapAndThen(Order::getProductLines, toEnumSet(ProductLine.class)));
}
T - The type of the target element to be passed into the transformer function.U - The type of the elements in the Collection to be returned from the transformer function.C - The type of the resulting collection of the passed Collector.flatMapper - A transformer Function from objects of type <T>, to a Collection of elements
of type <U>.collector - A Collector<U, ?, C> to return a Collection of elements of type <C>.