001 002package gudusoft.gsqlparser.dlineage.util; 003 004/** 005 * Container to ease passing around a tuple of two objects. This object provides 006 * a sensible implementation of equals(), returning true if equals() is true on 007 * each of the contained objects. 008 */ 009public class Pair3<F, S, T> { 010 011 public final F first; 012 public final S second; 013 public final T third; 014 015 /** 016 * Constructor for a Pair. 017 * 018 * @param first the first object in the Pair 019 * @param second the second object in the pair 020 */ 021 public Pair3(F first, S second, T third) { 022 this.first = first; 023 this.second = second; 024 this.third = third; 025 } 026 027 /** 028 * Checks the two objects for equality by delegating to their respective 029 * {@link Object#equals(Object)} methods. 030 * 031 * @param o the {@link Pair3} to which this one is to be checked for 032 * equality 033 * @return true if the underlying objects of the Pair are both considered 034 * equal 035 */ 036 @Override 037 public boolean equals(Object o) { 038 if (!(o instanceof Pair3)) { 039 return false; 040 } 041 Pair3<?, ?, ?> p = (Pair3<?, ?, ?>) o; 042 return Objects.equal(p.first, first) 043 && Objects.equal(p.second, second) 044 && Objects.equal(p.third, third); 045 } 046 047 /** 048 * Compute a hash code using the hash codes of the underlying objects 049 * 050 * @return a hashcode of the Pair 051 */ 052 @Override 053 public int hashCode() { 054 return ((first == null ? 0 : first.hashCode()) 055 ^ (second == null ? 0 : second.hashCode())) 056 ^ (third == null ? 0 : third.hashCode()); 057 } 058 059 /** 060 * Convenience method for creating an appropriately typed pair. 061 * 062 * @param a the first object in the Pair 063 * @param b the second object in the pair 064 * @return a Pair that is templatized with the types of a and b 065 */ 066 public static <A, B, C> Pair3<A, B, C> create(A a, B b, C c) { 067 return new Pair3<A, B, C>(a, b, c); 068 } 069 070 public String toString() { 071 if(third!=null){ 072 return "[" + first + "," + second + "," + third + "]"; 073 } 074 else{ 075 return "[" + first + "," + second + "]"; 076 } 077 } 078}