1 2 23 24 package net.fenyo.gnetwatch; 25 26 import net.fenyo.gnetwatch.targets.Target; 27 28 33 34 public class Pair<E, F> { 35 private final E e; 36 private final F f; 37 38 43 public Pair(final E e, final F f) { 44 this.e = e; 45 this.f = f; 46 } 47 48 53 public E former() { 54 return e; 55 } 56 57 62 public F latter() { 63 return f; 64 } 65 66 71 public boolean equals(final Object o) { 72 if (this == o) return true; 73 if ((o == null) || (o.getClass() != getClass())) return false; 74 final Pair<E, F> pair = (Pair<E, F>) o; 75 if (e == null && f == null) return pair.former() == null && pair.latter() == null; 76 if (e == null) return pair.former() == null && f.equals(pair.latter()); 77 if (f == null) return pair.latter() == null && e.equals(pair.former()); 78 return e.equals(pair.former()) && f.equals(pair.latter()); 79 } 80 81 86 public int hashCode() { 87 if (e == null && f == null) return 0; 88 if (e != null) return e.hashCode(); 89 if (f != null) return f.hashCode(); 90 return e.hashCode() ^ f.hashCode(); 91 } 92 } 93 | Popular Tags |