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
.Iterator
;
13 import java
.util
.List
;
15 import java
.util
.UUID
;
17 import org
.apache
.commons
.lang
.StringUtils
;
18 import org
.apache
.log4j
.Logger
;
20 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
21 import eu
.etaxonomy
.cdm
.common
.UTF8
;
22 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
23 import eu
.etaxonomy
.cdm
.model
.agent
.INomenclaturalAuthor
;
24 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
25 import eu
.etaxonomy
.cdm
.model
.name
.HybridRelationship
;
26 import eu
.etaxonomy
.cdm
.model
.name
.INonViralName
;
27 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalStatus
;
28 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalStatusType
;
29 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
30 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
31 import eu
.etaxonomy
.cdm
.model
.reference
.INomenclaturalReference
;
32 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
33 import eu
.etaxonomy
.cdm
.model
.term
.Representation
;
34 import eu
.etaxonomy
.cdm
.strategy
.cache
.TagEnum
;
35 import eu
.etaxonomy
.cdm
.strategy
.cache
.TaggedText
;
36 import eu
.etaxonomy
.cdm
.strategy
.exceptions
.UnknownCdmTypeException
;
37 import eu
.etaxonomy
.cdm
.strategy
.parser
.NonViralNameParserImplRegExBase
;
41 * This class is a default implementation for the INonViralNameCacheStrategy<T extends NonViralName>
43 * The method implements a cache strategy for botanical names so no method has to be overwritten by
44 * a subclass for botanic names.
45 * Where differing from this default botanic name strategy other subclasses should overwrite the
46 * existing methods, e.g. a CacheStrategy for zoological names should overwrite getAuthorAndExAuthor
49 public class TaxonNameDefaultCacheStrategy
50 extends NameCacheStrategyBase
51 implements INonViralNameCacheStrategy
{
53 private static final Logger logger
= Logger
.getLogger(TaxonNameDefaultCacheStrategy
.class);
54 private static final long serialVersionUID
= -6577757501563212669L;
56 final static UUID uuid
= UUID
.fromString("1cdda0d1-d5bc-480f-bf08-40a510a2f223");
58 protected String nameAuthorSeperator
= " ";
59 protected String basionymStart
= "(";
60 protected String basionymEnd
= ")";
61 protected String exAuthorSeperator
= " ex ";
62 private static String NOTHO
= "notho";
63 protected CharSequence basionymAuthorCombinationAuthorSeperator
= " ";
65 protected String zooAuthorYearSeperator
= ", ";
70 public UUID
getUuid(){
74 // ************************** FACTORY ******************************/
76 public static TaxonNameDefaultCacheStrategy
NewInstance(){
77 return new TaxonNameDefaultCacheStrategy();
81 // ************ CONSTRUCTOR *******************/
83 protected TaxonNameDefaultCacheStrategy(){
87 /* **************** GETTER / SETTER **************************************/
90 * String that separates the NameCache part from the AuthorCache part
93 public String
getNameAuthorSeperator() {
94 return nameAuthorSeperator
;
96 public void setNameAuthorSeperator(String nameAuthorSeperator
) {
97 this.nameAuthorSeperator
= nameAuthorSeperator
;
102 * String the basionym author part starts with e.g. '('.
103 * This should correspond with the {@link TaxonNameDefaultCacheStrategy#getBasionymEnd() basionymEnd} attribute
106 public String
getBasionymStart() {
107 return basionymStart
;
109 public void setBasionymStart(String basionymStart
) {
110 this.basionymStart
= basionymStart
;
114 * String the basionym author part ends with e.g. ')'.
115 * This should correspond with the {@link TaxonNameDefaultCacheStrategy#getBasionymStart() basionymStart} attribute
118 public String
getBasionymEnd() {
121 public void setBasionymEnd(String basionymEnd
) {
122 this.basionymEnd
= basionymEnd
;
127 * String to separate ex author from author.
130 public String
getExAuthorSeperator() {
131 return exAuthorSeperator
;
133 public void setExAuthorSeperator(String exAuthorSeperator
) {
134 this.exAuthorSeperator
= exAuthorSeperator
;
139 * String that separates the basionym/original_combination author part from the combination author part
142 public CharSequence
getBasionymAuthorCombinationAuthorSeperator() {
143 return basionymAuthorCombinationAuthorSeperator
;
147 public void setBasionymAuthorCombinationAuthorSeperator( CharSequence basionymAuthorCombinationAuthorSeperator
) {
148 this.basionymAuthorCombinationAuthorSeperator
= basionymAuthorCombinationAuthorSeperator
;
151 public String
getZooAuthorYearSeperator() {
152 return zooAuthorYearSeperator
;
154 public void setZooAuthorYearSeperator(String authorYearSeperator
) {
155 this.zooAuthorYearSeperator
= authorYearSeperator
;
158 // ******************* Authorship ******************************/
161 public String
getAuthorshipCache(TaxonName taxonName
) {
162 if (taxonName
== null){
164 }else if (taxonName
.getNameType().isViral()){
166 }else if(taxonName
.isProtectedAuthorshipCache() == true) {
168 return taxonName
.getAuthorshipCache();
170 return getNonCacheAuthorshipCache(taxonName
);
175 * Returns the authorshipcache string for the atomized authorship fields. Does not use the authorship field.
176 * @throws NullPointerException if nonViralName is null.
180 protected String
getNonCacheAuthorshipCache(TaxonName nonViralName
){
181 if (nonViralName
.getNameType().isZoological()){
182 return this.getZoologicalNonCacheAuthorshipCache(nonViralName
);
185 INomenclaturalAuthor combinationAuthor
= nonViralName
.getCombinationAuthorship();
186 INomenclaturalAuthor exCombinationAuthor
= nonViralName
.getExCombinationAuthorship();
187 INomenclaturalAuthor basionymAuthor
= nonViralName
.getBasionymAuthorship();
188 INomenclaturalAuthor exBasionymAuthor
= nonViralName
.getExBasionymAuthorship();
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 protected String
getZoologicalNonCacheAuthorshipCache(TaxonName nonViralName
) {
207 if (nonViralName
== null){
211 INomenclaturalAuthor combinationAuthor
= nonViralName
.getCombinationAuthorship();
212 INomenclaturalAuthor exCombinationAuthor
= nonViralName
.getExCombinationAuthorship();
213 INomenclaturalAuthor basionymAuthor
= nonViralName
.getBasionymAuthorship();
214 INomenclaturalAuthor exBasionymAuthor
= nonViralName
.getExBasionymAuthorship();
215 Integer publicationYear
= nonViralName
.getPublicationYear();
216 Integer originalPublicationYear
= nonViralName
.getOriginalPublicationYear();
218 String basionymPart
= "";
219 String authorPart
= "";
221 if (basionymAuthor
!= null || exBasionymAuthor
!= null || originalPublicationYear
!= null ){
222 String authorAndEx
= getAuthorAndExAuthor(basionymAuthor
, exBasionymAuthor
);
223 String originalPublicationYearString
= originalPublicationYear
== null ?
null : String
.valueOf(originalPublicationYear
);
224 String authorAndExAndYear
= CdmUtils
.concat(zooAuthorYearSeperator
, authorAndEx
, originalPublicationYearString
);
225 basionymPart
= basionymStart
+ authorAndExAndYear
+ basionymEnd
;
227 if (combinationAuthor
!= null || exCombinationAuthor
!= null){
228 String authorAndEx
= getAuthorAndExAuthor(combinationAuthor
, exCombinationAuthor
);
229 String publicationYearString
= publicationYear
== null ?
null : String
.valueOf(publicationYear
);
230 authorPart
= CdmUtils
.concat(zooAuthorYearSeperator
, authorAndEx
, publicationYearString
);
232 result
= CdmUtils
.concat(basionymAuthorCombinationAuthorSeperator
, basionymPart
, authorPart
);
241 * Returns the AuthorCache part for a combination of an author and an ex author. This applies on
242 * combination authors as well as on basionym/orginal combination authors.
243 * The correct order is exAuthor ex author though some botanist do not know about and do it the
244 * other way round. (see 46.4-46.6 ICBN (Vienna Code, 2006))
246 * @param author the author
247 * @param exAuthor the ex-author
250 protected String
getAuthorAndExAuthor(INomenclaturalAuthor author
, INomenclaturalAuthor exAuthor
){
251 String authorString
= "";
252 String exAuthorString
= "";
254 authorString
= CdmUtils
.Nz(author
.getNomenclaturalTitle());
256 if (exAuthor
!= null){
257 exAuthorString
= CdmUtils
.Nz(exAuthor
.getNomenclaturalTitle());
258 exAuthorString
+= exAuthorSeperator
;
260 String result
= exAuthorString
+ authorString
;
267 * Checks if the given name should include the author in it's cached version.<BR>
268 * This is usually the case but not for <i>species aggregates</i>.
269 * @param nonViralName
272 protected boolean nameIncludesAuthorship(INonViralName nonViralName
){
273 Rank rank
= nonViralName
.getRank();
274 if (rank
!= null && rank
.isSpeciesAggregate()){
281 // ************* TAGGED NAME ***************************************/
284 public List
<TaggedText
> getTaggedFullTitle(TaxonName nonViralName
) {
285 List
<TaggedText
> tags
= new ArrayList
<>();
288 if (nonViralName
== null){
292 //protected full title cache
293 if (nonViralName
.isProtectedFullTitleCache()){
294 tags
.add(new TaggedText(TagEnum
.fullName
, nonViralName
.getFullTitleCache()));
299 // String titleCache = nonViralName.getTitleCache();
300 List
<TaggedText
> titleTags
= getTaggedTitle(nonViralName
);
301 tags
.addAll(titleTags
);
304 String microReference
= nonViralName
.getNomenclaturalMicroReference();
305 INomenclaturalReference ref
= nonViralName
.getNomenclaturalReference();
306 String referenceCache
= null;
308 Reference reference
= HibernateProxyHelper
.deproxy(ref
, Reference
.class);
309 referenceCache
= reference
.getNomenclaturalCitation(microReference
);
312 if (StringUtils
.isNotBlank(referenceCache
)){
313 if (! referenceCache
.trim().startsWith("in ")){
314 String refConcat
= ", ";
315 tags
.add(new TaggedText(TagEnum
.separator
, refConcat
));
317 tags
.add(new TaggedText(TagEnum
.reference
, referenceCache
));
320 addOriginalSpelling(tags
, nonViralName
);
322 //nomenclatural status
323 tags
.addAll(getNomStatusTags(nonViralName
, true, false));
330 * @param nonViralName
335 public List
<TaggedText
> getNomStatusTags(TaxonName nonViralName
, boolean includeSeparatorBefore
,
336 boolean includeSeparatorAfter
) {
338 Set
<NomenclaturalStatus
> ncStati
= nonViralName
.getStatus();
339 Iterator
<NomenclaturalStatus
> iterator
= ncStati
.iterator();
340 List
<TaggedText
> nomStatusTags
= new ArrayList
<>();
341 while (iterator
.hasNext()) {
342 NomenclaturalStatus ncStatus
= iterator
.next();
343 // since the NewInstance method of nomencatural status allows null as parameter
344 // we have to check for null values here
345 String nomStatusStr
= "not defined";
346 if(ncStatus
.getType() != null){
347 NomenclaturalStatusType statusType
= ncStatus
.getType();
348 Language lang
= Language
.LATIN();
349 Representation repr
= statusType
.getRepresentation(lang
);
351 nomStatusStr
= repr
.getAbbreviatedLabel();
353 String message
= "No latin representation available for nom. status. " + statusType
.getTitleCache();
354 logger
.warn(message
);
355 throw new IllegalStateException(message
);
357 }else if(StringUtils
.isNotBlank(ncStatus
.getRuleConsidered())){
358 nomStatusStr
= ncStatus
.getRuleConsidered();
360 String statusSeparator
= ", ";
361 if (includeSeparatorBefore
){
362 nomStatusTags
.add(new TaggedText(TagEnum
.separator
, statusSeparator
));
364 nomStatusTags
.add(new TaggedText(TagEnum
.nomStatus
, nomStatusStr
));
365 if (includeSeparatorAfter
){
366 nomStatusTags
.add(new TaggedText(TagEnum
.postSeparator
, ","));
369 return nomStatusTags
;
373 public List
<TaggedText
> getTaggedTitle(TaxonName taxonName
) {
374 if (taxonName
== null){
378 List
<TaggedText
> tags
= new ArrayList
<>();
380 if (taxonName
.isViral()){
381 return getViralTaggedTitle(taxonName
);
383 //TODO how to handle protected fullTitleCache here?
384 if (taxonName
.isProtectedTitleCache()){
385 //protected title cache
386 tags
.add(new TaggedText(TagEnum
.name
, taxonName
.getTitleCache()));
388 }else if (taxonName
.isHybridFormula()){
390 String hybridSeparator
= NonViralNameParserImplRegExBase
.hybridSign
;
391 boolean isFirst
= true;
392 List
<HybridRelationship
> rels
= taxonName
.getOrderedChildRelationships();
393 for (HybridRelationship rel
: rels
){
395 tags
.add(new TaggedText(TagEnum
.hybridSign
, hybridSeparator
));
398 tags
.addAll(getTaggedTitle(rel
.getParentName()));
401 }else if (taxonName
.isAutonym()){
403 tags
.addAll(handleTaggedAutonym(taxonName
));
405 List
<TaggedText
> nameTags
= getTaggedName(taxonName
);
406 tags
.addAll(nameTags
);
407 String authorCache
= getAuthorshipCache(taxonName
);
408 if (StringUtils
.isNotBlank(authorCache
)){
409 tags
.add(new TaggedText(TagEnum
.authors
, authorCache
));
420 private List
<TaggedText
> getViralTaggedTitle(TaxonName viralName
) {
421 List
<TaggedText
> tags
= new ArrayList
<>();
422 if (viralName
.isProtectedTitleCache()){
423 //protected title cache
424 tags
.add(new TaggedText(TagEnum
.name
, viralName
.getTitleCache()));
427 if (StringUtils
.isNotBlank(viralName
.getAcronym())){
428 //this is not according to the code
429 tags
.add(new TaggedText(TagEnum
.name
, viralName
.getAcronym()));
436 * Returns the tag list of the name part (without author and reference).
437 * @param nonViralName
441 public List
<TaggedText
> getTaggedName(TaxonName nonViralName
) {
442 if (nonViralName
== null){
444 }else if (nonViralName
.getNameType().isViral()){
447 List
<TaggedText
> tags
= new ArrayList
<>();
448 Rank rank
= nonViralName
.getRank();
450 if (nonViralName
.isProtectedNameCache()){
451 tags
.add(new TaggedText(TagEnum
.name
, nonViralName
.getNameCache()));
452 }else if (nonViralName
.isHybridFormula()){
454 String hybridSeparator
= NonViralNameParserImplRegExBase
.hybridSign
;
455 boolean isFirst
= true;
456 List
<HybridRelationship
> rels
= nonViralName
.getOrderedChildRelationships();
457 for (HybridRelationship rel
: rels
){
459 tags
.add(new TaggedText(TagEnum
.hybridSign
, hybridSeparator
));
462 tags
.addAll(getTaggedName(rel
.getParentName()));
466 }else if (rank
== null){
467 tags
= getRanklessTaggedNameCache(nonViralName
);
468 // }else if (nonViralName.isInfragenericUnranked()){
469 // result = getUnrankedInfragenericNameCache(nonViralName);
470 }else if (rank
.isInfraSpecific()){
471 tags
= getInfraSpeciesTaggedNameCache(nonViralName
);
472 }else if (rank
.isSpecies() || isAggregateWithAuthorship(nonViralName
, rank
) ){ //exception see #4288
473 tags
= getSpeciesTaggedNameCache(nonViralName
);
474 }else if (rank
.isInfraGeneric()){
475 tags
= getInfraGenusTaggedNameCache(nonViralName
);
476 }else if (rank
.isGenus()){
477 tags
= getGenusOrUninomialTaggedNameCache(nonViralName
);
478 }else if (rank
.isSupraGeneric()){
479 tags
= getGenusOrUninomialTaggedNameCache(nonViralName
);
481 tags
= getRanklessTaggedNameCache(nonViralName
);
482 logger
.warn("Rank does not belong to a rank class: " + rank
.getTitleCache() + ". Used rankless nameCache for name " + nonViralName
.getUuid());
484 //TODO handle appended phrase here instead of different places, check first if this is true for all
494 //***************************** PRIVATES ***************************************/
497 private boolean isAggregateWithAuthorship(TaxonName nonViralName
, Rank rank
) {
501 return rank
.isSpeciesAggregate() && ( isNotBlank(nonViralName
.getAuthorshipCache()) || nonViralName
.getNomenclaturalReference() != null );
507 * Returns the tag list for an autonym taxon.
509 * @see NonViralName#isAutonym()
510 * @see BotanicalName#isAutonym()
511 * @param nonViralName
514 private List
<TaggedText
> handleTaggedAutonym(TaxonName nonViralName
) {
515 List
<TaggedText
> tags
= null;
516 if (nonViralName
.isInfraSpecific()){
518 tags
= getSpeciesTaggedNameCache(nonViralName
);
521 String authorCache
= getAuthorshipCache(nonViralName
);
522 if (StringUtils
.isNotBlank(authorCache
)){
523 tags
.add(new TaggedText(TagEnum
.authors
, authorCache
));
527 //infra species marker
528 if (nonViralName
.getRank() == null || !nonViralName
.getRank().isInfraSpecific()){
529 //TODO handle exception
530 logger
.warn("Rank for autonym does not exist or is not lower than species !!");
532 String infraSpeciesMarker
= nonViralName
.getRank().getAbbreviation();
533 if (nonViralName
.isTrinomHybrid()){
534 infraSpeciesMarker
= CdmUtils
.concat("", NOTHO
, infraSpeciesMarker
);
536 if (StringUtils
.isNotBlank(infraSpeciesMarker
)){
537 tags
.add(new TaggedText(TagEnum
.rank
, infraSpeciesMarker
));
542 String infraSpeciesPart
= CdmUtils
.Nz(nonViralName
.getInfraSpecificEpithet()).trim();
543 if (StringUtils
.isNotBlank(infraSpeciesPart
)){
544 tags
.add(new TaggedText(TagEnum
.name
, infraSpeciesPart
));
547 } else if (nonViralName
.isInfraGeneric()){
549 tags
=getGenusOrUninomialTaggedNameCache(nonViralName
);
552 //infra species marker
553 if (nonViralName
.getRank() == null || !nonViralName
.getRank().isInfraGeneric()){
554 //TODO handle exception
555 logger
.warn("Rank for autonym does not exist or is not lower than species !!");
557 Rank rank
= nonViralName
.getRank();
558 String infraGenericMarker
= rank
.getAbbreviation();
559 if (rank
.equals(Rank
.SECTION_BOTANY()) || rank
.equals(Rank
.SUBSECTION_BOTANY())){
560 infraGenericMarker
= infraGenericMarker
.replace("(bot.)", "");
562 if (StringUtils
.isNotBlank(infraGenericMarker
)){
563 tags
.add(new TaggedText(TagEnum
.rank
, infraGenericMarker
));
568 String infraGenericPart
= CdmUtils
.Nz(nonViralName
.getInfraGenericEpithet()).trim();
569 if (StringUtils
.isNotBlank(infraGenericPart
)){
570 tags
.add(new TaggedText(TagEnum
.name
, infraGenericPart
));
581 * Returns the tag list for rankless taxa.
582 * @param nonViralName
585 protected List
<TaggedText
> getRanklessTaggedNameCache(INonViralName nonViralName
){
586 List
<TaggedText
> tags
= getUninomialTaggedPart(nonViralName
);
587 String speciesEpi
= CdmUtils
.Nz(nonViralName
.getSpecificEpithet()).trim();
588 if (StringUtils
.isNotBlank(speciesEpi
)){
589 tags
.add(new TaggedText(TagEnum
.name
, speciesEpi
));
592 String infraSpeciesEpi
= CdmUtils
.Nz(nonViralName
.getInfraSpecificEpithet());
593 if (StringUtils
.isNotBlank(infraSpeciesEpi
)){
594 tags
.add(new TaggedText(TagEnum
.name
, infraSpeciesEpi
));
597 //result += " (rankless)";
598 addAppendedTaggedPhrase(tags
, nonViralName
);
603 * Returns the tag list for the first epithet (including a hybrid sign if required).
604 * @param nonViralName
607 private List
<TaggedText
> getUninomialTaggedPart(INonViralName nonViralName
) {
608 List
<TaggedText
> tags
= new ArrayList
<>();
610 if (nonViralName
.isMonomHybrid()){
611 addHybridPrefix(tags
);
614 String uninomial
= CdmUtils
.Nz(nonViralName
.getGenusOrUninomial()).trim();
615 if (StringUtils
.isNotBlank(uninomial
)){
616 tags
.add(new TaggedText(TagEnum
.name
, uninomial
));
623 * Returns the tag list for an genus or higher taxon.
625 * @param nonViralName
628 protected List
<TaggedText
> getGenusOrUninomialTaggedNameCache(INonViralName nonViralName
){
629 List
<TaggedText
> tags
= getUninomialTaggedPart(nonViralName
);
630 addAppendedTaggedPhrase(tags
, nonViralName
);
635 * Returns the tag list for an infrageneric taxon (including species aggregates).
637 * @see #getSpeciesAggregateTaggedCache(NonViralName)
638 * @param nonViralName
641 protected List
<TaggedText
> getInfraGenusTaggedNameCache(INonViralName nonViralName
){
642 Rank rank
= nonViralName
.getRank();
643 if (rank
!= null && rank
.isSpeciesAggregate() && isBlank(nonViralName
.getAuthorshipCache())){
644 return getSpeciesAggregateTaggedCache(nonViralName
);
648 List
<TaggedText
> tags
= getUninomialTaggedPart(nonViralName
);
651 String infraGenericMarker
;
654 infraGenericMarker
= rank
.getInfraGenericMarker();
655 if (rank
.equals(Rank
.SECTION_BOTANY()) || rank
.equals(Rank
.SUBSECTION_BOTANY())){
656 infraGenericMarker
= infraGenericMarker
.replace("(bot.)", "");
658 } catch (UnknownCdmTypeException e
) {
659 infraGenericMarker
= "'unhandled infrageneric rank'";
662 infraGenericMarker
= "'undefined infrageneric rank'";
664 String infraGenEpi
= CdmUtils
.Nz(nonViralName
.getInfraGenericEpithet()).trim();
665 if (nonViralName
.isBinomHybrid()){
666 infraGenericMarker
= CdmUtils
.concat("", NOTHO
, infraGenericMarker
);
669 addInfraGenericPart(nonViralName
, tags
, infraGenericMarker
, infraGenEpi
);
671 addAppendedTaggedPhrase(tags
, nonViralName
);
677 * Default implementation for the infrageneric part of a name.
678 * This is usually the infrageneric marker and the infrageneric epitheton. But may be
679 * implemented differently e.g. for zoological names the infrageneric epitheton
680 * may be surrounded by brackets and the marker left out.
681 * @param nonViralName
683 * @param infraGenericMarker
685 protected void addInfraGenericPart(
686 @SuppressWarnings("unused") INonViralName name
,
687 List
<TaggedText
> tags
,
688 String infraGenericMarker
,
689 String infraGenEpi
) {
691 tags
.add(new TaggedText(TagEnum
.rank
, infraGenericMarker
));
694 if (StringUtils
.isNotBlank(infraGenEpi
)){
695 tags
.add(new TaggedText(TagEnum
.name
, infraGenEpi
));
700 * Returns the tag list for a species aggregate (or similar) taxon.<BR>
701 * Possible ranks for a <i>species aggregate</i> are "aggr.", "species group", ...
702 * @param nonViralName
705 protected List
<TaggedText
> getSpeciesAggregateTaggedCache(INonViralName nonViralName
){
706 if (! isBlank(nonViralName
.getAuthorshipCache())){
707 List
<TaggedText
> result
= getSpeciesTaggedNameCache(nonViralName
);
712 List
<TaggedText
> tags
= getGenusAndSpeciesTaggedPart(nonViralName
);
714 addSpeciesAggregateTaggedEpithet(tags
, nonViralName
);
715 addAppendedTaggedPhrase(tags
, nonViralName
);
720 * Adds the aggregate tag to the tag list.
722 * @param nonViralName
724 private void addSpeciesAggregateTaggedEpithet(List
<TaggedText
> tags
, INonViralName nonViralName
) {
727 marker
= nonViralName
.getRank().getInfraGenericMarker();
728 } catch (UnknownCdmTypeException e
) {
729 marker
= "'unknown aggregat type'";
731 if (StringUtils
.isNotBlank(marker
)){
732 tags
.add(new TaggedText(TagEnum
.rank
, marker
));
738 * Returns the tag list for a species taxon.
739 * @param nonViralName
742 protected List
<TaggedText
> getSpeciesTaggedNameCache(INonViralName nonViralName
){
743 List
<TaggedText
> tags
= getGenusAndSpeciesTaggedPart(nonViralName
);
744 addAppendedTaggedPhrase(tags
, nonViralName
);
749 * Creates the tag list for an infraspecific taxon. In include is true the result will contain
750 * @param nonViralName
753 protected List
<TaggedText
> getInfraSpeciesTaggedNameCache(TaxonName nonViralName
){
754 if (nonViralName
.getNameType().isZoological()){
755 boolean includeMarker
= ! (nonViralName
.isAutonym());
756 return getInfraSpeciesTaggedNameCache(nonViralName
, includeMarker
);
758 return getInfraSpeciesTaggedNameCache(nonViralName
, true);
763 * Creates the tag list for an infraspecific taxon. If include is true the result will contain
764 * the infraspecific marker (e.g. "var.")
765 * @param nonViralName
766 * @param includeMarker
769 protected List
<TaggedText
> getInfraSpeciesTaggedNameCache(INonViralName nonViralName
, boolean includeMarker
){
770 List
<TaggedText
> tags
= getGenusAndSpeciesTaggedPart(nonViralName
);
771 if (includeMarker
|| nonViralName
.isTrinomHybrid()){
772 String marker
= (nonViralName
.getRank().getAbbreviation()).trim().replace("null", "");
773 if (nonViralName
.isTrinomHybrid()){
774 marker
= CdmUtils
.concat("", NOTHO
, marker
);
776 if (StringUtils
.isNotBlank(marker
)){
777 tags
.add(new TaggedText(TagEnum
.rank
, marker
));
781 String infrSpecEpi
= CdmUtils
.Nz(nonViralName
.getInfraSpecificEpithet());
783 infrSpecEpi
= infrSpecEpi
.trim().replace("null", "");
785 if (StringUtils
.isNotBlank(infrSpecEpi
)){
786 tags
.add(new TaggedText(TagEnum
.name
, infrSpecEpi
));
789 addAppendedTaggedPhrase(tags
, nonViralName
);
795 * Adds a tag for the hybrid sign and an empty separator to avoid trailing whitespaces.
798 private void addHybridPrefix(List
<TaggedText
> tags
) {
799 tags
.add(new TaggedText(TagEnum
.hybridSign
, NonViralNameParserImplRegExBase
.hybridSign
));
800 tags
.add(new TaggedText(TagEnum
.separator
, "")); //no whitespace separator
804 * Creates the tag list for the genus and species part.
805 * @param nonViralName
808 private List
<TaggedText
> getGenusAndSpeciesTaggedPart(INonViralName nonViralName
) {
810 List
<TaggedText
> tags
= getUninomialTaggedPart(nonViralName
);
813 boolean hasInfraGenericEpi
= StringUtils
.isNotBlank(nonViralName
.getInfraGenericEpithet());
814 if (hasInfraGenericEpi
){
815 String infrGenEpi
= nonViralName
.getInfraGenericEpithet().trim();
816 if (nonViralName
.isBinomHybrid()){
817 //maybe not correct but not really expected to happen
818 infrGenEpi
= UTF8
.HYBRID
+ infrGenEpi
;
820 infrGenEpi
= "(" + infrGenEpi
+ ")";
821 tags
.add(new TaggedText(TagEnum
.name
, infrGenEpi
));
825 String specEpi
= CdmUtils
.Nz(nonViralName
.getSpecificEpithet()).trim();
826 if (! hasInfraGenericEpi
&& nonViralName
.isBinomHybrid() ||
827 hasInfraGenericEpi
&& nonViralName
.isTrinomHybrid()){
828 addHybridPrefix(tags
);
830 if (StringUtils
.isNotBlank(specEpi
)){
831 tags
.add(new TaggedText(TagEnum
.name
, specEpi
));
837 * Adds the tag for the appended phrase if an appended phrase exists
839 * @param nonViralName
841 protected void addAppendedTaggedPhrase(List
<TaggedText
> tags
, INonViralName nonViralName
){
842 String appendedPhrase
= nonViralName
==null ?
null : nonViralName
.getAppendedPhrase();
843 if (StringUtils
.isNotEmpty(appendedPhrase
)){
844 tags
.add(new TaggedText(TagEnum
.name
, appendedPhrase
));
850 public String
getLastEpithet(TaxonName taxonName
) {
851 Rank rank
= taxonName
.getRank();
852 if(rank
.isGenus() || rank
.isSupraGeneric()) {
853 return taxonName
.getGenusOrUninomial();
854 } else if(rank
.isInfraGeneric()) {
855 return taxonName
.getInfraGenericEpithet();
856 } else if(rank
.isSpecies()) {
857 return taxonName
.getSpecificEpithet();
859 return taxonName
.getInfraSpecificEpithet();
868 protected List
<TaggedText
> doGetTaggedTitle(TaxonName taxonName
) {
869 List
<TaggedText
> tags
= new ArrayList
<>();
870 if (taxonName
.getNameType().isViral()){
871 String acronym
= taxonName
.getAcronym();
872 tags
.add(new TaggedText(TagEnum
.name
, acronym
));
874 }else if (taxonName
.isHybridFormula()){
876 String hybridSeparator
= NonViralNameParserImplRegExBase
.hybridSign
;
877 boolean isFirst
= true;
878 List
<HybridRelationship
> rels
= taxonName
.getOrderedChildRelationships();
879 for (HybridRelationship rel
: rels
){
881 tags
.add(new TaggedText(TagEnum
.hybridSign
, hybridSeparator
));
884 tags
.addAll(getTaggedTitle(rel
.getParentName()));
887 }else if (taxonName
.isAutonym()){
889 tags
.addAll(handleTaggedAutonym(taxonName
));
891 List
<TaggedText
> nameTags
= getTaggedName(taxonName
);
892 tags
.addAll(nameTags
);
893 String authorCache
= getAuthorshipCache(taxonName
);
894 if (StringUtils
.isNotBlank(authorCache
)){
895 tags
.add(new TaggedText(TagEnum
.authors
, authorCache
));