Class Pair<A,B>

java.lang.Object
it.tidalwave.util.Pair<A,B>
Type Parameters:
A - the type of the former element
B - the type of the latter element

public class Pair<A,B> extends Object
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 Details

    • BASE_0

      public static final IntUnaryOperator BASE_0
      A base 0 index rebaser.
    • BASE_1

      public static final IntUnaryOperator BASE_1
      A base 1 index rebaser.
    • a

      @Nonnull public final A a
    • b

      @Nonnull public final B 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)
      Returns a new Stream of Pairs composed of a given fixed value and another element taken from another Stream..
      Type Parameters:
      T - the type of the value
      U - the type of the Stream
      Parameters:
      value - the value
      stream - the Stream
      Returns:
      a new Stream of Pairs composed of a given fixed value and another element taken from another Stream
      Since:
      3.2-ALPHA-12
    • pairRange

      @Nonnull public static <T> Stream<Pair<T,Integer>> pairRange(@Nonnull T value, int from, int to)
      Returns a new Stream of Pairs composed of a given fixed value and an integer in the given range..
      Type Parameters:
      T - the type of the value
      Parameters:
      value - the value
      from - the first value of the integer Stream (included)
      to - the last value of the integer Stream (excluded)
      Returns:
      the Stream of Pairs
    • pairRangeClosed

      @Nonnull public static <T> Stream<Pair<T,Integer>> pairRangeClosed(@Nonnull T value, int from, int to)
      Returns a new Stream of Pairs composed of a given fixed value and an integer in the given range..
      Type Parameters:
      T - the type of the value
      Parameters:
      value - the value
      from - the first value of the integer Stream (included)
      to - the last value of the integer Stream (included)
      Returns:
      a new Stream of Pairs composed of a given fixed value and an integer in the given range
      Since:
      3.2-ALPHA-12
    • indexedPairStream

      @Nonnull public static <T> Stream<Pair<Integer,T>> indexedPairStream(@Nonnull T[] array)
      Returns a new Stream out of the elements in a given array made of Pairs (index, value)..
      Type Parameters:
      T - the type of the elements
      Parameters:
      array - the array
      Returns:
      a new Stream out of the elements in a given array made of Pairs (index, value)
      See Also:
    • indexedPairStream

      @Nonnull public static <T> Stream<Pair<Integer,T>> indexedPairStream(@Nonnull T[] array, @Nonnull IntUnaryOperator rebaser)
      Returns a new Stream out of the elements in the array, made of Pairs (index, value).. The index can be rebased.
      Type Parameters:
      T - the type of the elements
      Parameters:
      array - the array
      rebaser - the rebaser of the index (BASE_0, BASE_1 or a similar function)
      Returns:
      a new Stream out of the elements in the array, made of Pairs (index, value)
      See Also:
    • indexedPairStream

      @Nonnull public static <I, T> Stream<Pair<I,T>> indexedPairStream(@Nonnull T[] array, @Nonnull IntFunction<? extends I> indexTransformer)
      Returns a new Stream out of the elements in a given array made of Pairs (index, value).. The index is transformed with the given function.
      Type Parameters:
      I - the type of the transformed index
      T - the type of the elements
      Parameters:
      array - the array
      indexTransformer - the transformer of the index
      Returns:
      a new Stream out of the elements in a given array made of Pairs (index, value)
    • indexedPairStream

      @Nonnull public static <T, I> Stream<Pair<I,T>> indexedPairStream(@Nonnull T[] array, @Nonnull IntUnaryOperator rebaser, @Nonnull IntFunction<? extends I> indexTransformer)
      Returns a new Stream out of the elements in the array, made of Pairs (index, value).. The index can be rebased and transformed with specific functions.
      Type Parameters:
      T - the type of the elements
      I - the type of the transformed index
      Parameters:
      array - the array
      rebaser - 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 of Pairs (index, value)
    • indexedPairStream

      @Nonnull public static <T> Stream<Pair<Integer,T>> indexedPairStream(@Nonnull Iterable<? extends T> iterable)
      Returns a new Stream out of the elements in a given Iterable made of Pairs (index, value)..
      Type Parameters:
      T - the type of the elements
      Parameters:
      iterable - the iterable
      Returns:
      a new Stream out of the elements in a given Iterable made of Pairs (index, value)
      See Also:
    • indexedPairStream

      @Nonnull public static <T> Stream<Pair<Integer,T>> indexedPairStream(@Nonnull Iterable<? extends T> iterable, @Nonnull IntUnaryOperator rebaser)
      Returns a new Stream out of the elements in a given Iterable made of Pairs (index, value).. The index can be rebased.
      Type Parameters:
      T - the type of the elements
      Parameters:
      iterable - the iterable
      rebaser - the rebaser of the index (BASE_0, BASE_1 or a similar function)
      Returns:
      a new Stream out of the elements in a given Iterable made of Pairs (index, value)
      See Also:
    • indexedPairStream

      @Nonnull public static <I, T> Stream<Pair<I,T>> indexedPairStream(@Nonnull Iterable<? extends T> iterable, @Nonnull IntFunction<? extends I> indexTransformer)
      Returns a new Stream out of the elements in a given Iterable made of Pairs (index, value).. The index is transformed with the given function.
      Type Parameters:
      I - the type of the transformed index
      T - the type of the elements
      Parameters:
      iterable - the iterable
      indexTransformer - the transformer of the index
      Returns:
      a new Stream out of the elements in a given Iterable made of Pairs (index, value)
    • 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 new Stream out of the elements returned by an iterable, made of Pairs (index, value).. The index is rebased and transformed with specific functions.
      Type Parameters:
      I - the type of the transformed index
      T - the type of the elements
      Parameters:
      iterable - the iterable
      rebaser - 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 of Pairs (index, value)
    • indexedPairStream

      @Nonnull public static <T> Stream<Pair<Integer,T>> indexedPairStream(@Nonnull Stream<? extends T> stream)
      Returns a new Stream out of the elements in a given Stream made of Pairs (index, value)..
      Type Parameters:
      T - the type of the elements
      Parameters:
      stream - the stream
      Returns:
      a new Stream out of the elements in a given Stream made of Pairs (index, value)
      Since:
      3.2-ALPHA-12
    • indexedPairStream

      @Nonnull public static <T> Stream<Pair<Integer,T>> indexedPairStream(@Nonnull Stream<? extends T> stream, @Nonnull IntUnaryOperator rebaser)
      Returns a new Stream out of the elements in a given Stream made of Pairs (index, value).. The index can be rebased.
      Type Parameters:
      T - the type of the elements
      Parameters:
      stream - the stream
      rebaser - the rebaser of the index (BASE_0, BASE_1 or a similar function)
      Returns:
      a new Stream out of the elements in a given Stream made of Pairs (index, value)
      Since:
      3.2-ALPHA-12
    • indexedPairStream

      @Nonnull public static <I, T> Stream<Pair<I,T>> indexedPairStream(@Nonnull Stream<? extends T> stream, @Nonnull IntFunction<? extends I> indexTransformer)
      Returns a new Stream out of the elements in a given Stream made of Pairs (index, value).. The index is transformed with the given function.
      Type Parameters:
      I - the type of the transformed index
      T - the type of the elements
      Parameters:
      stream - the stream
      indexTransformer - the transformer of the index
      Returns:
      a new Stream out of the elements in a given Stream made of Pairs (index, value)
      Since:
      3.2-ALPHA-12
    • 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 new Stream out of the elements returned by a Stream, made of Pairs (index, value).. The index is rebased and transformed with specific functions.
      Type Parameters:
      I - the type of the transformed index
      T - the type of the elements
      Parameters:
      stream - the stream
      rebaser - 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 of Pairs (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)
      Returns a new Stream out of the elements returned by a supplier, made of Pairs (index, value)..
      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:
      a new Stream out of the elements returned by a supplier, made of Pairs (index, value)
    • indexedPairStream

      @Nonnull public static <T> Stream<Pair<Integer,T>> indexedPairStream(int from, int to, @Nonnull IntFunction<? extends T> valueSupplier, @Nonnull IntUnaryOperator rebaser)
      Returns a new Stream out of the elements returned by a supplier, made of Pairs (index, value)..
      Type Parameters:
      T - the type of the elements
      Parameters:
      from - the first index (included)
      to - the last index (excluded)
      valueSupplier - the supplier of values
      rebaser - 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 of Pairs (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 new Stream out of the elements returned by a supplier, made of Pairs (index, value).. The index can be rebased and transformed with specific functions.
      Type Parameters:
      T - the type of the elements
      I - the type of the transformed index
      Parameters:
      from - the first index (included)
      to - the last index (excluded)
      valueSupplier - the supplier of values
      rebaser - 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 of Pairs (index, value)
    • pairsToMap

      @Nonnull public static <A, B> Collector<Pair<A,B>,?,Map<A,B>> pairsToMap()
      Returns a new Collector that produces a Map whose key is field a and value field b.. Use with Stream.collect(Collector).
      Type Parameters:
      A - the type of the former element of the pair
      B - 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 of Pairs created by “zipping” together two existing streams..
      Type Parameters:
      A - the type of elements of the first Stream
      B - the type of elements of the second Stream
      Parameters:
      streamA - the first Stream
      streamB - the second Stream
      Returns:
      a new stream of Pairs created by “zipping” together two existing streams
      Since:
      3.2-ALPHA-17 (since 3.2-ALPHA-12 was in StreamOperations
    • isEven

      public static boolean isEven(@Nonnull Pair<Integer,?> pair)
      Returns true 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

      public static boolean isOdd(@Nonnull Pair<Integer,?> pair)
      Returns true 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: