Class Pair<F,​S>

  • Type Parameters:
    F - first type
    S - second type
    Direct Known Subclasses:
    SpatialPair

    public class Pair<F,​S>
    extends java.lang.Object
    Simple class wrapping two objects.

    Do not use this for primitive types such as Integer and Double - avoid the memory waste and garbage collection overhead!

    Does not implement any "special" interfaces such as Comparable. If you need more complicated pairs, please use domain specific code, with more meaningful field names and comparators.

    Since:
    0.2
    Author:
    Erich Schubert
    • Field Summary

      Fields 
      Modifier and Type Field Description
      F first
      First value in pair
      S second
      Second value in pair
    • Constructor Summary

      Constructors 
      Constructor Description
      Pair​(F first, S second)
      Initialize pair
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object obj)
      Simple equals statement.
      F getFirst()
      Getter for first
      S getSecond()
      Getter for second element in pair
      int hashCode()
      Canonical hash function, mixing the two hash values.
      void setFirst​(F first)
      Setter for first
      void setSecond​(S second)
      Setter for second
      java.lang.String toString()
      Canonical toString operator
      • Methods inherited from class java.lang.Object

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

      • first

        public F first
        First value in pair
      • second

        public S second
        Second value in pair
    • Constructor Detail

      • Pair

        public Pair​(F first,
                    S second)
        Initialize pair
        Parameters:
        first - first parameter
        second - second parameter
    • Method Detail

      • toString

        public java.lang.String toString()
        Canonical toString operator
        Overrides:
        toString in class java.lang.Object
      • getFirst

        public final F getFirst()
        Getter for first
        Returns:
        first element in pair
      • setFirst

        public final void setFirst​(F first)
        Setter for first
        Parameters:
        first - new value for first element
      • getSecond

        public final S getSecond()
        Getter for second element in pair
        Returns:
        second element in pair
      • setSecond

        public final void setSecond​(S second)
        Setter for second
        Parameters:
        second - new value for second element
      • equals

        public boolean equals​(java.lang.Object obj)
        Simple equals statement.

        This Pair equals another Object if they are identical or if the other Object is also a Pair and the first and second element of this Pair equal the first and second element, respectively, of the other Pair.

        Overrides:
        equals in class java.lang.Object
        Parameters:
        obj - Object to compare to
      • hashCode

        public final int hashCode()
        Canonical hash function, mixing the two hash values.
        Overrides:
        hashCode in class java.lang.Object