public final class Product extends Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
Product.HasFirst<T>
An interface representing an object that has a first component.
|
static interface |
Product.HasSecond<U>
An interface representing an object that has a second component.
|
static interface |
Product.HasThird<V>
Interface representing an object that has a third component of type
V. |
static interface |
Product.Product2<T,U>
A Product2 is a composite object comprising two components.
|
static interface |
Product.Product3<T,U,V>
A Product3 is a composite object comprising three components.
|
static interface |
Product.TriFunction<T,U,V,R>
Function interface representing a function that accepts three arguments and produces a result.
|
| Modifier and Type | Method and Description |
|---|---|
static <T,U> Stream<Product.Product2<T,U>> |
of(@NotNull Collection<T> ts,
@NotNull Collection<U> us)
Creates and returns a Stream representing the Cartesian product of the given
ts and us collections. |
static <T,U,R> Stream<R> |
of(@NotNull Collection<T> ts,
@NotNull Collection<U> us,
@NotNull BiFunction<? super T,? super U,? extends R> constructor)
Creates and returns the cartesian product of the given elements by applying the provided
constructor to each tuple (pair of elements). |
static <T,U,V> Stream<Product.Product3<T,U,V>> |
of(@NotNull Collection<T> ts,
@NotNull Collection<U> us,
@NotNull Collection<V> vs)
Creates and returns the cartesian product of the given elements by applying a default
Product3 constructor to each tuple.
|
static <T,U,V,R> Stream<R> |
of(@NotNull Collection<T> ts,
@NotNull Collection<U> us,
@NotNull Collection<V> vs,
@NotNull Product.TriFunction<T,U,V,R> constructor)
Creates and returns the cartesian product of the given elements by applying the provided
constructor to each tuple. |
static <T,U> Stream<Product.Product2<T,U>> |
of(@NotNull Stream<T> ts,
@NotNull Stream<U> us)
Creates and returns the cartesian product of the given elements by applying a default
Product2 constructor to each tuple.
|
static <T,U,R> Stream<R> |
of(@NotNull Stream<T> ts,
@NotNull Stream<U> us,
@NotNull BiFunction<? super T,? super U,? extends R> constructor)
Creates and returns the cartesian product of the given elements by applying the provided
constructor to each tuple. |
static <T,U,V> Stream<Product.Product3<T,U,V>> |
of(@NotNull Stream<T> ts,
@NotNull Stream<U> us,
@NotNull Stream<V> vs)
Creates and returns the cartesian product of the given elements by applying a default
Product3 constructor to each tuple.
|
static <T,U,V,R> Stream<R> |
of(@NotNull Stream<T> ts,
@NotNull Stream<U> us,
@NotNull Stream<V> vs,
@NotNull Product.TriFunction<T,U,V,R> constructor)
Creates and returns the cartesian product of the given elements by applying the provided
constructor to each tuple. |
public static <T,U> Stream<Product.Product2<T,U>> of(@NotNull @NotNull Collection<T> ts, @NotNull @NotNull Collection<U> us)
ts and us collections.
This method returns a Stream of Product.Product2 objects, which pairs each element in ts with each
element in us. The order of the product is by T (most significant factor) and then U.
The provided collections must not be null, or a NullPointerException will be thrown.
Example:
If ts = ["A", "B"] and us = [1, 2], the method will return a Stream with elements:
[("A", 1), ("A", 2), ("B", 1), ("B", 2)].
T - The element type for the first collectionU - The element type for the second collectionts - The first collection of elements (non-null)us - The second collection of elements (non-null)Product.Product2 objectsNullPointerException - if any of the provided collections are nullpublic static <T,U,R> Stream<R> of(@NotNull @NotNull Collection<T> ts, @NotNull @NotNull Collection<U> us, @NotNull @NotNull BiFunction<? super T,? super U,? extends R> constructor)
constructor to each tuple (pair of elements).
This method calculates the Cartesian product of two collections, ts and us,
by pairing each element in ts with each element in us and applying the provided
constructor to each pair. The order of the product is determined first by T
(most significant factor) and then by U.
Example:
If ts = ["A", "B"] and us = [1, 2], and the constructor concatenates the elements,
the method will return a Stream with elements ["A1", "A2", "B1", "B2"].
T - Element type for the first collectionU - Element type for the second collectionR - Return type after applying the constructor to each tuplets - The first collection of elements (non-null)us - The second collection of elements (non-null)constructor - A BiFunction to be applied to all pairs, creating the result type R (non-null)NullPointerException - if any of the provided parameters are nullpublic static <T,U> Stream<Product.Product2<T,U>> of(@NotNull @NotNull Stream<T> ts, @NotNull @NotNull Stream<U> us)
The cartesian product is the combination of all possible pairs between the first stream ts and the second stream us.
The order of the product is by T (most significant factor) and then U.
This method applies a default constructor ProductUtil.Product2Impl::new to create objects of type Product2<T, U>
representing each tuple in the product.
T - element type for the first factor orderU - element type for the second factor orderts - the first factor order (non-null)us - the second factor order (non-null)Product2<T, U> representing the cartesian product of the given elementsNullPointerException - if any of the provided parameters are null.public static <T,U,R> Stream<R> of(@NotNull @NotNull Stream<T> ts, @NotNull @NotNull Stream<U> us, @NotNull @NotNull BiFunction<? super T,? super U,? extends R> constructor)
constructor to each tuple.
Similar to the previous method, this function creates pairs of all possible combinations
between two streams, ts and us, and then applies the provided constructor
to each pair to create objects of type R.
The order of the product is determined first by T (most significant factor) and then by U.
The provided stream ts is consumed lazily, and the other provided streams are not.
T - Element type for the first streamU - Element type for the second streamR - Return type after applying the constructor to each tuplets - The first stream of elements (non-null)us - The second stream of elements (non-null)constructor - A BiFunction to be applied to all pairs, creating the result type R (non-null)NullPointerException - if any of the provided parameters are nullpublic static <T,U,V> Stream<Product.Product3<T,U,V>> of(@NotNull @NotNull Collection<T> ts, @NotNull @NotNull Collection<U> us, @NotNull @NotNull Collection<V> vs)
The cartesian product is formed by creating all possible combinations of the three
collections ts, us, and vs, with the order being determined first
by T (most significant factor), then by U, and finally by V.
The default constructor ProductUtil.Product3Impl::new is used to create objects of type
Product3<T, U, V> representing each tuple in the product.
T - element type for the first factor orderU - element type for the second factor orderV - element type for the third factor orderts - the first factor order (non-null)us - the second factor order (non-null)vs - the third factor order (non-null)Product3<T, U, V> representing the cartesian product of the given elementsNullPointerException - if any of the provided parameters are null.public static <T,U,V,R> Stream<R> of(@NotNull @NotNull Collection<T> ts, @NotNull @NotNull Collection<U> us, @NotNull @NotNull Collection<V> vs, @NotNull @NotNull Product.TriFunction<T,U,V,R> constructor)
constructor to each tuple.
Similar to the previous method, this function creates all possible combinations between
the three collections ts, us, and vs, and then applies the provided
constructor to each tuple to create objects of type R.
The order of the product is determined first by T (most significant factor), then
by U, and finally by V.
T - Element type for the first collectionU - Element type for the second collectionV - Element type for the third collectionR - Return type after applying the constructor to each tuplets - The first collection of elements (non-null)us - The second collection of elements (non-null)vs - The third collection of elements (non-null)constructor - A TriFunction to be applied to all tuples, creating the result type R (non-null)NullPointerException - if any of the provided parameters are nullpublic static <T,U,V> Stream<Product.Product3<T,U,V>> of(@NotNull @NotNull Stream<T> ts, @NotNull @NotNull Stream<U> us, @NotNull @NotNull Stream<V> vs)
The order of the product is by T (most significant factor) and then U and then V. The provided stream
ts is consumed lazily, and the other provided streams are not, which allows for more efficient
processing of large or infinite streams.
The default constructor ProductUtil.Product3Impl::new is used to represent each tuple in the product.
T - element type for the first factor orderU - element type for the second factor orderV - element type for the third factor orderts - the first factor order (non-null)us - the second factor order (non-null)vs - the third factor order (non-null)Product3<T, U, V> representing the cartesian product of the given elementsNullPointerException - if any of the provided parameters are null.public static <T,U,V,R> Stream<R> of(@NotNull @NotNull Stream<T> ts, @NotNull @NotNull Stream<U> us, @NotNull @NotNull Stream<V> vs, @NotNull @NotNull Product.TriFunction<T,U,V,R> constructor)
constructor to each tuple.
This function creates all possible combinations between the three streams ts, us,
and vs, and then applies the provided constructor to each tuple to create objects
of type R.
The order of the product is determined first by T (most significant factor), then
by U, and finally by V. The stream ts is consumed lazily, while the
others are not.
T - Element type for the first streamU - Element type for the second streamV - Element type for the third streamR - Return type after applying the constructor to each tuplets - The first stream of elements (non-null)us - The second stream of elements (non-null)vs - The third stream of elements (non-null)constructor - A TriFunction to be applied to all tuples, creating the result type R (non-null)NullPointerException - if any of the provided parameters are nullCopyright © 2024. All rights reserved.