Package it.tidalwave.util
Class Pair<A,B>
- java.lang.Object
-
- it.tidalwave.util.Pair<A,B>
-
@Immutable public class Pair<A,B> extends java.lang.Object
A value object that contains a pair of values. Some factory methods allow to create pairs out of existing collections or arrays associating an index.- Since:
- 3.2-ALPHA-6
- Author:
- Fabrizio Giudici
- Status: draft API
-
-
Constructor Summary
Constructors Constructor Description Pair()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> java.util.stream.Stream<Pair<java.lang.Integer,T>>
indexedPairStream(int from, int to, java.util.function.IntFunction<T> valueSupplier)
static <T> java.util.stream.Stream<Pair<java.lang.Integer,T>>
indexedPairStream(int from, int to, java.util.function.IntFunction<T> valueSupplier, java.util.function.IntUnaryOperator rebaser)
static <T,I>
java.util.stream.Stream<Pair<I,T>>indexedPairStream(int from, int to, java.util.function.IntFunction<T> valueSupplier, java.util.function.IntUnaryOperator rebaser, java.util.function.IntFunction<I> indexTransformer)
static <T> java.util.stream.Stream<Pair<java.lang.Integer,T>>
indexedPairStream(java.lang.Iterable<T> iterable)
static <I,T>
java.util.stream.Stream<Pair<I,T>>indexedPairStream(java.lang.Iterable<T> iterable, java.util.function.IntFunction<I> indexTransformer)
static <T> java.util.stream.Stream<Pair<java.lang.Integer,T>>
indexedPairStream(java.lang.Iterable<T> iterable, java.util.function.IntUnaryOperator rebaser)
static <I,T>
java.util.stream.Stream<Pair<I,T>>indexedPairStream(java.lang.Iterable<T> iterable, java.util.function.IntUnaryOperator rebaser, java.util.function.IntFunction<I> indexTransformer)
static <T> java.util.stream.Stream<Pair<java.lang.Integer,T>>
indexedPairStream(T[] array)
static <I,T>
java.util.stream.Stream<Pair<I,T>>indexedPairStream(T[] array, java.util.function.IntFunction<I> indexTransformer)
static <T> java.util.stream.Stream<Pair<java.lang.Integer,T>>
indexedPairStream(T[] array, java.util.function.IntUnaryOperator rebaser)
static <T,I>
java.util.stream.Stream<Pair<I,T>>indexedPairStream(T[] array, java.util.function.IntUnaryOperator rebaser, java.util.function.IntFunction<I> indexTransformer)
static <A,B>
java.util.stream.Collector<? super Pair<A,B>,?,java.util.Map<A,B>>pairsToMap()
ACollector
that produces aMap
whose key is fielda
and value fieldb
.
-
-
-
Method Detail
-
indexedPairStream
@Nonnull public static <T> java.util.stream.Stream<Pair<java.lang.Integer,T>> indexedPairStream(@Nonnull T[] array)
- Type Parameters:
T
- the type of the elements- Parameters:
array
- the array- Returns:
- the stream
-
indexedPairStream
@Nonnull public static <T> java.util.stream.Stream<Pair<java.lang.Integer,T>> indexedPairStream(@Nonnull T[] array, @Nonnull java.util.function.IntUnaryOperator rebaser)
Returns aStream
out of the elements in the array, made ofPair
s(index, value)
. The index can be rebased.- Type Parameters:
T
- the type of the elements- Parameters:
array
- the arrayrebaser
- the rebaser of the index (BASE_0, BASE_1 or a similar function)- Returns:
- the stream
-
indexedPairStream
@Nonnull public static <I,T> java.util.stream.Stream<Pair<I,T>> indexedPairStream(@Nonnull T[] array, @Nonnull java.util.function.IntFunction<I> indexTransformer)
Returns aStream
out of the elements in a given array made ofPair
s(index, value)
. The index is transformed with the given function.- Type Parameters:
I
- the type of the transformed indexT
- the type of the elements- Parameters:
array
- the arrayindexTransformer
- the transformer of the index- Returns:
- the stream
-
indexedPairStream
@Nonnull public static <T,I> java.util.stream.Stream<Pair<I,T>> indexedPairStream(@Nonnull T[] array, @Nonnull java.util.function.IntUnaryOperator rebaser, @Nonnull java.util.function.IntFunction<I> indexTransformer)
Returns aStream
out of the elements in the array, made ofPair
s(index, value)
. The index can be rebased and transformed with specific functions.- Type Parameters:
T
- the type of the elementsI
- the type of the transformed index- Parameters:
array
- the arrayrebaser
- the rebaser of the index (BASE_0, BASE_1 or a similar function)indexTransformer
- the transformer of the index- Returns:
- the stream
-
indexedPairStream
@Nonnull public static <T> java.util.stream.Stream<Pair<java.lang.Integer,T>> indexedPairStream(@Nonnull java.lang.Iterable<T> iterable)
- Type Parameters:
T
- the type of the elements- Parameters:
iterable
- the iterable- Returns:
- the stream
-
indexedPairStream
@Nonnull public static <T> java.util.stream.Stream<Pair<java.lang.Integer,T>> indexedPairStream(@Nonnull java.lang.Iterable<T> iterable, @Nonnull java.util.function.IntUnaryOperator rebaser)
Returns aStream
out of the elements in a givenIterable
made ofPair
s(index, value)
. The index can be rebased.- Type Parameters:
T
- the type of the elements- Parameters:
iterable
- the iterablerebaser
- the rebaser of the index (BASE_0, BASE_1 or a similar function)- Returns:
- the stream
-
indexedPairStream
@Nonnull public static <I,T> java.util.stream.Stream<Pair<I,T>> indexedPairStream(@Nonnull java.lang.Iterable<T> iterable, @Nonnull java.util.function.IntFunction<I> indexTransformer)
Returns aStream
out of the elements in a givenIterable
made ofPair
s(index, value)
. The index is transformed with the given function.- Type Parameters:
I
- the type of the transformed indexT
- the type of the elements- Parameters:
iterable
- the iterableindexTransformer
- the transformer of the index- Returns:
- the stream
-
indexedPairStream
@Nonnull public static <I,T> java.util.stream.Stream<Pair<I,T>> indexedPairStream(@Nonnull java.lang.Iterable<T> iterable, @Nonnull java.util.function.IntUnaryOperator rebaser, @Nonnull java.util.function.IntFunction<I> indexTransformer)
Returns aStream
out of the elements returned by an iterable, made ofPair
s(index, value)
. The index is rebased and transformed with specific functions.- Type Parameters:
T
- the type of the elementsI
- the type of the transformed index- Parameters:
iterable
- the iterablerebaser
- the rebaser of the index (BASE_0, BASE_1 or a similar function)indexTransformer
- the transformer of the index- Returns:
- the stream
-
indexedPairStream
@Nonnull public static <T> java.util.stream.Stream<Pair<java.lang.Integer,T>> indexedPairStream(@Nonnegative int from, @Nonnegative int to, @Nonnull java.util.function.IntFunction<T> valueSupplier)
- Type Parameters:
T
- the type of the elements- Parameters:
from
- the first index (included)to
- the last index (excluded)valueSupplier
- the supplier of values- Returns:
- the stream
-
indexedPairStream
@Nonnull public static <T> java.util.stream.Stream<Pair<java.lang.Integer,T>> indexedPairStream(@Nonnegative int from, @Nonnegative int to, @Nonnull java.util.function.IntFunction<T> valueSupplier, @Nonnull java.util.function.IntUnaryOperator rebaser)
- Type Parameters:
T
- the type of the elements- Parameters:
from
- the first index (included)to
- the last index (excluded)valueSupplier
- the supplier of valuesrebaser
- the rebaser of the index (BASE_0, BASE_1 or a similar function)- Returns:
- the stream
-
indexedPairStream
@Nonnull public static <T,I> java.util.stream.Stream<Pair<I,T>> indexedPairStream(@Nonnegative int from, @Nonnegative int to, @Nonnull java.util.function.IntFunction<T> valueSupplier, @Nonnull java.util.function.IntUnaryOperator rebaser, @Nonnull java.util.function.IntFunction<I> indexTransformer)
Returns aStream
out of the elements returned by a supplier, made ofPair
s(index, value)
. The index can be rebased and transformed with specific functions.- Type Parameters:
I
- the type of the transformed indexT
- the type of the elements- Parameters:
from
- the first index (included)to
- the last index (excluded)valueSupplier
- the supplier of valuesrebaser
- the rebaser of the index (BASE_0, BASE_1 or a similar function)indexTransformer
- the transformer of the index- Returns:
- the stream
-
pairsToMap
@Nonnull public static <A,B> java.util.stream.Collector<? super Pair<A,B>,?,java.util.Map<A,B>> pairsToMap()
ACollector
that produces aMap
whose key is fielda
and value fieldb
. Use withStream.collect(Collector)
.- Type Parameters:
A
- the type of the former element of the pairB
- the type of the latter element of the pair- Returns:
- the
Collector
-
-