BlobCitationEntry implements Comparable<BlobCitationEntry> { @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((identifiers == null) ? 0 : identifiers.hashCode()); result = prime * result + position; result = prime * result + ((rawText == null) ? 0 : rawText.hashCode()); return result; } BlobCitationEntry();  BlobCitationEntry(String rawText); String getRawText(); void setRawText(String rawText); List<TypedId> getIdentifiers(); void setIdentifiers(List<TypedId> identifiers); @Override int hashCode(); @Override boolean equals(Object obj); @Override int compareTo(BlobCitationEntry c2); int getPosition(); void setPosition(int position);  }
@Test public void testHashCode() throws Exception { String rawText = "some raw text"; int position = 1; List<TypedId> identifiers = Lists.newArrayList(new TypedId("someValue", "someType", 0.9f)); BlobCitationEntry blobCitationEntry = new BlobCitationEntry(rawText); blobCitationEntry.setPosition(position); blobCitationEntry.setIdentifiers(identifiers); assertFalse(blobCitationEntry.equals(null)); assertFalse(blobCitationEntry.equals("string")); BlobCitationEntry otherBlobCitationEntry = new BlobCitationEntry("other raw text"); otherBlobCitationEntry.setPosition(position); otherBlobCitationEntry.setIdentifiers(identifiers); assertNotEquals(blobCitationEntry.hashCode(), otherBlobCitationEntry.hashCode()); otherBlobCitationEntry = new BlobCitationEntry(rawText); otherBlobCitationEntry.setPosition(2); otherBlobCitationEntry.setIdentifiers(identifiers); assertNotEquals(blobCitationEntry.hashCode(), otherBlobCitationEntry.hashCode()); otherBlobCitationEntry = new BlobCitationEntry(rawText); otherBlobCitationEntry.setPosition(position); otherBlobCitationEntry.setIdentifiers(Lists.newArrayList(new TypedId("someOtherValue", "someType", 0.9f))); assertNotEquals(blobCitationEntry.hashCode(), otherBlobCitationEntry.hashCode()); otherBlobCitationEntry = new BlobCitationEntry(rawText); otherBlobCitationEntry.setPosition(position); otherBlobCitationEntry.setIdentifiers(identifiers); assertEquals(blobCitationEntry.hashCode(), otherBlobCitationEntry.hashCode()); }