Class PairImpl<T1,​T2>

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<Pair<T1,​T2>>, Pair<T1,​T2>
    Direct Known Subclasses:
    TwinImpl

    class PairImpl<T1,​T2>
    extends java.lang.Object
    implements Pair<T1,​T2>
    A PairImpl is a container that holds two related objects. It is the equivalent of an Association in Smalltalk, or an implementation of Map.Entry in the JDK.
    • Field Detail

      • one

        private final T1 one
      • two

        private final T2 two
    • Constructor Detail

      • PairImpl

        PairImpl​(T1 newOne,
                 T2 newTwo)
    • Method Detail

      • getOne

        public T1 getOne()
        Specified by:
        getOne in interface Pair<T1,​T2>
      • getTwo

        public T2 getTwo()
        Specified by:
        getTwo in interface Pair<T1,​T2>
      • put

        public void put​(java.util.Map<? super T1,​? super T2> map)
        Specified by:
        put in interface Pair<T1,​T2>
      • swap

        public PairImpl<T2,​T1> swap()
        Description copied from interface: Pair
        Method used to swap the elements of pair.
        e.g.
         Pair<String, Integer> pair = Tuples.pair("One", 1);
         Pair<Integer, String> swappedPair = pair.swap();
         
        Specified by:
        swap in interface Pair<T1,​T2>
      • 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
      • toString

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

        public java.util.Map.Entry<T1,​T2> toEntry()
        Specified by:
        toEntry in interface Pair<T1,​T2>
      • compareTo

        public int compareTo​(Pair<T1,​T2> other)
        Specified by:
        compareTo in interface java.lang.Comparable<T1>