TypedRange implements Comparable<TypedRange<T>> { @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; TypedRange<?> other = (TypedRange<?>) obj; if (length != other.length) return false; if (metadata == null) { if (other.metadata != null) return false; } else if (!metadata.equals(other.metadata)) return false; if (offset != other.offset) return false; return true; } TypedRange(long offset, long length, T metadata); @Override String toString(); long getOffset(); long getLength(); T getMetadata(); @Override int hashCode(); @Override boolean equals(Object obj); @Override int compareTo(TypedRange<T> other);  }
@Test public void testEquals() { TypedRange<String> range1a = new TypedRange<String>(123, 456, "hi mom"); Assert.assertEquals(range1a, range1a); TypedRange<String> range1b = new TypedRange<String>(123, 456, "hi mom"); Assert.assertEquals(range1a, range1b); Assert.assertNotEquals(range1a, new TypedRange<String>(123 + 1, 456, "hi mom")); Assert.assertNotEquals(range1a, new TypedRange<String>(123, 456 + 1, "hi mom")); Assert.assertNotEquals(range1a, new TypedRange<String>(123, 456, "foo")); Assert.assertNotEquals(range1a, new TypedRange<String>(123, 456, null)); Assert.assertNotEquals(new TypedRange<String>(123, 456, null), range1a); Assert.assertEquals( new TypedRange<String>(123, 456, null), new TypedRange<String>(123, 456, null)); Assert.assertNotEquals(range1a, null); Assert.assertNotEquals(range1a, "space channel 5"); }