Publication implements Comparator<Publication> { @Transient protected int getNthOccurrence(String str, char c, int nth) { if (str != null) { int pos = str.indexOf(c, 0); while (nth-- > 1 && pos != -1) pos = str.indexOf(c, pos + 1); return pos; } return -1; } 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 testGetNthOccurrence() { int pos = publication.getNthOccurrence(authors, ',', 1); assertEquals(',', authors.charAt(pos)); assertEquals(14, pos); pos = publication.getNthOccurrence(authors, ',', 2); assertEquals(',', authors.charAt(pos)); assertEquals(22, pos); pos = publication.getNthOccurrence(authors, ',', 5); assertEquals(',', authors.charAt(pos)); assertEquals(60, pos); pos = publication.getNthOccurrence("Frias-Lopez J.", ',', 1); assertEquals(-1, pos); pos = publication.getNthOccurrence("", ',', 1); assertEquals(-1, pos); }