1 28 package net.sf.jasperreports.engine.util; 29 30 import java.io.Serializable ; 31 32 33 39 public class Pair implements Serializable 40 { 41 private static final long serialVersionUID = 1L; 42 43 private final Object o1; 44 private final Object o2; 45 private final int hash; 46 47 48 54 public Pair(Object o1, Object o2) 55 { 56 this.o1 = o1; 57 this.o2 = o2; 58 this.hash = computeHash(); 59 } 60 61 private int computeHash() 62 { 63 int hashCode = o1 == null ? 0 : o1.hashCode(); 64 hashCode *= 31; 65 hashCode += o2 == null ? 0 : o2.hashCode(); 66 return hashCode; 67 } 68 69 public boolean equals(Object o) 70 { 71 if (o == this) 72 { 73 return true; 74 } 75 76 if (o == null || !(o instanceof Pair)) 77 { 78 return false; 79 } 80 81 Pair p = (Pair) o; 82 83 return (p.o1 == null ? o1 == null : (o1 != null && p.o1.equals(o1))) && 84 (p.o2 == null ? o2 == null : (o2 != null && p.o2.equals(o2))); 85 } 86 87 public int hashCode() 88 { 89 return hash; 90 } 91 92 public String toString() 93 { 94 return "(" + String.valueOf(o1) + ", " + String.valueOf(o2) + ")"; 95 } 96 97 } 98 | Popular Tags |