Class Pair<A,B>

java.lang.Object
org.jlab.coda.emu.support.data.tuple.Tuple
org.jlab.coda.emu.support.data.tuple.Pair<A,B>
All Implemented Interfaces:
Serializable, Comparable<Tuple>, Iterable<Object>, IValue0<A>, IValue1<B>

public final class Pair<A,B> extends Tuple implements IValue0<A>, IValue1<B>

A tuple of two elements.

Since:
1.0
See Also:
  • Constructor Details

    • Pair

      public Pair(A value0, B value1)
  • Method Details

    • with

      public static <A, B> Pair<A,B> with(A value0, B value1)
    • fromArray

      public static <X> Pair<X,X> fromArray(X[] array)

      Create tuple from array. Array has to have exactly two elements.

      Type Parameters:
      X - the array component type
      Parameters:
      array - the array to be converted to a tuple
      Returns:
      the tuple
    • fromCollection

      public static <X> Pair<X,X> fromCollection(Collection<X> collection)

      Create tuple from collection. Collection has to have exactly two elements.

      Type Parameters:
      X - the collection component type
      Parameters:
      collection - the collection to be converted to a tuple
      Returns:
      the tuple
    • fromIterable

      public static <X> Pair<X,X> fromIterable(Iterable<X> iterable)

      Create tuple from iterable. Iterable has to have exactly two elements.

      Type Parameters:
      X - the iterable component type
      Parameters:
      iterable - the iterable to be converted to a tuple
      Returns:
      the tuple
    • fromIterable

      public static <X> Pair<X,X> fromIterable(Iterable<X> iterable, int index)

      Create tuple from iterable, starting from the specified index. Iterable can have more (or less) elements than the tuple to be created.

      Type Parameters:
      X - the iterable component type
      Parameters:
      iterable - the iterable to be converted to a tuple
      Returns:
      the tuple
    • getValue0

      public A getValue0()
      Specified by:
      getValue0 in interface IValue0<A>
    • getValue1

      public B getValue1()
      Specified by:
      getValue1 in interface IValue1<A>
    • getSize

      public int getSize()
      Description copied from class: Tuple

      Return the size of the tuple.

      Specified by:
      getSize in class Tuple
      Returns:
      the size of the tuple.
    • addAt0

      public <X0> Triplet<X0,A,B> addAt0(X0 value0)
    • addAt1

      public <X0> Triplet<A,X0,B> addAt1(X0 value0)
    • addAt2

      public <X0> Triplet<A,B,X0> addAt2(X0 value0)
    • add

      public <X0> Triplet<A,B,X0> add(X0 value0)
    • setAt0

      public <X> Pair<X,B> setAt0(X value)
    • setAt1

      public <X> Pair<A,X> setAt1(X value)