Class Pair<A,B>

java.lang.Object
org.jgrapht.alg.util.Pair<A,B>
Type Parameters:
A - the first element type
B - the second element type
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
UnorderedPair

public class Pair<A,B> extends Object implements Serializable
Generic pair.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected A
    The first pair element
    protected B
    The second pair element
  • Constructor Summary

    Constructors
    Constructor
    Description
    Pair(A a, B b)
    Create a new pair
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    Get the first element of the pair
    Get the second element of the pair
    <E> boolean
    Assess if this pair contains an element.
    int
     
    static <A, B> Pair<A,B>
    of(A a, B b)
    Create a new pair.
    void
    Set the first element of the pair.
    void
    Set the second element of the pair.
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • first

      protected A first
      The first pair element
    • second

      protected B second
      The second pair element
  • Constructor Details

    • Pair

      public Pair(A a, B b)
      Create a new pair
      Parameters:
      a - the first element
      b - the second element
  • Method Details

    • getFirst

      public A getFirst()
      Get the first element of the pair
      Returns:
      the first element of the pair
    • getSecond

      public B getSecond()
      Get the second element of the pair
      Returns:
      the second element of the pair
    • setFirst

      public void setFirst(A f)
      Set the first element of the pair.
      Parameters:
      f - the element to be assigned.
    • setSecond

      public void setSecond(B s)
      Set the second element of the pair.
      Parameters:
      s - the element to be assigned.
    • hasElement

      public <E> boolean hasElement(E e)
      Assess if this pair contains an element.
      Type Parameters:
      E - the element type
      Parameters:
      e - The element in question
      Returns:
      true if contains the element, false otherwise
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

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

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

      public static <A, B> Pair<A,B> of(A a, B b)
      Create a new pair.
      Type Parameters:
      A - the first element type
      B - the second element type
      Parameters:
      a - first element
      b - second element
      Returns:
      new pair