Class Pair<L,R>

java.lang.Object
org.sklsft.commons.api.model.Pair<L,R>
Type Parameters:
L - the left element type
R - the right element type
All Implemented Interfaces:
Serializable, Map.Entry<L,R>

public class Pair<L,R> extends Object implements Map.Entry<L,R>, Serializable

A pair consisting of two elements.

This class is an abstract implementation defining the basic API. It refers to the elements as 'left' and 'right'. It also implements the Map.Entry interface where the key is 'left' and the value is 'right'.

Author:
Jerome RANCATI
See Also:
  • Constructor Details

    • Pair

      public Pair(L left, R right)
    • Pair

      public Pair()
  • Method Details

    • getLeft

      public L getLeft()
    • setLeft

      public void setLeft(L left)
    • getRight

      public R getRight()
    • setRight

      public void setRight(R right)
    • getKey

      public final L getKey()
      Specified by:
      getKey in interface Map.Entry<L,R>
    • getValue

      public R getValue()
      Specified by:
      getValue in interface Map.Entry<L,R>
    • setValue

      public R setValue(R right)
      Specified by:
      setValue in interface Map.Entry<L,R>
    • of

      public Pair<L,R> of(L left, R right)
    • toString

      public String toString()

      Returns a String representation of this pair using the format ($left,$right).

      Overrides:
      toString in class Object
      Returns:
      a string describing this object, not null
    • equals

      public boolean equals(Object obj)
      Specified by:
      equals in interface Map.Entry<L,R>
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()

      Returns a suitable hash code. The hash code follows the definition in Map.Entry.

      Specified by:
      hashCode in interface Map.Entry<L,R>
      Overrides:
      hashCode in class Object
      Returns:
      the hash code
    • toString

      public String toString(String format)

      Formats the receiver using the given format.

      This uses Formattable to perform the formatting. Two variables may be used to embed the left and right elements. Use %1$s for the left element (key) and %2$s for the right element (value). The default format used by toString() is (%1$s,%2$s).

      Parameters:
      format - the format string, optionally containing %1$s and %2$s, not null
      Returns:
      the formatted string, not null