Class Tuple2<T1,T2>

java.lang.Object
reactor.util.function.Tuple2<T1,T2>
Type Parameters:
T1 - The type of the first non-null value held by this tuple
T2 - The type of the second non-null value held by this tuple
All Implemented Interfaces:
Serializable, Iterable<Object>
Direct Known Subclasses:
Tuple3

public class Tuple2<T1,T2> extends Object implements Iterable<Object>, Serializable
A tuple that holds two non-null values.
Author:
Jon Brisbin, Stephane Maldini
See Also:
  • Method Details

    • getT1

      public T1 getT1()
      Type-safe way to get the first object of this Tuples.
      Returns:
      The first object
    • getT2

      public T2 getT2()
      Type-safe way to get the second object of this Tuples.
      Returns:
      The second object
    • mapT1

      public <R> Tuple2<R,T2> mapT1(Function<T1,R> mapper)
      Map the left-hand part (T1) of this Tuple2 into a different value and type, keeping the right-hand part (T2).
      Type Parameters:
      R - the new type for the left-hand part
      Parameters:
      mapper - the mapping Function for the left-hand part
      Returns:
      a new Tuple2 with a different left (T1) value
    • mapT2

      public <R> Tuple2<T1,R> mapT2(Function<T2,R> mapper)
      Map the right-hand part (T2) of this Tuple2 into a different value and type, keeping the left-hand part (T1).
      Type Parameters:
      R - the new type for the right-hand part
      Parameters:
      mapper - the mapping Function for the right-hand part
      Returns:
      a new Tuple2 with a different right (T2) value
    • get

      public @Nullable Object get(int index)
      Get the object at the given index.
      Parameters:
      index - The index of the object to retrieve. Starts at 0.
      Returns:
      The object or null if out of bounds.
    • toList

      public List<Object> toList()
      Turn this Tuple into a List<Object>. The list isn't tied to this Tuple but is a copy with limited mutability (add and remove are not supported, but set is).
      Returns:
      A copy of the tuple as a new List<Object>.
    • toArray

      public Object[] toArray()
      Turn this Tuple into a plain Object[]. The array isn't tied to this Tuple but is a copy.
      Returns:
      A copy of the tuple as a new Object[].
    • iterator

      public Iterator<Object> iterator()
      Return an immutable Iterator<Object> around the content of this Tuple.
      Specified by:
      iterator in interface Iterable<T1>
      Returns:
      An unmodifiable Iterator over the elements in this Tuple.
      Implementation Note:
      As an Iterator is always tied to its Iterable source by definition, the iterator cannot be mutable without the iterable also being mutable. Since Tuples are immutable, so is the Iterator returned by this method.
    • equals

      public boolean equals(@Nullable Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • size

      public int size()
      Return the number of elements in this Tuples.
      Returns:
      The size of this Tuples.
    • toString

      public final String toString()
      A Tuple String representation is the comma separated list of values, enclosed in square brackets.
      Overrides:
      toString in class Object
      Returns:
      the Tuple String representation