Node implements Comparable<Node> { @Override public boolean equals(Object o) { if (!(o instanceof Node)) return false; Node n = (Node) o; return (type.equals(n.type) && index == n.index); } Node(NodeType type, int index);  Node(String serialized); static Node ofStorage(int index); static Node ofDistributor(int index); String toString(); NodeType getType(); int getIndex(); @Override int compareTo(Node n); @Override int hashCode(); @Override boolean equals(Object o);  }
@Test public void testEquals() { Node n1 = new Node(NodeType.STORAGE, 6); Node n2 = new Node(NodeType.STORAGE, 7); Node n3 = new Node(NodeType.DISTRIBUTOR, 6); Node n4 = new Node(NodeType.DISTRIBUTOR, 7); Node n5 = new Node(NodeType.STORAGE, 6); Node n6 = new Node(NodeType.STORAGE, 7); Node n7 = new Node(NodeType.DISTRIBUTOR, 6); Node n8 = new Node(NodeType.DISTRIBUTOR, 7); assertEquals(n1, n5); assertEquals(n2, n6); assertEquals(n3, n7); assertEquals(n4, n8); assertEquals(n1, n1); assertEquals(n2, n2); assertEquals(n3, n3); assertEquals(n4, n4); assertFalse(n1.equals(n2)); assertFalse(n1.equals(n3)); assertFalse(n1.equals(n4)); assertFalse(n2.equals(n1)); assertFalse(n2.equals(n3)); assertFalse(n2.equals(n4)); assertFalse(n3.equals(n1)); assertFalse(n3.equals(n2)); assertFalse(n3.equals(n4)); assertFalse(n4.equals(n1)); assertFalse(n4.equals(n2)); assertFalse(n4.equals(n3)); assertFalse(n1.equals("class not instance of Node")); }