NameFormatter { public static String buildName(ParsedName n, boolean hybridMarker, boolean rankMarker, boolean authorship, boolean genusForinfrageneric, boolean infrageneric, boolean decomposition, boolean asciiOnly, boolean showQualifier, boolean showIndet, boolean nomNote, boolean showSensu, boolean showCultivar, boolean showStrain, boolean html ) { StringBuilder sb = new StringBuilder(); boolean candidateItalics = false; if (n.isCandidatus()) { sb.append("\""); if (html) { openItalics(sb); candidateItalics = true; html = false; } sb.append("Candidatus "); } if (n.getUninomial() != null) { if (hybridMarker && NamePart.GENERIC == n.getNotho()) { sb.append(HYBRID_MARKER) .append(" "); } appendInItalics(sb, n.getUninomial(), html); } else { if (n.getInfragenericEpithet() != null) { if ((isUnknown(n.getRank()) && n.getSpecificEpithet() == null) || (n.getRank() != null && n.getRank().isInfragenericStrictly())) { boolean showInfraGen = true; if (n.getGenus() != null && genusForinfrageneric) { appendGenus(sb, n, hybridMarker, showQualifier, html); sb.append(" "); if (NomCode.ZOOLOGICAL == n.getCode()) { sb.append("("); if (hybridMarker && NamePart.INFRAGENERIC == n.getNotho()) { sb.append(HYBRID_MARKER) .append(' '); } appendInItalics(sb, n.getInfragenericEpithet(), html); sb.append(")"); showInfraGen = false; } } if (showInfraGen) { if (rankMarker) { if (appendRankMarker(sb, n.getRank(), hybridMarker && NamePart.INFRAGENERIC == n.getNotho())) { sb.append(' '); } } appendInItalics(sb, n.getInfragenericEpithet(), html); } } else { if (n.getGenus() != null) { appendGenus(sb, n, hybridMarker, showQualifier, html); } if (infrageneric) { sb.append(" ("); appendInItalics(sb, n.getInfragenericEpithet(), html); sb.append(")"); } } } else if (n.getGenus() != null) { appendGenus(sb, n, hybridMarker, showQualifier, html); } if (n.getSpecificEpithet() == null) { if (showIndet && n.getGenus() != null && n.getCultivarEpithet() == null) { if (n.getRank() != null && n.getRank().isSpeciesOrBelow()) { if (n.getRank().isInfraspecific()) { appendInfraspecific(sb, n, hybridMarker, showQualifier, rankMarker, true, html); } else { sb.append(" "); sb.append(n.getRank().getMarker()); } authorship = false; } } else if (n.getInfraspecificEpithet() != null) { appendInfraspecific(sb, n, hybridMarker, showQualifier, rankMarker, false, html); } } else { sb.append(' '); if (showQualifier && n.hasEpithetQualifier(NamePart.SPECIFIC )) { sb.append(n.getEpithetQualifier().get(NamePart.SPECIFIC)) .append(" "); } if (hybridMarker && NamePart.SPECIFIC == n.getNotho()) { sb.append(HYBRID_MARKER) .append(" "); } appendInItalics(sb, n.getSpecificEpithet(), html); if (n.getInfraspecificEpithet() == null) { if (showIndet && n.getRank() != null && n.getRank().isInfraspecific() && (NomCode.CULTIVARS != n.getRank().isRestrictedToCode() || n.getCultivarEpithet() == null) ) { if (n.getRank() == Rank.SUBSPECIES) { sb.append(" ssp."); } else { sb.append(' '); sb.append(n.getRank().getMarker()); } authorship = false; } } else { appendInfraspecific(sb, n, hybridMarker, showQualifier, rankMarker, false, html); if (n.isAutonym()) { authorship = false; } } } } if (n.isCandidatus()) { if (candidateItalics) { closeItalics(sb); } sb.append("\""); } if (authorship && n.hasAuthorship()) { sb.append(" "); appendAuthorship(n, sb); } if (showStrain && n.getStrain() != null) { sb.append(" ") .append(n.getStrain()); } if (showCultivar && n.getCultivarEpithet() != null) { if (Rank.CULTIVAR_GROUP == n.getRank()) { sb.append(" ") .append(n.getCultivarEpithet()) .append(" Group"); } else if (Rank.GREX == n.getRank()) { sb.append(" ") .append(n.getCultivarEpithet()) .append(" gx"); } else { sb.append(" '") .append(n.getCultivarEpithet()) .append("'"); } } if (showSensu && n.getTaxonomicNote() != null) { appendIfNotEmpty(sb, " ") .append(n.getTaxonomicNote()); } if (nomNote && n.getNomenclaturalNote() != null) { appendIfNotEmpty(sb, ", ") .append(n.getNomenclaturalNote()); } String name = sb.toString().trim(); if (decomposition) { name = UnicodeUtils.decompose(name); } if (asciiOnly) { name = UnicodeUtils.ascii(name); } return Strings.emptyToNull(name); } private  NameFormatter(); static String canonical(ParsedName n); static String canonicalWithoutAuthorship(ParsedName n); static String canonicalMinimal(ParsedName n); static String canonicalComplete(ParsedName n); static String canonicalCompleteHtml(ParsedName n); static String authorshipComplete(ParsedAuthorship n); static String authorString(Authorship authors, boolean inclYear); static String buildName(ParsedName n,
                                 boolean hybridMarker,
                                 boolean rankMarker,
                                 boolean authorship,
                                 boolean genusForinfrageneric,
                                 boolean infrageneric,
                                 boolean decomposition,
                                 boolean asciiOnly,
                                 boolean showQualifier,
                                 boolean showIndet,
                                 boolean nomNote,
                                 boolean showSensu,
                                 boolean showCultivar,
                                 boolean showStrain,
                                 boolean html
  ); static void appendAuthorship(StringBuilder sb, Authorship auth, boolean includeYear); static final char HYBRID_MARKER; }
