java.lang.Object
it.tidalwave.util.Pair<A,B>
- Type Parameters:
A
- the type of the former elementB
- the type of the latter element
A value object that contains a pair of values. Some factory methods allow creating pairs out of existing collections or arrays associating an index.
- Since:
- 3.2-ALPHA-6
- Author:
- Fabrizio Giudici
- Status: draft API
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal A
final B
static final IntUnaryOperator
A base 0 index rebaser.static final IntUnaryOperator
A base 1 index rebaser. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionindexedPairStream
(int from, int to, IntFunction<? extends T> valueSupplier) indexedPairStream
(int from, int to, IntFunction<? extends T> valueSupplier, IntUnaryOperator rebaser) indexedPairStream
(int from, int to, IntFunction<? extends T> valueSupplier, IntUnaryOperator rebaser, IntFunction<? extends I> indexTransformer) indexedPairStream
(Iterable<? extends T> iterable) indexedPairStream
(Iterable<? extends T> iterable, IntFunction<? extends I> indexTransformer) indexedPairStream
(Iterable<? extends T> iterable, IntUnaryOperator rebaser) indexedPairStream
(Iterable<? extends T> iterable, IntUnaryOperator rebaser, IntFunction<? extends I> indexTransformer) indexedPairStream
(Stream<? extends T> stream) indexedPairStream
(Stream<? extends T> stream, IntFunction<? extends I> indexTransformer) indexedPairStream
(Stream<? extends T> stream, IntUnaryOperator rebaser) indexedPairStream
(Stream<? extends T> stream, IntUnaryOperator rebaser, IntFunction<? extends I> indexTransformer) indexedPairStream
(T[] array) indexedPairStream
(T[] array, IntFunction<? extends I> indexTransformer) indexedPairStream
(T[] array, IntUnaryOperator rebaser) indexedPairStream
(T[] array, IntUnaryOperator rebaser, IntFunction<? extends I> indexTransformer) static boolean
Returnstrue
if the given pair with an integer member has an even integer.static boolean
Returnstrue
if the given pair with an integer member has an odd integer.pairRange
(T value, int from, int to) Returns a newStream
ofPair
s composed of a given fixed value and an integer in the given range.pairRangeClosed
(T value, int from, int to) Returns a newStream
ofPair
s composed of a given fixed value and an integer in the given range.pairStream
(T value, Stream<? extends U> stream) Returns a new stream ofPair
s created by “zipping” together two existing streams.
-
Field Details
-
BASE_0
A base 0 index rebaser. -
BASE_1
A base 1 index rebaser. -
a
-
b
-
-
Constructor Details
-
Pair
public Pair()
-
-
Method Details
-
pairStream
@Nonnull public static <T,U> Stream<Pair<T,U>> pairStream(@Nonnull T value, @Nonnull Stream<? extends U> stream) -
pairRange
Returns a newStream
ofPair
s composed of a given fixed value and an integer in the given range..- Type Parameters:
T
- the type of the value- Parameters:
value
- the valuefrom
- the first value of the integerStream
(included)to
- the last value of the integerStream
(excluded)- Returns:
- the
Stream
ofPair
s
-
pairRangeClosed
@Nonnull public static <T> Stream<Pair<T,Integer>> pairRangeClosed(@Nonnull T value, int from, int to) Returns a newStream
ofPair
s composed of a given fixed value and an integer in the given range..- Type Parameters:
T
- the type of the value- Parameters:
value
- the valuefrom
- the first value of the integerStream
(included)to
- the last value of the integerStream
(included)- Returns:
- a new
Stream
ofPair
s composed of a given fixed value and an integer in the given range - Since:
- 3.2-ALPHA-12
-
indexedPairStream
-
indexedPairStream
@Nonnull public static <T> Stream<Pair<Integer,T>> indexedPairStream(@Nonnull T[] array, @Nonnull IntUnaryOperator rebaser) -
indexedPairStream
@Nonnull public static <I,T> Stream<Pair<I,T>> indexedPairStream(@Nonnull T[] array, @Nonnull IntFunction<? extends I> indexTransformer) -
indexedPairStream
@Nonnull public static <T,I> Stream<Pair<I,T>> indexedPairStream(@Nonnull T[] array, @Nonnull IntUnaryOperator rebaser, @Nonnull IntFunction<? extends I> indexTransformer) Returns a newStream
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:
- a new
Stream
out of the elements in the array, made ofPair
s(index, value)
-
indexedPairStream
-
indexedPairStream
@Nonnull public static <T> Stream<Pair<Integer,T>> indexedPairStream(@Nonnull Iterable<? extends T> iterable, @Nonnull IntUnaryOperator rebaser) -
indexedPairStream
@Nonnull public static <I,T> Stream<Pair<I,T>> indexedPairStream(@Nonnull Iterable<? extends T> iterable, @Nonnull IntFunction<? extends I> indexTransformer) -
indexedPairStream
@Nonnull public static <I,T> Stream<Pair<I,T>> indexedPairStream(@Nonnull Iterable<? extends T> iterable, @Nonnull IntUnaryOperator rebaser, @Nonnull IntFunction<? extends I> indexTransformer) Returns a newStream
out of the elements returned by an iterable, made ofPair
s(index, value)
.. The index is rebased and transformed with specific functions.- Type Parameters:
I
- the type of the transformed indexT
- the type of the elements- Parameters:
iterable
- the iterablerebaser
- the rebaser of the index (BASE_0, BASE_1 or a similar function)indexTransformer
- the transformer of the index- Returns:
- a new
Stream
out of the elements returned by an iterable, made ofPair
s(index, value)
-
indexedPairStream
-
indexedPairStream
@Nonnull public static <T> Stream<Pair<Integer,T>> indexedPairStream(@Nonnull Stream<? extends T> stream, @Nonnull IntUnaryOperator rebaser) -
indexedPairStream
@Nonnull public static <I,T> Stream<Pair<I,T>> indexedPairStream(@Nonnull Stream<? extends T> stream, @Nonnull IntFunction<? extends I> indexTransformer) -
indexedPairStream
@Nonnull public static <I,T> Stream<Pair<I,T>> indexedPairStream(@Nonnull Stream<? extends T> stream, @Nonnull IntUnaryOperator rebaser, @Nonnull IntFunction<? extends I> indexTransformer) Returns a newStream
out of the elements returned by a Stream, made ofPair
s(index, value)
.. The index is rebased and transformed with specific functions.- Type Parameters:
I
- the type of the transformed indexT
- the type of the elements- Parameters:
stream
- the streamrebaser
- the rebaser of the index (BASE_0
,BASE_1
or a similar function)indexTransformer
- the transformer of the index- Returns:
- a new
Stream
out of the elements returned by a Stream, made ofPair
s(index, value)
- Since:
- 3.2-ALPHA-12
-
indexedPairStream
@Nonnull public static <T> Stream<Pair<Integer,T>> indexedPairStream(int from, int to, @Nonnull IntFunction<? extends T> valueSupplier) -
indexedPairStream
@Nonnull public static <T> Stream<Pair<Integer,T>> indexedPairStream(int from, int to, @Nonnull IntFunction<? extends T> valueSupplier, @Nonnull 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:
- a new
Stream
out of the elements returned by a supplier, made ofPair
s(index, value)
-
indexedPairStream
@Nonnull public static <T,I> Stream<Pair<I,T>> indexedPairStream(int from, int to, @Nonnull IntFunction<? extends T> valueSupplier, @Nonnull IntUnaryOperator rebaser, @Nonnull IntFunction<? extends I> indexTransformer) Returns a newStream
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:
T
- the type of the elementsI
- the type of the transformed index- 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:
- a new
Stream
out of the elements returned by a supplier, made ofPair
s(index, value)
-
pairsToMap
Returns a newCollector
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
-
zip
@Nonnull public static <A,B> Stream<Pair<A,B>> zip(@Nonnull Stream<? extends A> streamA, @Nonnull Stream<? extends B> streamB) Returns a new stream ofPair
s created by “zipping” together two existing streams..- Type Parameters:
A
- the type of elements of the firstStream
B
- the type of elements of the secondStream
- Parameters:
streamA
- the firstStream
streamB
- the secondStream
- Returns:
- a new stream of
Pair
s created by “zipping” together two existing streams - Since:
- 3.2-ALPHA-17 (since 3.2-ALPHA-12 was in
StreamOperations
-
isEven
Returnstrue
if the given pair with an integer member has an even integer..- Parameters:
pair
- the pair- Returns:
true
if the given pair with an integer member has an even integer- Since:
- 5.0-ALPHA-3
- See Also:
-
isOdd
Returnstrue
if the given pair with an integer member has an odd integer..- Parameters:
pair
- the pair- Returns:
true
if the given pair with an integer member has an odd integer- Since:
- 5.0-ALPHA-3
- See Also:
-