1package org.testng.internal.collections; 2 3import org.testng.collections.Objects; 4 5 6 7 8 9public class Pair<A, B> { 10 private final A first; 11 private final B second; 12 13 public Pair(A first, B second) { 14 this.first = first; 15 this.second = second; 16 } 17 18 public A first() { 19 return first; 20 } 21 22 public B second() { 23 return second; 24 } 25 26 @Override 27 public int hashCode() { 28 final int prime = 31; 29 int result = 1; 30 result = prime * result + ((first == null) ? 0 : first.hashCode()); 31 result = prime * result + ((second == null) ? 0 : second.hashCode()); 32 return result; 33 } 34 35 @Override 36 public boolean equals(Object obj) { 37 if (this == obj) { 38 return true; 39 } 40 if (obj == null) { 41 return false; 42 } 43 if (getClass() != obj.getClass()) { 44 return false; 45 } 46 final Pair other = (Pair) obj; 47 if (first == null) { 48 if (other.first != null) { 49 return false; 50 } 51 } 52 else if (!first.equals(other.first)) { 53 return false; 54 } 55 if (second == null) { 56 if (other.second != null) { 57 return false; 58 } 59 } 60 else if (!second.equals(other.second)) { 61 return false; 62 } 63 return true; 64 } 65 66 public static <A, B> Pair<A, B> create(A first, B second) { 67 return of(first, second); 68 } 69 70 public static <A, B> Pair<A, B> of(A a, B b) { 71 return new Pair<>(a, b); 72 } 73 74 @Override 75 public String toString() { 76 return Objects.toStringHelper(getClass()) 77 .add("first", first()) 78 .add("second", second()) 79 .toString(); 80 } 81}