2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.cdm
.strategy
.cache
.name
;
11 import java
.util
.ArrayList
;
12 import java
.util
.List
;
13 import java
.util
.UUID
;
14 import java
.util
.regex
.Matcher
;
15 import java
.util
.regex
.Pattern
;
17 import org
.apache
.log4j
.Logger
;
19 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
20 import eu
.etaxonomy
.cdm
.common
.UTF8
;
21 import eu
.etaxonomy
.cdm
.model
.agent
.INomenclaturalAuthor
;
22 import eu
.etaxonomy
.cdm
.model
.name
.HybridRelationship
;
23 import eu
.etaxonomy
.cdm
.model
.name
.INonViralName
;
24 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
25 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
26 import eu
.etaxonomy
.cdm
.strategy
.cache
.TagEnum
;
27 import eu
.etaxonomy
.cdm
.strategy
.cache
.TaggedText
;
28 import eu
.etaxonomy
.cdm
.strategy
.cache
.TaggedTextBuilder
;
29 import eu
.etaxonomy
.cdm
.strategy
.exceptions
.UnknownCdmTypeException
;
30 import eu
.etaxonomy
.cdm
.strategy
.parser
.NonViralNameParserImplRegExBase
;
34 * This class is a default implementation for the INonViralNameCacheStrategy<T extends NonViralName>
36 * The method implements a cache strategy for botanical names so no method has to be overwritten by
37 * a subclass for botanic names.
38 * Where differing from this default botanic name strategy other subclasses should overwrite the
39 * existing methods, e.g. a CacheStrategy for zoological names should overwrite getAuthorAndExAuthor
42 public class TaxonNameDefaultCacheStrategy
43 extends NameCacheStrategyBase
44 implements INonViralNameCacheStrategy
{
46 private static final Logger logger
= Logger
.getLogger(TaxonNameDefaultCacheStrategy
.class);
47 private static final long serialVersionUID
= -6577757501563212669L;
49 final static UUID uuid
= UUID
.fromString("1cdda0d1-d5bc-480f-bf08-40a510a2f223");
51 protected String nameAuthorSeperator
= " ";
52 protected String basionymStart
= "(";
53 protected String basionymEnd
= ")";
54 protected String exAuthorSeperator
= " ex ";
55 private static String NOTHO
= "notho";
56 protected CharSequence basionymAuthorCombinationAuthorSeperator
= " ";
58 protected String zooAuthorYearSeperator
= ", ";
60 private String cultivarStart
= "'";
61 private String cultivarEnd
= "'";
64 public UUID
getUuid(){
68 // ************************** FACTORY ******************************/
70 public static TaxonNameDefaultCacheStrategy
NewInstance(){
71 return new TaxonNameDefaultCacheStrategy();
75 // ************ CONSTRUCTOR *******************/
77 protected TaxonNameDefaultCacheStrategy(){
81 /* **************** GETTER / SETTER **************************************/
84 * String that separates the NameCache part from the AuthorCache part
87 public String
getNameAuthorSeperator() {
88 return nameAuthorSeperator
;
90 public void setNameAuthorSeperator(String nameAuthorSeperator
) {
91 this.nameAuthorSeperator
= nameAuthorSeperator
;
96 * String the basionym author part starts with e.g. '('.
97 * This should correspond with the {@link TaxonNameDefaultCacheStrategy#getBasionymEnd() basionymEnd} attribute
100 public String
getBasionymStart() {
101 return basionymStart
;
103 public void setBasionymStart(String basionymStart
) {
104 this.basionymStart
= basionymStart
;
108 * String the basionym author part ends with e.g. ')'.
109 * This should correspond with the {@link TaxonNameDefaultCacheStrategy#getBasionymStart() basionymStart} attribute
112 public String
getBasionymEnd() {
115 public void setBasionymEnd(String basionymEnd
) {
116 this.basionymEnd
= basionymEnd
;
121 * String to separate ex author from author.
124 public String
getExAuthorSeperator() {
125 return exAuthorSeperator
;
127 public void setExAuthorSeperator(String exAuthorSeperator
) {
128 this.exAuthorSeperator
= exAuthorSeperator
;
133 * String that separates the basionym/original_combination author part from the combination author part
136 public CharSequence
getBasionymAuthorCombinationAuthorSeperator() {
137 return basionymAuthorCombinationAuthorSeperator
;
141 public void setBasionymAuthorCombinationAuthorSeperator( CharSequence basionymAuthorCombinationAuthorSeperator
) {
142 this.basionymAuthorCombinationAuthorSeperator
= basionymAuthorCombinationAuthorSeperator
;
145 public String
getZooAuthorYearSeperator() {
146 return zooAuthorYearSeperator
;
148 public void setZooAuthorYearSeperator(String authorYearSeperator
) {
149 this.zooAuthorYearSeperator
= authorYearSeperator
;
152 // ******************* Authorship ******************************/
155 public String
getAuthorshipCache(TaxonName taxonName
) {
156 if (taxonName
== null){
158 }else if (taxonName
.isViral()){
160 }else if(taxonName
.isProtectedAuthorshipCache() == true) {
162 return taxonName
.getAuthorshipCache();
164 return getNonCacheAuthorshipCache(taxonName
);
169 * Returns the authorshipcache string for the atomized authorship fields. Does not use the authorship field.
170 * @throws NullPointerException if nonViralName is null.
174 protected String
getNonCacheAuthorshipCache(TaxonName nonViralName
){
175 if (nonViralName
.getNameType().isZoological()){
176 return this.getZoologicalNonCacheAuthorshipCache(nonViralName
);
179 INomenclaturalAuthor combinationAuthor
= nonViralName
.getCombinationAuthorship();
180 INomenclaturalAuthor exCombinationAuthor
= nonViralName
.getExCombinationAuthorship();
181 INomenclaturalAuthor basionymAuthor
= nonViralName
.getBasionymAuthorship();
182 INomenclaturalAuthor exBasionymAuthor
= nonViralName
.getExBasionymAuthorship();
183 if (isCultivar(nonViralName
) ){
184 exCombinationAuthor
= null;
185 basionymAuthor
= null;
186 exBasionymAuthor
= null;
189 String basionymPart
= "";
190 String authorPart
= "";
192 if (basionymAuthor
!= null || exBasionymAuthor
!= null){
193 basionymPart
= basionymStart
+ getAuthorAndExAuthor(basionymAuthor
, exBasionymAuthor
) + basionymEnd
;
195 if (combinationAuthor
!= null || exCombinationAuthor
!= null){
196 authorPart
= getAuthorAndExAuthor(combinationAuthor
, exCombinationAuthor
);
198 result
= CdmUtils
.concat(basionymAuthorCombinationAuthorSeperator
, basionymPart
, authorPart
);
199 // if ("".equals(result)){
206 private boolean isCultivar(TaxonName name
) {
207 return name
.isCultivar() || isNotBlank(name
.getCultivarEpithet()) || isNotBlank(name
.getCultivarGroupEpithet());
210 protected String
getZoologicalNonCacheAuthorshipCache(TaxonName nonViralName
) {
211 if (nonViralName
== null){
215 INomenclaturalAuthor combinationAuthor
= nonViralName
.getCombinationAuthorship();
216 INomenclaturalAuthor exCombinationAuthor
= nonViralName
.getExCombinationAuthorship();
217 INomenclaturalAuthor basionymAuthor
= nonViralName
.getBasionymAuthorship();
218 INomenclaturalAuthor exBasionymAuthor
= nonViralName
.getExBasionymAuthorship();
219 Integer publicationYear
= nonViralName
.getPublicationYear();
220 Integer originalPublicationYear
= nonViralName
.getOriginalPublicationYear();
222 String basionymPart
= "";
223 String authorPart
= "";
225 if (basionymAuthor
!= null || exBasionymAuthor
!= null || originalPublicationYear
!= null ){
226 String authorAndEx
= getAuthorAndExAuthor(basionymAuthor
, exBasionymAuthor
);
227 String originalPublicationYearString
= originalPublicationYear
== null ?
null : String
.valueOf(originalPublicationYear
);
228 String authorAndExAndYear
= CdmUtils
.concat(zooAuthorYearSeperator
, authorAndEx
, originalPublicationYearString
);
229 basionymPart
= basionymStart
+ authorAndExAndYear
+ basionymEnd
;
231 if (combinationAuthor
!= null || exCombinationAuthor
!= null){
232 String authorAndEx
= getAuthorAndExAuthor(combinationAuthor
, exCombinationAuthor
);
233 String publicationYearString
= publicationYear
== null ?
null : String
.valueOf(publicationYear
);
234 authorPart
= CdmUtils
.concat(zooAuthorYearSeperator
, authorAndEx
, publicationYearString
);
236 result
= CdmUtils
.concat(basionymAuthorCombinationAuthorSeperator
, basionymPart
, authorPart
);
245 * Returns the AuthorCache part for a combination of an author and an ex author. This applies on
246 * combination authors as well as on basionym/orginal combination authors.
247 * The correct order is exAuthor ex author though some botanist do not know about and do it the
248 * other way round. (see 46.4-46.6 ICBN (Vienna Code, 2006))
250 protected String
getAuthorAndExAuthor(INomenclaturalAuthor author
, INomenclaturalAuthor exAuthor
){
251 String authorString
= "";
252 String exAuthorString
= "";
254 authorString
= getNomAuthorTitle(author
);
256 if (exAuthor
!= null){
257 exAuthorString
= getNomAuthorTitle(exAuthor
);
258 exAuthorString
+= exAuthorSeperator
;
260 String result
= exAuthorString
+ authorString
;
264 private String
getNomAuthorTitle(INomenclaturalAuthor author
) {
265 return CdmUtils
.Nz(author
.getNomenclaturalTitleCache());
269 * Checks if the given name should include the author in it's cached version.<BR>
270 * This is usually the case but not for <i>species aggregates</i>.
271 * @param nonViralName
274 protected boolean nameIncludesAuthorship(INonViralName nonViralName
){
275 Rank rank
= nonViralName
.getRank();
276 if (rank
!= null && rank
.isSpeciesAggregate()){
283 // ************* TAGGED NAME ***************************************/
286 protected List
<TaggedText
> doGetTaggedTitle(TaxonName taxonName
) {
287 List
<TaggedText
> tags
= new ArrayList
<>();
288 if (taxonName
.getNameType().isViral()){
289 String acronym
= taxonName
.getAcronym();
290 if (isNotBlank(taxonName
.getAcronym())){
291 //this is not according to the code
292 tags
.add(new TaggedText(TagEnum
.name
, acronym
));
295 }else if (taxonName
.isHybridFormula()){
297 String hybridSeparator
= NonViralNameParserImplRegExBase
.hybridSign
;
298 boolean isFirst
= true;
299 List
<HybridRelationship
> rels
= taxonName
.getOrderedChildRelationships();
300 for (HybridRelationship rel
: rels
){
302 tags
.add(new TaggedText(TagEnum
.hybridSign
, hybridSeparator
));
305 tags
.addAll(getTaggedTitle(rel
.getParentName()));
308 }else if (taxonName
.isAutonym()){
310 tags
.addAll(handleTaggedAutonym(taxonName
));
312 List
<TaggedText
> nameTags
= getTaggedName(taxonName
);
313 tags
.addAll(nameTags
);
314 String authorCache
= getAuthorshipCache(taxonName
);
315 if (isNotBlank(authorCache
)){
316 tags
.add(new TaggedText(TagEnum
.authors
, authorCache
));
323 * Returns the tag list of the name part (without author and reference).
328 public List
<TaggedText
> getTaggedName(TaxonName taxonName
) {
329 if (taxonName
== null){
331 }else if (taxonName
.isViral()){
334 List
<TaggedText
> tags
= new ArrayList
<>();
335 Rank rank
= taxonName
.getRank();
337 if (taxonName
.isProtectedNameCache()){
338 tags
.add(new TaggedText(TagEnum
.name
, taxonName
.getNameCache()));
339 }else if (taxonName
.isHybridFormula()){
341 //TODO graft-chimera (see also cultivars)
342 String hybridSeparator
= NonViralNameParserImplRegExBase
.hybridSign
;
343 boolean isFirst
= true;
344 List
<HybridRelationship
> rels
= taxonName
.getOrderedChildRelationships();
345 for (HybridRelationship rel
: rels
){
347 tags
.add(new TaggedText(TagEnum
.hybridSign
, hybridSeparator
));
350 tags
.addAll(getTaggedName(rel
.getParentName()));
354 }else if (rank
== null){
355 tags
= getRanklessTaggedNameCache(taxonName
);
356 }else if (rank
.isCultivar()){
357 tags
= getCultivarTaggedNameCache(taxonName
);
358 }else if (rank
.isInfraSpecific()){
359 tags
= getInfraSpeciesTaggedNameCache(taxonName
);
360 }else if (rank
.isSpecies() || isAggregateWithAuthorship(taxonName
, rank
) ){ //exception see #4288
361 tags
= getSpeciesTaggedNameCache(taxonName
);
362 }else if (rank
.isInfraGeneric()){
363 tags
= getInfraGenusTaggedNameCache(taxonName
);
364 }else if (rank
.isGenus()){
365 tags
= getGenusOrUninomialTaggedNameCache(taxonName
);
366 }else if (rank
.isSupraGeneric()){
367 tags
= getGenusOrUninomialTaggedNameCache(taxonName
);
369 tags
= getRanklessTaggedNameCache(taxonName
);
370 logger
.warn("Rank does not belong to a rank class: " + rank
.getTitleCache() + ". Used rankless nameCache for name " + taxonName
.getUuid());
372 //TODO handle appended phrase here instead of different places, check first if this is true for all
378 //***************************** PRIVATES ***************************************/
380 private List
<TaggedText
> getCultivarTaggedNameCache(TaxonName taxonName
) {
381 List
<TaggedText
> scientificNameTags
;
382 TaggedTextBuilder builder
= TaggedTextBuilder
.NewInstance();
383 if (isNotBlank(taxonName
.getInfraSpecificEpithet())){
384 scientificNameTags
= getInfraSpeciesTaggedNameCache(taxonName
);
385 } else if (isNotBlank(taxonName
.getSpecificEpithet())){
386 scientificNameTags
= getSpeciesTaggedNameCache(taxonName
);
387 } else if (isNotBlank(taxonName
.getInfraGenericEpithet())){
388 scientificNameTags
= getInfraGenusTaggedNameCache(taxonName
);
389 } else /*if (isNotBlank(taxonName.getGenusOrUninomial())) */{
390 scientificNameTags
= getGenusOrUninomialTaggedNameCache(taxonName
);
393 UUID rankUuid
= taxonName
.getRank().getUuid();
394 boolean rankIsHandled
= true;
395 String cultivarStr
= null;
396 String groupStr
= taxonName
.getCultivarGroupEpithet();
397 if (rankUuid
.equals(Rank
.uuidCultivar
)){
398 cultivarStr
= surroundedCultivarEpithet(taxonName
);
399 if (isNotBlank(cultivarStr
) && isNotBlank(groupStr
)){
400 groupStr
= surroundGroupWithBracket(groupStr
);
402 cultivarStr
= CdmUtils
.concat(" ", groupStr
, cultivarStr
);
403 }else if (rankUuid
.equals(Rank
.uuidCultivarGroup
)){
404 cultivarStr
= CdmUtils
.concat(" ", groupStr
, checkHasGroupEpithet(groupStr
)?
null: "Group");
405 }else if (rankUuid
.equals(Rank
.uuidGrex
)){
406 cultivarStr
= CdmUtils
.concat(" ", groupStr
, checkHasGrexEpithet(groupStr
)?
null: "grex");
408 rankIsHandled
= false;
410 if (isNotBlank(cultivarStr
)){
411 builder
.addAll(scientificNameTags
);
412 builder
.add(TagEnum
.cultivar
, cultivarStr
);
415 if (rankUuid
.equals(Rank
.uuidGraftChimaera
)){
416 //TODO not yet fully implemented
417 cultivarStr
= "+ " + taxonName
.getGenusOrUninomial() + " " + surroundedCultivarEpithet(taxonName
);
418 builder
.add(TagEnum
.cultivar
, cultivarStr
);
419 } else if (!rankIsHandled
){
420 throw new IllegalStateException("Unsupported rank " + taxonName
.getRank().getTitleCache() + " for cultivar.");
423 return builder
.getTaggedText();
426 private String
surroundGroupWithBracket(String groupStr
) {
427 if (groupStr
.matches(NonViralNameParserImplRegExBase
.grex
+ "$")){
429 }else if (groupStr
.matches(".*" + NonViralNameParserImplRegExBase
.grex
+ ".+")){
430 Matcher matcher
= Pattern
.compile(NonViralNameParserImplRegExBase
.grex
+ "\\s*" ).matcher(groupStr
);
432 return groupStr
.substring(0, matcher
.end()) + "("+ groupStr
.substring(matcher
.end())+ ")";
434 return "("+ groupStr
+ ")";
438 private boolean checkHasGroupEpithet(String group
) {
440 String
[] splits
= group
== null?
new String
[0]: group
.split("\\s+");
441 if (splits
.length
<= 1){
443 }else if (splits
[0].matches(NonViralNameParserImplRegExBase
.group
)
444 || splits
[splits
.length
-1].matches(NonViralNameParserImplRegExBase
.group
)){
451 private boolean checkHasGrexEpithet(String grex
) {
452 String
[] splits
= grex
== null?
new String
[0]: grex
.split("\\s+");
453 if (splits
.length
<= 1){
455 }else if (splits
[splits
.length
-1].matches(NonViralNameParserImplRegExBase
.grex
)){
462 private String
surroundedCultivarEpithet(TaxonName taxonName
) {
463 return cultivarStart
+ taxonName
.getCultivarEpithet() + cultivarEnd
;
466 private boolean isAggregateWithAuthorship(TaxonName nonViralName
, Rank rank
) {
470 return rank
.isSpeciesAggregate() && ( isNotBlank(nonViralName
.getAuthorshipCache()) || nonViralName
.getNomenclaturalReference() != null );
475 * Returns the tag list for an autonym taxon.
477 * @see NonViralName#isAutonym()
478 * @see BotanicalName#isAutonym()
479 * @param nonViralName
482 private List
<TaggedText
> handleTaggedAutonym(TaxonName nonViralName
) {
483 List
<TaggedText
> tags
= null;
484 if (nonViralName
.isInfraSpecific()){
486 tags
= getSpeciesTaggedNameCache(nonViralName
);
489 String authorCache
= getAuthorshipCache(nonViralName
);
490 if (isNotBlank(authorCache
)){
491 tags
.add(new TaggedText(TagEnum
.authors
, authorCache
));
494 //infra species marker
495 if (nonViralName
.getRank() == null || !nonViralName
.getRank().isInfraSpecific()){
496 //TODO handle exception
497 logger
.warn("Rank for autonym does not exist or is not lower than species !!");
499 String infraSpeciesMarker
= nonViralName
.getRank().getAbbreviation();
500 if (nonViralName
.isTrinomHybrid()){
501 infraSpeciesMarker
= CdmUtils
.concat("", NOTHO
, infraSpeciesMarker
);
503 if (isNotBlank(infraSpeciesMarker
)){
504 tags
.add(new TaggedText(TagEnum
.rank
, infraSpeciesMarker
));
509 String infraSpeciesPart
= CdmUtils
.Nz(nonViralName
.getInfraSpecificEpithet()).trim();
510 if (isNotBlank(infraSpeciesPart
)){
511 tags
.add(new TaggedText(TagEnum
.name
, infraSpeciesPart
));
514 } else if (nonViralName
.isInfraGeneric()){
516 tags
=getGenusOrUninomialTaggedNameCache(nonViralName
);
519 String authorCache
= getAuthorshipCache(nonViralName
);
520 if (isNotBlank(authorCache
)){
521 tags
.add(new TaggedText(TagEnum
.authors
, authorCache
));
524 //infra species marker
525 if (nonViralName
.getRank() == null || !nonViralName
.getRank().isInfraGeneric()){
526 //TODO handle exception
527 logger
.warn("Rank for autonym does not exist or is not lower than species !!");
529 Rank rank
= nonViralName
.getRank();
530 String infraGenericMarker
= rank
.getAbbreviation();
531 if (rank
.equals(Rank
.SECTION_BOTANY()) || rank
.equals(Rank
.SUBSECTION_BOTANY())){
532 infraGenericMarker
= infraGenericMarker
.replace("(bot.)", "");
534 if (isNotBlank(infraGenericMarker
)){
535 tags
.add(new TaggedText(TagEnum
.rank
, infraGenericMarker
));
540 String infraGenericPart
= CdmUtils
.Nz(nonViralName
.getInfraGenericEpithet()).trim();
541 if (isNotBlank(infraGenericPart
)){
542 tags
.add(new TaggedText(TagEnum
.name
, infraGenericPart
));
552 * Returns the tag list for rankless taxa.
553 * @param nonViralName
556 protected List
<TaggedText
> getRanklessTaggedNameCache(INonViralName nonViralName
){
557 List
<TaggedText
> tags
= getUninomialTaggedPart(nonViralName
);
558 String speciesEpi
= CdmUtils
.Nz(nonViralName
.getSpecificEpithet()).trim();
559 if (isNotBlank(speciesEpi
)){
560 tags
.add(new TaggedText(TagEnum
.name
, speciesEpi
));
563 String infraSpeciesEpi
= CdmUtils
.Nz(nonViralName
.getInfraSpecificEpithet());
564 if (isNotBlank(infraSpeciesEpi
)){
565 tags
.add(new TaggedText(TagEnum
.name
, infraSpeciesEpi
));
568 //result += " (rankless)";
569 addAppendedTaggedPhrase(tags
, nonViralName
);
574 * Returns the tag list for the first epithet (including a hybrid sign if required).
575 * @param nonViralName
578 private List
<TaggedText
> getUninomialTaggedPart(INonViralName nonViralName
) {
579 List
<TaggedText
> tags
= new ArrayList
<>();
581 if (nonViralName
.isMonomHybrid()){
582 addHybridPrefix(tags
);
585 String uninomial
= CdmUtils
.Nz(nonViralName
.getGenusOrUninomial()).trim();
586 if (isNotBlank(uninomial
)){
587 tags
.add(new TaggedText(TagEnum
.name
, uninomial
));
594 * Returns the tag list for an genus or higher taxon.
596 * @param nonViralName
599 protected List
<TaggedText
> getGenusOrUninomialTaggedNameCache(INonViralName nonViralName
){
600 List
<TaggedText
> tags
= getUninomialTaggedPart(nonViralName
);
601 addAppendedTaggedPhrase(tags
, nonViralName
);
606 * Returns the tag list for an infrageneric taxon (including species aggregates).
608 * @see #getSpeciesAggregateTaggedCache(NonViralName)
609 * @param nonViralName
612 protected List
<TaggedText
> getInfraGenusTaggedNameCache(INonViralName nonViralName
){
613 Rank rank
= nonViralName
.getRank();
614 if (rank
!= null && rank
.isSpeciesAggregate() && isBlank(nonViralName
.getAuthorshipCache())){
615 return getSpeciesAggregateTaggedCache(nonViralName
);
619 List
<TaggedText
> tags
= getUninomialTaggedPart(nonViralName
);
622 String infraGenericMarker
;
625 infraGenericMarker
= rank
.getInfraGenericMarker();
626 if (rank
.equals(Rank
.SECTION_BOTANY()) || rank
.equals(Rank
.SUBSECTION_BOTANY())){
627 infraGenericMarker
= infraGenericMarker
.replace("(bot.)", "");
629 } catch (UnknownCdmTypeException e
) {
630 infraGenericMarker
= "'unhandled infrageneric rank'";
633 infraGenericMarker
= "'undefined infrageneric rank'";
635 String infraGenEpi
= CdmUtils
.Nz(nonViralName
.getInfraGenericEpithet()).trim();
636 if (nonViralName
.isBinomHybrid()){
637 infraGenericMarker
= CdmUtils
.concat("", NOTHO
, infraGenericMarker
);
640 addInfraGenericPart(nonViralName
, tags
, infraGenericMarker
, infraGenEpi
);
642 addAppendedTaggedPhrase(tags
, nonViralName
);
648 * Default implementation for the infrageneric part of a name.
649 * This is usually the infrageneric marker and the infrageneric epitheton. But may be
650 * implemented differently e.g. for zoological names the infrageneric epitheton
651 * may be surrounded by brackets and the marker left out.
652 * @param nonViralName
654 * @param infraGenericMarker
656 protected void addInfraGenericPart(
657 @SuppressWarnings("unused") INonViralName name
,
658 List
<TaggedText
> tags
,
659 String infraGenericMarker
,
660 String infraGenEpi
) {
662 tags
.add(new TaggedText(TagEnum
.rank
, infraGenericMarker
));
665 if (isNotBlank(infraGenEpi
)){
666 tags
.add(new TaggedText(TagEnum
.name
, infraGenEpi
));
671 * Returns the tag list for a species aggregate (or similar) taxon.<BR>
672 * Possible ranks for a <i>species aggregate</i> are "aggr.", "species group", ...
673 * @param nonViralName
676 protected List
<TaggedText
> getSpeciesAggregateTaggedCache(INonViralName nonViralName
){
677 if (! isBlank(nonViralName
.getAuthorshipCache())){
678 List
<TaggedText
> result
= getSpeciesTaggedNameCache(nonViralName
);
683 List
<TaggedText
> tags
= getGenusAndSpeciesTaggedPart(nonViralName
);
685 addSpeciesAggregateTaggedEpithet(tags
, nonViralName
);
686 addAppendedTaggedPhrase(tags
, nonViralName
);
691 * Adds the aggregate tag to the tag list.
693 * @param nonViralName
695 private void addSpeciesAggregateTaggedEpithet(List
<TaggedText
> tags
, INonViralName nonViralName
) {
698 marker
= nonViralName
.getRank().getInfraGenericMarker();
699 } catch (UnknownCdmTypeException e
) {
700 marker
= "'unknown aggregat type'";
702 if (isNotBlank(marker
)){
703 tags
.add(new TaggedText(TagEnum
.rank
, marker
));
709 * Returns the tag list for a species taxon.
710 * @param nonViralName
713 protected List
<TaggedText
> getSpeciesTaggedNameCache(INonViralName nonViralName
){
714 List
<TaggedText
> tags
= getGenusAndSpeciesTaggedPart(nonViralName
);
715 addAppendedTaggedPhrase(tags
, nonViralName
);
719 protected List
<TaggedText
> getInfraSpeciesTaggedNameCache(TaxonName name
){
720 if (name
.getNameType().isZoological()){
721 boolean includeMarker
=includeInfraSpecificMarkerForZooNames(name
);
722 return getInfraSpeciesTaggedNameCache(name
, includeMarker
);
724 return getInfraSpeciesTaggedNameCache(name
, true);
728 protected boolean includeInfraSpecificMarkerForZooNames(TaxonName name
){
729 return ! (name
.isAutonym()); //only exclude marker if autonym, see also ZooNameNoMarkerCacheStrategy
733 * Creates the tag list for an infraspecific taxon. If include is true the result will contain
734 * the infraspecific marker (e.g. "var.")
735 * @param nonViralName
736 * @param includeMarker
739 protected List
<TaggedText
> getInfraSpeciesTaggedNameCache(INonViralName nonViralName
, boolean includeMarker
){
740 List
<TaggedText
> tags
= getGenusAndSpeciesTaggedPart(nonViralName
);
741 if (includeMarker
|| nonViralName
.isTrinomHybrid()){
742 String marker
= (nonViralName
.getRank().getAbbreviation()).trim().replace("null", "");
743 if (nonViralName
.isTrinomHybrid()){
744 marker
= CdmUtils
.concat("", NOTHO
, marker
);
746 if (isNotBlank(marker
)){
747 tags
.add(new TaggedText(TagEnum
.rank
, marker
));
751 String infrSpecEpi
= CdmUtils
.Nz(nonViralName
.getInfraSpecificEpithet());
753 infrSpecEpi
= infrSpecEpi
.trim().replace("null", "");
755 if (isNotBlank(infrSpecEpi
)){
756 tags
.add(new TaggedText(TagEnum
.name
, infrSpecEpi
));
759 addAppendedTaggedPhrase(tags
, nonViralName
);
765 * Adds a tag for the hybrid sign and an empty separator to avoid trailing whitespaces.
768 private void addHybridPrefix(List
<TaggedText
> tags
) {
769 tags
.add(new TaggedText(TagEnum
.hybridSign
, NonViralNameParserImplRegExBase
.hybridSign
));
770 tags
.add(new TaggedText(TagEnum
.separator
, "")); //no whitespace separator
774 * Creates the tag list for the genus and species part.
775 * @param nonViralName
778 private List
<TaggedText
> getGenusAndSpeciesTaggedPart(INonViralName nonViralName
) {
780 List
<TaggedText
> tags
= getUninomialTaggedPart(nonViralName
);
783 boolean hasInfraGenericEpi
= isNotBlank(nonViralName
.getInfraGenericEpithet());
784 if (hasInfraGenericEpi
){
785 String infrGenEpi
= nonViralName
.getInfraGenericEpithet().trim();
786 if (nonViralName
.isBinomHybrid()){
787 //maybe not correct but not really expected to happen
788 infrGenEpi
= UTF8
.HYBRID
+ infrGenEpi
;
790 infrGenEpi
= "(" + infrGenEpi
+ ")";
791 tags
.add(new TaggedText(TagEnum
.name
, infrGenEpi
));
795 String specEpi
= CdmUtils
.Nz(nonViralName
.getSpecificEpithet()).trim();
796 if (! hasInfraGenericEpi
&& nonViralName
.isBinomHybrid() ||
797 hasInfraGenericEpi
&& nonViralName
.isTrinomHybrid()){
798 addHybridPrefix(tags
);
800 if (isNotBlank(specEpi
)){
801 tags
.add(new TaggedText(TagEnum
.name
, specEpi
));
807 * Adds the tag for the appended phrase if an appended phrase exists
809 * @param nonViralName
811 protected void addAppendedTaggedPhrase(List
<TaggedText
> tags
, INonViralName nonViralName
){
812 String appendedPhrase
= nonViralName
==null ?
null : nonViralName
.getAppendedPhrase();
813 if (isNotBlank(appendedPhrase
)){
814 tags
.add(new TaggedText(TagEnum
.name
, appendedPhrase
));
819 public String
getLastEpithet(TaxonName taxonName
) {
820 Rank rank
= taxonName
.getRank();
821 if(rank
.isGenus() || rank
.isSupraGeneric()) {
822 return taxonName
.getGenusOrUninomial();
823 } else if(rank
.isInfraGeneric()) {
824 return taxonName
.getInfraGenericEpithet();
825 } else if(rank
.isSpecies()) {
826 return taxonName
.getSpecificEpithet();
828 return taxonName
.getInfraSpecificEpithet();