Package libai.common

Class Pair<V extends java.lang.Comparable<V>,K>

  • All Implemented Interfaces:
    java.lang.Comparable<Pair<V,K>>

    public final class Pair<V extends java.lang.Comparable<V>,K>
    extends java.lang.Object
    implements java.lang.Comparable<Pair<V,K>>
    Pair class allows to keep two elements of possibly different types in the same structure and can be used for keep pairs key-value.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      V first
      First element of the pair (the 'key').
      K second
      Second element of the pair (the 'value').
    • Constructor Summary

      Constructors 
      Constructor Description
      Pair​(V x, K y)
      Constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compareTo​(Pair<V,K> o)
      Compare two pairs by the first element.
      boolean equals​(java.lang.Object obj)  
      int hashCode()  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

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

      • first

        public V extends java.lang.Comparable<V> first
        First element of the pair (the 'key').
      • second

        public K second
        Second element of the pair (the 'value').
    • Constructor Detail

      • Pair

        public Pair​(V x,
                    K y)
        Constructor.
        Parameters:
        x - the first element for the pair.
        y - the second element for the pair.
    • Method Detail

      • compareTo

        public int compareTo​(Pair<V,K> o)
        Compare two pairs by the first element. The first element type must implement the Comparable interface.
        Specified by:
        compareTo in interface java.lang.Comparable<V extends java.lang.Comparable<V>>
        Parameters:
        o - The pair to compare with.
        Returns:
        -1 if this is less than o, 0 if are equals, 1 if this is greater than o.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object