@Test public void testEqualsObject() { Pair<Integer, String> pair1 = new Pair<Integer, String>(1, "one"); Pair<Integer, String> pair2 = new Pair<Integer, String>(1, "one"); assertEquals(pair1, pair2); assertEquals(pair2, pair1); pair1 = pair2; assertEquals(pair1, pair2); assertEquals(pair2, pair1); pair2 = new Pair<Integer, String>(1, "two"); assertFalse(pair1.equals(pair2)); assertFalse(pair2.equals(pair1)); pair1 = new Pair<Integer, String>(null, "one"); pair2 = new Pair<Integer, String>(null, "one"); assertEquals(pair1, pair2); assertEquals(pair2, pair1); pair1 = new Pair<Integer, String>(1, null); pair2 = new Pair<Integer, String>(1, null); assertEquals(pair1, pair2); assertEquals(pair2, pair1); pair1 = new Pair<Integer, String>(null, null); pair2 = new Pair<Integer, String>(null, null); assertEquals(pair1, pair2); assertEquals(pair2, pair1); assertFalse(pair1.equals(null)); assertFalse(pair1.equals("hello")); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } Pair<?, ?> other = (Pair<?, ?>) obj; if (first == null) { if (other.first != null) { return false; } } else if (!first.equals(other.first)) { return false; } if (second == null) { if (other.second != null) { return false; } } else if (!second.equals(other.second)) { return false; } return true; }
Pair { @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } Pair<?, ?> other = (Pair<?, ?>) obj; if (first == null) { if (other.first != null) { return false; } } else if (!first.equals(other.first)) { return false; } if (second == null) { if (other.second != null) { return false; } } else if (!second.equals(other.second)) { return false; } return true; } }
Pair { @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } Pair<?, ?> other = (Pair<?, ?>) obj; if (first == null) { if (other.first != null) { return false; } } else if (!first.equals(other.first)) { return false; } if (second == null) { if (other.second != null) { return false; } } else if (!second.equals(other.second)) { return false; } return true; } Pair(F first, S second); }
Pair { @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } Pair<?, ?> other = (Pair<?, ?>) obj; if (first == null) { if (other.first != null) { return false; } } else if (!first.equals(other.first)) { return false; } if (second == null) { if (other.second != null) { return false; } } else if (!second.equals(other.second)) { return false; } return true; } Pair(F first, S second); F getFirst(); S getSecond(); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); }
Pair { @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } Pair<?, ?> other = (Pair<?, ?>) obj; if (first == null) { if (other.first != null) { return false; } } else if (!first.equals(other.first)) { return false; } if (second == null) { if (other.second != null) { return false; } } else if (!second.equals(other.second)) { return false; } return true; } Pair(F first, S second); F getFirst(); S getSecond(); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString();  }