Class Pair<A,​B>

  • Type Parameters:
    A - the first value type
    B - the second value type
    All Implemented Interfaces:
    java.io.Serializable

    @Externalize(Externalizer.class)
    public final class Pair<A,​B>
    extends java.lang.Object
    implements java.io.Serializable
    A serializable pair of values. There is also a specified externalizer as well, to support more efficient I/O.
    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Pair.Externalizer
      An externalizer for Pair instances.
    • Constructor Summary

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

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static <A,​B>
      Pair<A,​B>
      create​(A a, B b)
      Create a new instance.
      boolean equals​(java.lang.Object other)
      Determine if this pair equals another.
      boolean equals​(Pair<?,​?> other)
      Determine if this pair equals another.
      A getA()
      Get the first value.
      B getB()
      Get the second value.
      int hashCode()
      Return the combined hash code of the two argument objects.
      private static int hashCode​(java.lang.Object a, java.lang.Object b)
      Calculate the combined hash code of two objects.
      private void readObject​(java.io.ObjectInputStream ois)
      Reinitialize the object and set the hash code.
      java.lang.String toString()
      Get a string representation of this pair.
      • Methods inherited from class java.lang.Object

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

      • a

        private final A a
      • b

        private final B b
      • hashCode

        private final transient int hashCode
    • Constructor Detail

      • Pair

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

      • hashCode

        private static int hashCode​(java.lang.Object a,
                                    java.lang.Object b)
        Calculate the combined hash code of two objects.
        Parameters:
        a - the first object
        b - the second object
        Returns:
        the combined hash code
      • getA

        public A getA()
        Get the first value.
        Returns:
        the first value
      • getB

        public B getB()
        Get the second value.
        Returns:
        the second value
      • readObject

        private void readObject​(java.io.ObjectInputStream ois)
                         throws java.io.IOException,
                                java.lang.ClassNotFoundException
        Reinitialize the object and set the hash code.
        Parameters:
        ois - the object input stream
        Throws:
        java.io.IOException - if an I/O error occurs while reading the default fields
        java.lang.ClassNotFoundException - if a class isn't found while reading the default fields
      • hashCode

        public int hashCode()
        Return the combined hash code of the two argument objects.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        the combined hash code
      • equals

        public boolean equals​(java.lang.Object other)
        Determine if this pair equals another. A pair is equal to another pair if both members are equal.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        other - the other pair
        Returns:
        true if they are equal, false otherwise
      • equals

        public boolean equals​(Pair<?,​?> other)
        Determine if this pair equals another. A pair is equal to another pair if both members are equal.
        Parameters:
        other - the other pair
        Returns:
        true if they are equal, false otherwise
      • toString

        public java.lang.String toString()
        Get a string representation of this pair.
        Overrides:
        toString in class java.lang.Object
        Returns:
        the string representation
      • create

        public static <A,​B> Pair<A,​B> create​(A a,
                                                         B b)
        Create a new instance.
        Type Parameters:
        A - the first value type
        B - the second value type
        Parameters:
        a - the first value
        b - the second value
        Returns:
        the new instance