Class Pair<A,​B>

  • Type Parameters:
    A - the first element type
    B - the second element type
    All Implemented Interfaces:
    java.io.Serializable
    Direct Known Subclasses:
    UnorderedPair

    public class Pair<A,​B>
    extends java.lang.Object
    implements java.io.Serializable
    Generic pair.
    See Also:
    Serialized Form
    • Field Summary

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

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

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object o)  
      A getFirst()
      Get the first element of the pair
      B getSecond()
      Get the second element of the pair
      <E> boolean hasElement​(E e)
      Assess if this pair contains an element.
      int hashCode()  
      static <A,​B>
      Pair<A,​B>
      of​(A a, B b)
      Create a new pair.
      void setFirst​(A f)
      Set the first element of the pair.
      void setSecond​(B s)
      Set the second element of the pair.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

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

      • first

        protected A first
        The first pair element
      • second

        protected B second
        The second pair element
    • Constructor Detail

      • Pair

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

      • 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 java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.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