@Test public void testBuildName() throws Exception { pn.setUninomial("Pseudomonas"); assertName("Pseudomonas"); assertHtml("<i>Pseudomonas</i>"); pn.setUninomial(null); pn.setGenus("Pseudomonas"); pn.setSpecificEpithet("syringae"); assertName("Pseudomonas syringae"); assertHtml("<i>Pseudomonas</i> <i>syringae</i>"); pn.setCombinationAuthorship(Authorship.authors("Van Hall")); assertName("Pseudomonas syringae", "Pseudomonas syringae Van Hall"); assertHtml("<i>Pseudomonas</i> <i>syringae</i> Van Hall"); pn.getCombinationAuthorship().setYear("1904"); assertName("Pseudomonas syringae", "Pseudomonas syringae Van Hall, 1904"); assertHtml("<i>Pseudomonas</i> <i>syringae</i> Van Hall, 1904"); pn.setBasionymAuthorship(Authorship.authors("Carl.")); assertName("Pseudomonas syringae", "Pseudomonas syringae (Carl.) Van Hall, 1904"); assertHtml("<i>Pseudomonas</i> <i>syringae</i> (Carl.) Van Hall, 1904"); pn.setRank(Rank.PATHOVAR); pn.setInfraspecificEpithet("aceris"); pn.getBasionymAuthorship().getAuthors().clear(); assertName("Pseudomonas syringae aceris", "Pseudomonas syringae pv. aceris Van Hall, 1904"); assertHtml("<i>Pseudomonas</i> <i>syringae</i> pv. <i>aceris</i> Van Hall, 1904"); pn.setStrain("CFBP 2339"); assertName("Pseudomonas syringae aceris", "Pseudomonas syringae pv. aceris Van Hall, 1904 CFBP 2339"); assertHtml("<i>Pseudomonas</i> <i>syringae</i> pv. <i>aceris</i> Van Hall, 1904 CFBP 2339"); pn.getCombinationAuthorship().setYear(null); pn.getCombinationAuthorship().getAuthors().clear(); assertName("Pseudomonas syringae aceris", "Pseudomonas syringae pv. aceris CFBP 2339"); pn.setTaxonomicNote("tax note"); assertHtml("<i>Pseudomonas</i> <i>syringae</i> pv. <i>aceris</i> CFBP 2339 tax note"); pn = new ParsedName(); pn.setGenus("Abax"); pn.setSpecificEpithet("carinatus"); pn.setInfraspecificEpithet("carinatus"); pn.setBasionymAuthorship(Authorship.yearAuthors("1812", "Duftschmid")); pn.setRank(Rank.UNRANKED); assertName("Abax carinatus carinatus"); pn.setRank(null); assertName("Abax carinatus carinatus"); pn.setInfraspecificEpithet("urinatus"); assertName("Abax carinatus urinatus", "Abax carinatus urinatus (Duftschmid, 1812)"); pn.setRank(null); assertName("Abax carinatus urinatus", "Abax carinatus urinatus (Duftschmid, 1812)"); pn.setRank(Rank.SUBSPECIES); assertName("Abax carinatus urinatus", "Abax carinatus urinatus (Duftschmid, 1812)"); pn.setCode(NomCode.BOTANICAL); assertName("Abax carinatus urinatus", "Abax carinatus subsp. urinatus (Duftschmid, 1812)"); pn = new ParsedName(); pn.setGenus("Polypodium"); pn.setSpecificEpithet("vulgare"); pn.setInfraspecificEpithet("mantoniae"); pn.setBasionymAuthorship(Authorship.authors("Rothm.")); pn.setCombinationAuthorship(Authorship.authors("Schidlay")); pn.setRank(Rank.SUBSPECIES); pn.setNotho(NamePart.INFRASPECIFIC); assertName( "Polypodium vulgare mantoniae", "Polypodium vulgare nothosubsp. mantoniae (Rothm.) Schidlay", "Polypodium vulgare nothosubsp. mantoniae (Rothm.) Schidlay"); }