Publication implements Comparator<Publication> { @Override public int hashCode() { return new HashCodeBuilder(83, 23). append(getPubType()). append(getAuthors()). append(getPubTitle()). append(getDoi()). append(getIsbn()). append(getYear()). append(getVolume()). toHashCode(); } protected  Publication();  Publication(String pubType, String isbn, String volume, Integer year, String pubTitle, String authors, String doi); long getPubId(); void setPubId(long pubId); Integer getPubMedId(); void setPubMedId(Integer pubMedId); String getPubAbstract(); void setPubAbstract(String pubAbstract); String getPubTitle(); void setPubTitle(String pubTitle); String getPubType(); void setPubType(String pubType); String getIsbn(); void setIsbn(String isbn); String getVolume(); void setVolume(String volume); String getIssue(); void setIssue(String issue); Integer getYear(); void setYear(Integer year); String getUrl(); void setUrl(String url); String getRawPages(); void setRawPages(String rawPages); String getMedlineJournal(); void setMedlineJournal(String medlineJournal); String getIsoJournal(); void setIsoJournal(String isoJournal); String getDoi(); void setDoi(String doi); String getAuthors(); @Transient String getShortAuthors(); void setAuthors(String authors); Integer getPubMedCentralId(); void setPubMedCentralId(Integer pubMedCentralId); @Override int hashCode(); @Override int compare(Publication o1, Publication o2); @Override boolean equals(Object obj); @Override String toString();  }
@Test public void testHashCode() { Publication pub1 = new Publication("publication", "isbn1", "volumn1", 2001, "title1", "authors1", "doi1"); Publication pub2 = new Publication("publication", "isbn1", "volumn1", 2001, "title1", "authors1", "doi1"); Publication pub3 = new Publication("publication", "isbn3", "volumn3", 2003, "title3", "authors3", "doi3"); Set<Publication> publications = new HashSet<Publication>(); assertNotNull(publications); assertEquals(0, publications.size()); publications.add(pub1); assertEquals(1, publications.size()); assertTrue(publications.contains(pub1)); publications.add(pub2); assertEquals(1, publications.size()); assertTrue(publications.contains(pub2)); assertTrue(publications.contains(pub1)); publications.add(pub3); assertEquals(2, publications.size()); assertTrue(publications.contains(pub3)); }