Class 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 creating pairs out of existing collections or arrays associating an index.
    Since:
    3.2-ALPHA-6
    Author:
    Fabrizio Giudici
    Status: draft API
    • Field Summary

      Fields 
      Modifier and Type Field Description
      A a  
      B b  
      static java.util.function.IntUnaryOperator BASE_0
      A base 0 index rebaser.
      static java.util.function.IntUnaryOperator BASE_1
      A base 1 index rebaser.
    • 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<? extends T> valueSupplier)
      Returns a Stream out of the elements returned by a supplier, made of Pairs (index, value).
      static <T> java.util.stream.Stream<Pair<java.lang.Integer,​T>> indexedPairStream​(int from, int to, java.util.function.IntFunction<? extends T> valueSupplier, java.util.function.IntUnaryOperator rebaser)
      Returns a Stream out of the elements returned by a supplier, made of Pairs (index, value).
      static <T,​I>
      java.util.stream.Stream<Pair<I,​T>>
      indexedPairStream​(int from, int to, java.util.function.IntFunction<? extends T> valueSupplier, java.util.function.IntUnaryOperator rebaser, java.util.function.IntFunction<? extends I> indexTransformer)
      Returns a Stream out of the elements returned by a supplier, made of Pairs (index, value).
      static <T> java.util.stream.Stream<Pair<java.lang.Integer,​T>> indexedPairStream​(java.lang.Iterable<? extends T> iterable)
      Returns a Stream out of the elements in a given Iterable made of Pairs (index, value).
      static <I,​T>
      java.util.stream.Stream<Pair<I,​T>>
      indexedPairStream​(java.lang.Iterable<? extends T> iterable, java.util.function.IntFunction<? extends I> indexTransformer)
      Returns a Stream out of the elements in a given Iterable made of Pairs (index, value).
      static <T> java.util.stream.Stream<Pair<java.lang.Integer,​T>> indexedPairStream​(java.lang.Iterable<? extends T> iterable, java.util.function.IntUnaryOperator rebaser)
      Returns a Stream out of the elements in a given Iterable made of Pairs (index, value).
      static <I,​T>
      java.util.stream.Stream<Pair<I,​T>>
      indexedPairStream​(java.lang.Iterable<? extends T> iterable, java.util.function.IntUnaryOperator rebaser, java.util.function.IntFunction<? extends I> indexTransformer)
      Returns a Stream out of the elements returned by an iterable, made of Pairs (index, value).
      static <T> java.util.stream.Stream<Pair<java.lang.Integer,​T>> indexedPairStream​(java.util.stream.Stream<? extends T> stream)
      Returns a Stream out of the elements in a given Stream made of Pairs (index, value).
      static <I,​T>
      java.util.stream.Stream<Pair<I,​T>>
      indexedPairStream​(java.util.stream.Stream<? extends T> stream, java.util.function.IntFunction<? extends I> indexTransformer)
      Returns a Stream out of the elements in a given Stream made of Pairs (index, value).
      static <T> java.util.stream.Stream<Pair<java.lang.Integer,​T>> indexedPairStream​(java.util.stream.Stream<? extends T> stream, java.util.function.IntUnaryOperator rebaser)
      Returns a Stream out of the elements in a given Stream made of Pairs (index, value).
      static <I,​T>
      java.util.stream.Stream<Pair<I,​T>>
      indexedPairStream​(java.util.stream.Stream<? extends T> stream, java.util.function.IntUnaryOperator rebaser, java.util.function.IntFunction<? extends I> indexTransformer)
      Returns a Stream out of the elements returned by a Stream, made of Pairs (index, value).
      static <T> java.util.stream.Stream<Pair<java.lang.Integer,​T>> indexedPairStream​(T[] array)
      Returns a Stream out of the elements in a given array made of Pairs (index, value).
      static <I,​T>
      java.util.stream.Stream<Pair<I,​T>>
      indexedPairStream​(T[] array, java.util.function.IntFunction<? extends I> indexTransformer)
      Returns a Stream out of the elements in a given array made of Pairs (index, value).
      static <T> java.util.stream.Stream<Pair<java.lang.Integer,​T>> indexedPairStream​(T[] array, java.util.function.IntUnaryOperator rebaser)
      Returns a Stream out of the elements in the array, made of Pairs (index, value).
      static <T,​I>
      java.util.stream.Stream<Pair<I,​T>>
      indexedPairStream​(T[] array, java.util.function.IntUnaryOperator rebaser, java.util.function.IntFunction<? extends I> indexTransformer)
      Returns a Stream out of the elements in the array, made of Pairs (index, value).
      static <T> java.util.stream.Stream<Pair<T,​java.lang.Integer>> pairRange​(T value, int from, int to)
      Creates a Stream of Pairs composed of a given fixed value and an integer in the given range.
      static <T> java.util.stream.Stream<Pair<T,​java.lang.Integer>> pairRangeClosed​(T value, int from, int to)
      Creates a Stream of Pairs composed of a given fixed value and an integer in the given range.
      static <A,​B>
      java.util.stream.Collector<Pair<A,​B>,​?,​java.util.Map<A,​B>>
      pairsToMap()
      A Collector that produces a Map whose key is field a and value field b.
      static <T,​U>
      java.util.stream.Stream<Pair<T,​U>>
      pairStream​(T value, java.util.stream.Stream<? extends U> stream)
      Creates a Stream of Pairs composed of a given fixed value and another element taken from another Stream.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • BASE_0

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

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

        @Nonnull
        public final A a
      • b

        @Nonnull
        public final B b
    • Constructor Detail

      • Pair

        public Pair()
    • Method Detail

      • pairStream

        @Nonnull
        public static <T,​U> java.util.stream.Stream<Pair<T,​U>> pairStream​(@Nonnull
                                                                                      T value,
                                                                                      @Nonnull
                                                                                      java.util.stream.Stream<? extends U> stream)
        Creates a 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:
        the Stream of Pairs
        Since:
        3.2-ALPHA-12
      • pairRange

        @Nonnull
        public static <T> java.util.stream.Stream<Pair<T,​java.lang.Integer>> pairRange​(@Nonnull
                                                                                             T value,
                                                                                             @Nonnegative
                                                                                             int from,
                                                                                             @Nonnegative
                                                                                             int to)
        Creates a 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
        Since:
        3.2-ALPHA-12
      • pairRangeClosed

        @Nonnull
        public static <T> java.util.stream.Stream<Pair<T,​java.lang.Integer>> pairRangeClosed​(@Nonnull
                                                                                                   T value,
                                                                                                   @Nonnegative
                                                                                                   int from,
                                                                                                   @Nonnegative
                                                                                                   int to)
        Creates a 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:
        the Stream of Pairs
        Since:
        3.2-ALPHA-12
      • indexedPairStream

        @Nonnull
        public static <T> java.util.stream.Stream<Pair<java.lang.Integer,​T>> indexedPairStream​(@Nonnull
                                                                                                     T[] array)
        Returns a 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:
        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 a 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:
        the stream
      • indexedPairStream

        @Nonnull
        public static <I,​T> java.util.stream.Stream<Pair<I,​T>> indexedPairStream​(@Nonnull
                                                                                             T[] array,
                                                                                             @Nonnull
                                                                                             java.util.function.IntFunction<? extends I> indexTransformer)
        Returns a 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:
        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<? extends I> indexTransformer)
        Returns a 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:
        the stream
      • indexedPairStream

        @Nonnull
        public static <T> java.util.stream.Stream<Pair<java.lang.Integer,​T>> indexedPairStream​(@Nonnull
                                                                                                     java.lang.Iterable<? extends T> iterable)
        Returns a 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:
        the stream
      • indexedPairStream

        @Nonnull
        public static <T> java.util.stream.Stream<Pair<java.lang.Integer,​T>> indexedPairStream​(@Nonnull
                                                                                                     java.lang.Iterable<? extends T> iterable,
                                                                                                     @Nonnull
                                                                                                     java.util.function.IntUnaryOperator rebaser)
        Returns a 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:
        the stream
      • indexedPairStream

        @Nonnull
        public static <I,​T> java.util.stream.Stream<Pair<I,​T>> indexedPairStream​(@Nonnull
                                                                                             java.lang.Iterable<? extends T> iterable,
                                                                                             @Nonnull
                                                                                             java.util.function.IntFunction<? extends I> indexTransformer)
        Returns a 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:
        the stream
      • indexedPairStream

        @Nonnull
        public static <I,​T> java.util.stream.Stream<Pair<I,​T>> indexedPairStream​(@Nonnull
                                                                                             java.lang.Iterable<? extends T> iterable,
                                                                                             @Nonnull
                                                                                             java.util.function.IntUnaryOperator rebaser,
                                                                                             @Nonnull
                                                                                             java.util.function.IntFunction<? extends I> indexTransformer)
        Returns a 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:
        T - the type of the elements
        I - the type of the transformed index
        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:
        the stream
      • indexedPairStream

        @Nonnull
        public static <T> java.util.stream.Stream<Pair<java.lang.Integer,​T>> indexedPairStream​(@Nonnull
                                                                                                     java.util.stream.Stream<? extends T> stream)
        Returns a 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:
        the stream
        Since:
        3.2-ALPHA-12
      • indexedPairStream

        @Nonnull
        public static <T> java.util.stream.Stream<Pair<java.lang.Integer,​T>> indexedPairStream​(@Nonnull
                                                                                                     java.util.stream.Stream<? extends T> stream,
                                                                                                     @Nonnull
                                                                                                     java.util.function.IntUnaryOperator rebaser)
        Returns a 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:
        the stream
        Since:
        3.2-ALPHA-12
      • indexedPairStream

        @Nonnull
        public static <I,​T> java.util.stream.Stream<Pair<I,​T>> indexedPairStream​(@Nonnull
                                                                                             java.util.stream.Stream<? extends T> stream,
                                                                                             @Nonnull
                                                                                             java.util.function.IntFunction<? extends I> indexTransformer)
        Returns a 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:
        the stream
        Since:
        3.2-ALPHA-12
      • indexedPairStream

        @Nonnull
        public static <I,​T> java.util.stream.Stream<Pair<I,​T>> indexedPairStream​(@Nonnull
                                                                                             java.util.stream.Stream<? extends T> stream,
                                                                                             @Nonnull
                                                                                             java.util.function.IntUnaryOperator rebaser,
                                                                                             @Nonnull
                                                                                             java.util.function.IntFunction<? extends I> indexTransformer)
        Returns a 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:
        T - the type of the elements
        I - the type of the transformed index
        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:
        the stream
        Since:
        3.2-ALPHA-12
      • 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<? extends T> valueSupplier)
        Returns a 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:
        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<? extends T> valueSupplier,
                                                                                                     @Nonnull
                                                                                                     java.util.function.IntUnaryOperator rebaser)
        Returns a 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:
        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<? extends T> valueSupplier,
                                                                                             @Nonnull
                                                                                             java.util.function.IntUnaryOperator rebaser,
                                                                                             @Nonnull
                                                                                             java.util.function.IntFunction<? extends I> indexTransformer)
        Returns a 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:
        I - the type of the transformed index
        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)
        indexTransformer - the transformer of the index
        Returns:
        the stream
      • pairsToMap

        @Nonnull
        public static <A,​B> java.util.stream.Collector<Pair<A,​B>,​?,​java.util.Map<A,​B>> pairsToMap()
        A 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