TypedRange implements Comparable<TypedRange<T>> { @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + (int) (length ^ (length >>> 32)); result = prime * result + ((metadata == null) ? 0 : metadata.hashCode()); result = prime * result + (int) (offset ^ (offset >>> 32)); return result; } 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 testHashCode() { TypedRange<String> range1a = new TypedRange<String>(123, 456, "hi mom"); TypedRange<String> range1b = new TypedRange<String>(123, 456, "hi mom"); Assert.assertEquals(range1a.hashCode(), range1b.hashCode()); Set<Integer> hashCodes = new HashSet<Integer>(); hashCodes.add(range1a.hashCode()); hashCodes.add(new TypedRange<String>(123 + 1, 456, "hi mom").hashCode()); hashCodes.add(new TypedRange<String>(123, 456 + 1, "hi mom").hashCode()); hashCodes.add(new TypedRange<String>(123 + 1, 456, "x").hashCode()); hashCodes.add(new TypedRange<String>(123 + 1, 456, null).hashCode()); Assert.assertEquals(5, hashCodes.size()); }