NodeId implements Comparable<NodeId> { @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; NodeId nodeId = (NodeId) o; if (id != nodeId.id) return false; return true; } NodeId();  NodeId(long id);  NodeId(NodeId nid); @Override boolean equals(Object o); @Override int hashCode(); @Override int compareTo(NodeId o); @Override String toString(); final long id; }
@Test public void equalsTest() { NodeId a = new NodeId(1); NodeId b = new NodeId(2); NodeId c = new NodeId(1); NodeId d = new NodeId(a); Assert.assertTrue( a.equals(a) ); Assert.assertTrue( a.equals(c) ); Assert.assertTrue( a.equals(d) ); Assert.assertTrue( c.equals(d) ); Assert.assertFalse( a.equals(b) ); Assert.assertFalse( a.equals(null) ); Assert.assertFalse( a.equals( new Long(1)) ); }
@Test public void randomTest() { NodeId a = new NodeId(); NodeId b = new NodeId(); Assert.assertFalse( a.equals(b) ); }