SplitIndex { @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; SplitIndex other = (SplitIndex) obj; if (index != other.index) return false; if (last != other.last) return false; return true; } private  SplitIndex(int index, boolean last); static SplitIndex valueOf(int index, boolean last); int getIndex(); boolean isLast(); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString();  }
@Test public void testEquals() { SplitIndex index1a = SplitIndex.valueOf(4, false); SplitIndex index1b = SplitIndex.valueOf(4, false); SplitIndex index2 = SplitIndex.valueOf(5, false); SplitIndex index3 = SplitIndex.valueOf(4, true); assertTrue("Should be equal", index1a.equals(index1b)); assertFalse("Should not be equal", index1a.equals(index2)); assertFalse("Should not be equal", index1a.equals(index3)); assertFalse("Null is never equal", index1a.equals(null)); assertFalse("Unrelated class is never equal", index1a.equals(this)); assertTrue("Same instances should be equal", index1a.equals(index1a)); }