Class KeyValue<A,B>

java.lang.Object
org.javatuples.Tuple
org.javatuples.KeyValue<A,B>
All Implemented Interfaces:
Serializable, Comparable<Tuple>, Iterable<Object>, IValueKey<A>, IValueValue<B>

public final class KeyValue<A,B> extends Tuple implements IValueKey<A>, IValueValue<B>

A tuple of two elements, with positions 0 and 1 renamed as "key" and "value", respectively.

Since:
1.0
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • SIZE

      private static final int SIZE
      See Also:
    • key

      private final A key
    • value

      private final B value
  • Constructor Details

    • KeyValue

      public KeyValue(A key, B value)
  • Method Details

    • with

      public static <A, B> KeyValue<A,B> with(A key, B value)
    • fromArray

      public static <X> KeyValue<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> KeyValue<X,X> fromCollection(Collection<X> collection)
    • fromIterable

      public static <X> KeyValue<X,X> fromIterable(Iterable<X> iterable)
    • fromIterable

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

      private static <X> KeyValue<X,X> fromIterable(Iterable<X> iterable, int index, boolean exactSize)
    • getKey

      public A getKey()
      Specified by:
      getKey in interface IValueKey<A>
    • getValue

      public B getValue()
      Specified by:
      getValue in interface IValueValue<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.
    • setKey

      public <X> KeyValue<X,B> setKey(X key)
    • setValue

      public <Y> KeyValue<A,Y> setValue(Y value)