Revision 7b1ac952
Added by Andreas Müller over 12 years ago
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/name/NonViralNameDefaultCacheStrategy.java | ||
---|---|---|
29 | 29 |
import eu.etaxonomy.cdm.model.name.NonViralName; |
30 | 30 |
import eu.etaxonomy.cdm.model.name.Rank; |
31 | 31 |
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference; |
32 |
import eu.etaxonomy.cdm.strategy.TagEnum; |
|
33 |
import eu.etaxonomy.cdm.strategy.TaggedText; |
|
32 | 34 |
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException; |
33 | 35 |
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImplRegExBase; |
34 | 36 |
|
... | ... | |
71 | 73 |
return new NonViralNameDefaultCacheStrategy(); |
72 | 74 |
} |
73 | 75 |
|
76 |
/** |
|
77 |
* Factory method |
|
78 |
* @return NonViralNameDefaultCacheStrategy A new instance of NonViralNameDefaultCacheStrategy |
|
79 |
*/ |
|
80 |
public static <T extends NonViralName<?>> NonViralNameDefaultCacheStrategy<T> NewInstance(Class<T> clazz){ |
|
81 |
return new NonViralNameDefaultCacheStrategy<T>(); |
|
82 |
} |
|
83 |
|
|
74 | 84 |
/** |
75 | 85 |
* Constructor |
76 | 86 |
*/ |
... | ... | |
154 | 164 |
|
155 | 165 |
|
156 | 166 |
//** *****************************************************************************************/ |
157 |
|
|
158 |
|
|
167 |
|
|
159 | 168 |
/* (non-Javadoc) |
160 |
* @see eu.etaxonomy.cdm.strategy.INameCacheStrategy#getNameCache()
|
|
169 |
* @see eu.etaxonomy.cdm.strategy.cache.name.NameCacheStrategyBase#getTitleCache(eu.etaxonomy.cdm.model.name.TaxonNameBase)
|
|
161 | 170 |
*/ |
162 | 171 |
@Override |
163 | 172 |
public String getTitleCache(T nonViralName) { |
173 |
List<TaggedText> tags = getTaggedTitle(nonViralName); |
|
174 |
if (tags == null){ |
|
175 |
return null; |
|
176 |
}else{ |
|
177 |
String result = createString(tags); |
|
178 |
return result; |
|
179 |
} |
|
180 |
} |
|
181 |
|
|
182 |
|
|
183 |
|
|
184 |
public String getTitleCache_OLD(T nonViralName) { |
|
164 | 185 |
if (nonViralName == null){ |
165 | 186 |
return null; |
166 | 187 |
} |
... | ... | |
194 | 215 |
} |
195 | 216 |
|
196 | 217 |
|
218 |
/** |
|
219 |
* Creates a string from tagged text. |
|
220 |
* @param tags |
|
221 |
* @return |
|
222 |
*/ |
|
223 |
private String createString(List<TaggedText> tags) { |
|
224 |
StringBuffer result = new StringBuffer(); |
|
225 |
|
|
226 |
boolean isSeparator; |
|
227 |
boolean wasSeparator = true; //true for start tag |
|
228 |
for (TaggedText tag: tags){ |
|
229 |
isSeparator = tag.getType().equals(TagEnum.separator); |
|
230 |
if (! wasSeparator && ! isSeparator ){ |
|
231 |
result.append(" "); |
|
232 |
} |
|
233 |
result.append(tag.getText()); |
|
234 |
wasSeparator = isSeparator; |
|
235 |
} |
|
236 |
return result.toString(); |
|
237 |
} |
|
238 |
|
|
239 |
|
|
240 |
/** |
|
241 |
* @param nonViralName |
|
242 |
* @param speciesPart |
|
243 |
* @return |
|
244 |
*/ |
|
245 |
private List<TaggedText> handleTaggedAutonym(T nonViralName) { |
|
246 |
|
|
247 |
//species part |
|
248 |
List<TaggedText> tags = getSpeciesTaggedNameCache(nonViralName); |
|
249 |
|
|
250 |
//author |
|
251 |
//TODO should this include basionym authors and ex authors |
|
252 |
INomenclaturalAuthor author = nonViralName.getCombinationAuthorTeam(); |
|
253 |
String authorPart = ""; |
|
254 |
if (author != null){ |
|
255 |
authorPart = CdmUtils.Nz(author.getNomenclaturalTitle()); |
|
256 |
} |
|
257 |
INomenclaturalAuthor basAuthor = nonViralName.getBasionymAuthorTeam(); |
|
258 |
String basAuthorPart = ""; |
|
259 |
if (basAuthor != null){ |
|
260 |
basAuthorPart = CdmUtils.Nz(basAuthor.getNomenclaturalTitle()); |
|
261 |
} |
|
262 |
if (! "".equals(basAuthorPart)){ |
|
263 |
authorPart = "("+ basAuthorPart +") " + authorPart; |
|
264 |
} |
|
265 |
if (StringUtils.isNotBlank(authorPart)){ |
|
266 |
tags.add(new TaggedText(TagEnum.authors, authorPart)); |
|
267 |
} |
|
268 |
|
|
269 |
|
|
270 |
//infra species marker |
|
271 |
if (nonViralName.getRank() == null || !nonViralName.getRank().isInfraSpecific()){ |
|
272 |
//TODO handle exception |
|
273 |
logger.warn("Rank for autonym does not exist or is not lower than species !!"); |
|
274 |
}else{ |
|
275 |
String infraSpeciesMarker = nonViralName.getRank().getAbbreviation(); |
|
276 |
if (StringUtils.isNotBlank(infraSpeciesMarker)){ |
|
277 |
tags.add(new TaggedText(TagEnum.rank, infraSpeciesMarker)); |
|
278 |
} |
|
279 |
} |
|
280 |
|
|
281 |
//infra species |
|
282 |
String infraSpeciesPart = CdmUtils.Nz(nonViralName.getInfraSpecificEpithet()).trim().replace("null", ""); |
|
283 |
if (StringUtils.isNotBlank(infraSpeciesPart)){ |
|
284 |
tags.add(new TaggedText(TagEnum.name, infraSpeciesPart)); |
|
285 |
} |
|
286 |
|
|
287 |
return tags; |
|
288 |
} |
|
289 |
|
|
197 | 290 |
/** |
198 | 291 |
* @param nonViralName |
199 | 292 |
* @param speciesPart |
... | ... | |
231 | 324 |
return result; |
232 | 325 |
} |
233 | 326 |
|
234 |
protected boolean nameIncludesAuthorship(NonViralName nonViralName){ |
|
327 |
protected boolean nameIncludesAuthorship(NonViralName<?> nonViralName){
|
|
235 | 328 |
Rank rank = nonViralName.getRank(); |
236 | 329 |
if (rank != null && rank.isSpeciesAggregate()){ |
237 | 330 |
return false; |
... | ... | |
240 | 333 |
} |
241 | 334 |
} |
242 | 335 |
|
243 |
|
|
244 |
|
|
245 |
|
|
246 |
|
|
336 |
/* (non-Javadoc) |
|
337 |
* @see eu.etaxonomy.cdm.strategy.cache.name.NameCacheStrategyBase#getFullTitleCache(eu.etaxonomy.cdm.model.name.TaxonNameBase) |
|
338 |
*/ |
|
247 | 339 |
@Override |
248 | 340 |
public String getFullTitleCache(T nonViralName) { |
341 |
List<TaggedText> tags = getTaggedFullTitle(nonViralName); |
|
342 |
if (tags == null){ |
|
343 |
return null; |
|
344 |
}else{ |
|
345 |
String result = createString(tags); |
|
346 |
return result; |
|
347 |
} |
|
348 |
} |
|
349 |
|
|
350 |
|
|
351 |
public String getFullTitleCache_OLD(T nonViralName) { |
|
249 | 352 |
//null |
250 | 353 |
if (nonViralName == null){ |
251 | 354 |
return null; |
... | ... | |
302 | 405 |
return result; |
303 | 406 |
} |
304 | 407 |
|
408 |
|
|
305 | 409 |
|
306 | 410 |
/** |
307 | 411 |
* Generates and returns the "name cache" (only scientific name without author teams and year). |
308 | 412 |
* @see eu.etaxonomy.cdm.strategy.cache.name.INameCacheStrategy#getNameCache(eu.etaxonomy.cdm.model.name.TaxonNameBase) |
309 | 413 |
*/ |
414 |
@Override |
|
310 | 415 |
public String getNameCache(T nonViralName) { |
416 |
List<TaggedText> tags = getNameTags(nonViralName); |
|
417 |
if (tags == null){ |
|
418 |
return null; |
|
419 |
}else{ |
|
420 |
String result = createString(tags); |
|
421 |
return result; |
|
422 |
} |
|
423 |
} |
|
424 |
|
|
425 |
public String getNameCache_OLD(T nonViralName) { |
|
311 | 426 |
if (nonViralName == null){ |
312 | 427 |
return null; |
313 | 428 |
} |
... | ... | |
336 | 451 |
} |
337 | 452 |
return result; |
338 | 453 |
} |
339 |
// |
|
340 |
// |
|
341 |
// /** |
|
342 |
// * @param nonViralName |
|
343 |
// * @return |
|
344 |
// */ |
|
345 |
// private boolean isInfragenericUnranked(T nonViralName) { |
|
346 |
// Rank rank = nonViralName.getRank(); |
|
347 |
// if (rank == null || ! rank.equals(Rank.UNRANKED())){ |
|
348 |
// return false; |
|
349 |
// } |
|
350 |
// if (StringUtils.isBlank(nonViralName.getSpecificEpithet()) && StringUtils.isBlank(nonViralName.getInfraSpecificEpithet()) ){ |
|
351 |
// return true; |
|
352 |
// }else{ |
|
353 |
// return false; |
|
354 |
// } |
|
355 |
// } |
|
356 | 454 |
|
357 | 455 |
|
358 | 456 |
private String getUnrankedInfragenericNameCache(T nonViralName) { |
... | ... | |
434 | 532 |
|
435 | 533 |
} |
436 | 534 |
|
535 |
// ************* TAGGED NAME ***************************************/ |
|
437 | 536 |
|
537 |
/* (non-Javadoc) |
|
538 |
* @see eu.etaxonomy.cdm.strategy.cache.name.NameCacheStrategyBase#getTaggedTitle(eu.etaxonomy.cdm.model.name.TaxonNameBase) |
|
539 |
*/ |
|
540 |
@Override |
|
541 |
public List<TaggedText> getTaggedFullTitle(T nonViralName) { |
|
542 |
List<TaggedText> tags = new ArrayList<TaggedText>(); |
|
543 |
|
|
544 |
//null |
|
545 |
if (nonViralName == null){ |
|
546 |
return null; |
|
547 |
} |
|
548 |
|
|
549 |
//protected full title cache |
|
550 |
if (nonViralName.isProtectedFullTitleCache()){ |
|
551 |
tags.add(new TaggedText(TagEnum.fullName, nonViralName.getFullTitleCache())); |
|
552 |
return tags; |
|
553 |
} |
|
554 |
|
|
555 |
//title cache |
|
556 |
// String titleCache = nonViralName.getTitleCache(); |
|
557 |
List<TaggedText> titleTags = getTaggedTitle(nonViralName); |
|
558 |
tags.addAll(titleTags); |
|
559 |
|
|
560 |
|
|
561 |
//reference |
|
562 |
String microReference = nonViralName.getNomenclaturalMicroReference(); |
|
563 |
INomenclaturalReference ref = nonViralName.getNomenclaturalReference(); |
|
564 |
String referenceBaseCache = null; |
|
565 |
if (ref != null){ |
|
566 |
INomenclaturalReference nomenclaturalReference = HibernateProxyHelper.deproxy(ref, INomenclaturalReference.class); |
|
567 |
nomenclaturalReference.setCacheStrategy(nomenclaturalReference.getType().getCacheStrategy()); |
|
568 |
referenceBaseCache = nomenclaturalReference.getNomenclaturalCitation(microReference); |
|
569 |
} |
|
570 |
//add to tags |
|
571 |
if (StringUtils.isNotBlank(referenceBaseCache)){ |
|
572 |
if (! referenceBaseCache.trim().startsWith("in ")){ |
|
573 |
String refConcat = ", "; |
|
574 |
tags.add(new TaggedText(TagEnum.separator, refConcat)); |
|
575 |
} |
|
576 |
tags.add(new TaggedText(TagEnum.reference, referenceBaseCache)); |
|
577 |
} |
|
578 |
|
|
579 |
//nomenclatural status |
|
580 |
Set<NomenclaturalStatus> ncStati = nonViralName.getStatus(); |
|
581 |
Iterator<NomenclaturalStatus> iterator = ncStati.iterator(); |
|
582 |
List<TaggedText> nomStatusTags = new ArrayList<TaggedText>(); |
|
583 |
while (iterator.hasNext()) { |
|
584 |
NomenclaturalStatus ncStatus = (NomenclaturalStatus)iterator.next(); |
|
585 |
// since the NewInstance method of nomencatural status allows null as parameter |
|
586 |
// we have to check for null values here |
|
587 |
String suffix = "not defined"; |
|
588 |
if(ncStatus.getType() != null){ |
|
589 |
NomenclaturalStatusType statusType = ncStatus.getType(); |
|
590 |
Language lang = Language.LATIN(); |
|
591 |
Representation repr = statusType.getRepresentation(lang); |
|
592 |
if (repr != null){ |
|
593 |
suffix = repr.getAbbreviatedLabel(); |
|
594 |
}else{ |
|
595 |
String message = "No latin representation available for nom. status. " + statusType.getTitleCache(); |
|
596 |
logger.warn(message); |
|
597 |
throw new IllegalStateException(message); |
|
598 |
} |
|
599 |
}else if(ncStatus.getRuleConsidered() != null && ! ncStatus.getRuleConsidered().equals("")){ |
|
600 |
suffix = ncStatus.getRuleConsidered(); |
|
601 |
} |
|
602 |
String statusSeparator = ", "; |
|
603 |
nomStatusTags.add(new TaggedText(TagEnum.separator, statusSeparator)); |
|
604 |
nomStatusTags.add(new TaggedText(TagEnum.nomStatus, suffix)); |
|
605 |
} |
|
606 |
tags.addAll(nomStatusTags); |
|
607 |
return tags; |
|
608 |
|
|
609 |
} |
|
610 |
|
|
611 |
public List<TaggedText> getTaggedTitle(T nonViralName) { |
|
612 |
if (nonViralName == null){ |
|
613 |
return null; |
|
614 |
} |
|
615 |
|
|
616 |
List<TaggedText> tags = new ArrayList<TaggedText>(); |
|
617 |
|
|
618 |
//TODO how to handle protected fullTitleCache here? |
|
619 |
|
|
620 |
if (nonViralName.isProtectedTitleCache()){ |
|
621 |
//protected title cache |
|
622 |
tags.add(new TaggedText(TagEnum.name, nonViralName.getTitleCache())); |
|
623 |
return tags; |
|
624 |
}else if (nonViralName.isHybridFormula()){ |
|
625 |
//hybrid formula |
|
626 |
String hybridSeparator = NonViralNameParserImplRegExBase.hybridSign; |
|
627 |
boolean isFirst = true; |
|
628 |
List<HybridRelationship> rels = nonViralName.getOrderedChildRelationships(); |
|
629 |
for (HybridRelationship rel: rels){ |
|
630 |
if (! isFirst){ |
|
631 |
tags.add(new TaggedText(TagEnum.separator, hybridSeparator)); |
|
632 |
} |
|
633 |
tags.add(new TaggedText(TagEnum.name, hybridSeparator)); |
|
634 |
isFirst = false; |
|
635 |
tags.addAll(getTaggedTitle((T)rel.getParentName())); |
|
636 |
} |
|
637 |
return tags; |
|
638 |
}else if (nonViralName.isAutonym()){ |
|
639 |
//Autonym |
|
640 |
tags.addAll(handleTaggedAutonym(nonViralName)); |
|
641 |
}else{ //not Autonym |
|
642 |
// String nameCache = nonViralName.getNameCache(); //OLD: CdmUtils.Nz(getNameCache(nonViralName)); |
|
643 |
List<TaggedText> nameTags = getNameTags(nonViralName); |
|
644 |
tags.addAll(nameTags); |
|
645 |
if (nameIncludesAuthorship(nonViralName)){ |
|
646 |
String authorCache = getAuthorshipCache(nonViralName); |
|
647 |
if (StringUtils.isNotBlank(authorCache)){ |
|
648 |
tags.add(new TaggedText(TagEnum.authors, authorCache)); |
|
649 |
} |
|
650 |
} |
|
651 |
} |
|
652 |
return tags; |
|
653 |
|
|
654 |
} |
|
655 |
|
|
656 |
|
|
657 |
/** |
|
658 |
* @param nonViralName |
|
659 |
* @return |
|
660 |
*/ |
|
661 |
private List<TaggedText> getNameTags(T nonViralName) { |
|
662 |
if (nonViralName == null){ |
|
663 |
return null; |
|
664 |
} |
|
665 |
List<TaggedText> tags = new ArrayList<TaggedText>(); |
|
666 |
Rank rank = nonViralName.getRank(); |
|
667 |
|
|
668 |
if (nonViralName.isProtectedNameCache()){ |
|
669 |
tags.add(new TaggedText(TagEnum.name, nonViralName.getNameCache())); |
|
670 |
}else if (rank == null){ |
|
671 |
tags = getRanklessTaggedNameCache(nonViralName); |
|
672 |
// }else if (nonViralName.isInfragenericUnranked()){ |
|
673 |
// result = getUnrankedInfragenericNameCache(nonViralName); |
|
674 |
}else if (rank.isInfraSpecific()){ |
|
675 |
tags = getInfraSpeciesTaggedNameCache(nonViralName); |
|
676 |
}else if (rank.isSpecies()){ |
|
677 |
tags = getSpeciesTaggedNameCache(nonViralName); |
|
678 |
}else if (rank.isInfraGeneric()){ |
|
679 |
tags = getInfraGenusTaggedNameCache(nonViralName); |
|
680 |
}else if (rank.isGenus()){ |
|
681 |
tags = getGenusOrUninomialTaggedNameCache(nonViralName); |
|
682 |
}else if (rank.isSupraGeneric()){ |
|
683 |
tags = getGenusOrUninomialTaggedNameCache(nonViralName); |
|
684 |
}else{ |
|
685 |
logger.warn("Name Strategy for Name (UUID: " + nonViralName.getUuid() + ") not yet implemented"); |
|
686 |
} |
|
687 |
//TODO handle appended phrase here instead of different places, check first if this is true for all |
|
688 |
//cases |
|
689 |
|
|
690 |
return tags; |
|
691 |
|
|
692 |
} |
|
693 |
|
|
694 |
|
|
695 |
//Old: may be replaced once getTagged(Full)Title is fully tested |
|
438 | 696 |
/* (non-Javadoc) |
439 | 697 |
* @see eu.etaxonomy.cdm.strategy.INameCacheStrategy#getTaggedName(eu.etaxonomy.cdm.model.common.CdmBase) |
440 | 698 |
*/ |
... | ... | |
503 | 761 |
|
504 | 762 |
//***************************** PRIVATES ***************************************/ |
505 | 763 |
|
506 |
protected String getRanklessNameCache(NonViralName nonViralName){ |
|
507 |
String result = ""; |
|
508 |
result = (result + (CdmUtils.Nz(nonViralName.getGenusOrUninomial()))).trim().replace("null", ""); |
|
509 |
result += " " + (CdmUtils.Nz(nonViralName.getSpecificEpithet())).trim(); |
|
510 |
result += " " + (CdmUtils.Nz(nonViralName.getInfraSpecificEpithet())).trim(); |
|
511 |
result = result.trim().replace("null", ""); |
|
512 |
//result += " (rankless)"; |
|
513 |
result = addAppendedPhrase(result, nonViralName); |
|
514 |
return result; |
|
764 |
protected List<TaggedText> getRanklessTaggedNameCache(NonViralName<?> nonViralName){ |
|
765 |
List<TaggedText> tags = getUninomialTaggedPart(nonViralName); |
|
766 |
String speciesEpi = CdmUtils.Nz(nonViralName.getSpecificEpithet()).trim().replace("null", ""); |
|
767 |
if (StringUtils.isNotBlank(speciesEpi)){ |
|
768 |
tags.add(new TaggedText(TagEnum.name, speciesEpi)); |
|
515 | 769 |
} |
516 |
|
|
517 |
|
|
518 |
protected String getGenusOrUninomialNameCache(NonViralName nonViralName){ |
|
519 |
String result; |
|
520 |
result = getUninomialPart(nonViralName); |
|
521 |
result = addAppendedPhrase(result, nonViralName).trim(); |
|
522 |
return result; |
|
770 |
|
|
771 |
String infraSpeciesEpi = CdmUtils.Nz(nonViralName.getInfraSpecificEpithet()).trim().replace("null", ""); |
|
772 |
if (StringUtils.isNotBlank(infraSpeciesEpi)){ |
|
773 |
tags.add(new TaggedText(TagEnum.name, infraSpeciesEpi)); |
|
523 | 774 |
} |
775 |
|
|
776 |
//result += " (rankless)"; |
|
777 |
addAppendedTaggedPhrase(tags, nonViralName); |
|
778 |
return tags; |
|
779 |
} |
|
780 |
|
|
781 |
protected String getRanklessNameCache(NonViralName<?> nonViralName){ |
|
782 |
String result = ""; |
|
783 |
result = (result + (CdmUtils.Nz(nonViralName.getGenusOrUninomial()))).trim().replace("null", ""); |
|
784 |
result += " " + (CdmUtils.Nz(nonViralName.getSpecificEpithet())).trim(); |
|
785 |
result += " " + (CdmUtils.Nz(nonViralName.getInfraSpecificEpithet())).trim(); |
|
786 |
result = result.trim().replace("null", ""); |
|
787 |
//result += " (rankless)"; |
|
788 |
result = addAppendedPhrase(result, nonViralName); |
|
789 |
return result; |
|
790 |
} |
|
524 | 791 |
|
792 |
|
|
793 |
protected List<TaggedText> getGenusOrUninomialTaggedNameCache(NonViralName<?> nonViralName){ |
|
794 |
List<TaggedText> tags = getUninomialTaggedPart(nonViralName); |
|
795 |
addAppendedTaggedPhrase(tags, nonViralName); |
|
796 |
return tags; |
|
797 |
} |
|
525 | 798 |
|
526 |
private String getUninomialPart(NonViralName nonViralName) { |
|
527 |
String result; |
|
528 |
result = CdmUtils.Nz(nonViralName.getGenusOrUninomial()).trim(); |
|
529 |
if (nonViralName.isMonomHybrid()){ |
|
530 |
result = NonViralNameParserImplRegExBase.hybridSign + result; |
|
531 |
} |
|
532 |
return result; |
|
799 |
protected String getGenusOrUninomialNameCache(NonViralName<?> nonViralName){ |
|
800 |
String result; |
|
801 |
result = getUninomialPart(nonViralName); |
|
802 |
result = addAppendedPhrase(result, nonViralName).trim(); |
|
803 |
return result; |
|
804 |
} |
|
805 |
|
|
806 |
|
|
807 |
private List<TaggedText> getUninomialTaggedPart(NonViralName<?> nonViralName) { |
|
808 |
List<TaggedText> tags = new ArrayList<TaggedText>(); |
|
809 |
|
|
810 |
if (nonViralName.isMonomHybrid()){ |
|
811 |
addHybridPrefix(tags); |
|
533 | 812 |
} |
534 | 813 |
|
535 |
protected String getInfraGenusNameCache(NonViralName nonViralName){ |
|
536 |
String result; |
|
537 |
Rank rank = nonViralName.getRank(); |
|
538 |
if (rank.isSpeciesAggregate()){ |
|
539 |
return getSpeciesAggregateCache(nonViralName); |
|
540 |
} |
|
541 |
String infraGenericMarker = "'unhandled infrageneric rank'"; |
|
542 |
if (rank != null){ |
|
543 |
try { |
|
544 |
infraGenericMarker = rank.getInfraGenericMarker(); |
|
545 |
} catch (UnknownCdmTypeException e) { |
|
546 |
infraGenericMarker = "'unhandled infrageneric rank'"; |
|
547 |
} |
|
548 |
} |
|
549 |
result = getUninomialPart(nonViralName); |
|
550 |
result += " " + infraGenericMarker + " " + (CdmUtils.Nz(nonViralName.getInfraGenericEpithet())).trim().replace("null", ""); |
|
551 |
result = addAppendedPhrase(result, nonViralName).trim(); |
|
552 |
return result; |
|
814 |
String uninomial = CdmUtils.Nz(nonViralName.getGenusOrUninomial()).trim().replace("null", ""); |
|
815 |
if (StringUtils.isNotBlank(uninomial)){ |
|
816 |
tags.add(new TaggedText(TagEnum.name, uninomial)); |
|
553 | 817 |
} |
554 |
|
|
555 |
// aggr.|agg.|group |
|
556 |
protected String getSpeciesAggregateCache(NonViralName nonViralName){ |
|
557 |
String result = getGenusAndSpeciesPart(nonViralName); |
|
558 | 818 |
|
559 |
result += " " + getSpeciesAggregateEpithet(nonViralName); |
|
560 |
result = addAppendedPhrase(result, nonViralName).trim(); |
|
561 |
return result; |
|
819 |
return tags; |
|
820 |
} |
|
821 |
|
|
822 |
private String getUninomialPart(NonViralName<?> nonViralName) { |
|
823 |
String result; |
|
824 |
result = CdmUtils.Nz(nonViralName.getGenusOrUninomial()).trim(); |
|
825 |
if (nonViralName.isMonomHybrid()){ |
|
826 |
result = NonViralNameParserImplRegExBase.hybridSign + result; |
|
562 | 827 |
} |
828 |
return result; |
|
829 |
} |
|
830 |
|
|
831 |
|
|
832 |
protected List<TaggedText> getInfraGenusTaggedNameCache(NonViralName<?> nonViralName){ |
|
833 |
Rank rank = nonViralName.getRank(); |
|
834 |
if (rank.isSpeciesAggregate()){ |
|
835 |
return getSpeciesAggregateTaggedCache(nonViralName); |
|
836 |
} |
|
837 |
|
|
838 |
//genus |
|
839 |
List<TaggedText> tags = getUninomialTaggedPart(nonViralName); |
|
563 | 840 |
|
564 |
private String getSpeciesAggregateEpithet(NonViralName nonViralName) { |
|
565 |
String marker; |
|
841 |
//marker |
|
842 |
String infraGenericMarker = "'unhandled infrageneric rank'"; |
|
843 |
if (rank != null){ |
|
566 | 844 |
try { |
567 |
marker = nonViralName.getRank().getInfraGenericMarker();
|
|
845 |
infraGenericMarker = rank.getInfraGenericMarker();
|
|
568 | 846 |
} catch (UnknownCdmTypeException e) { |
569 |
marker = "'unknown aggregat type'";
|
|
847 |
infraGenericMarker = "'unhandled infrageneric rank'";
|
|
570 | 848 |
} |
571 |
return marker; |
|
572 | 849 |
} |
850 |
tags.add(new TaggedText(TagEnum.rank, infraGenericMarker)); |
|
573 | 851 |
|
574 |
protected String getSpeciesNameCache(NonViralName nonViralName){ |
|
575 |
String result = getGenusAndSpeciesPart(nonViralName); |
|
576 |
result = addAppendedPhrase(result, nonViralName).trim(); |
|
577 |
result = result.replace("\\s\\", " "); |
|
578 |
return result; |
|
852 |
|
|
853 |
String infraGenEpi = CdmUtils.Nz(nonViralName.getInfraGenericEpithet()).trim().replace("null", ""); |
|
854 |
if (StringUtils.isNotBlank(infraGenEpi)){ |
|
855 |
tags.add(new TaggedText(TagEnum.name, infraGenEpi)); |
|
579 | 856 |
} |
580 | 857 |
|
858 |
addAppendedTaggedPhrase(tags, nonViralName); |
|
859 |
return tags; |
|
860 |
} |
|
861 |
|
|
862 |
protected String getInfraGenusNameCache(NonViralName<?> nonViralName){ |
|
863 |
String result; |
|
864 |
Rank rank = nonViralName.getRank(); |
|
865 |
if (rank.isSpeciesAggregate()){ |
|
866 |
return getSpeciesAggregateCache(nonViralName); |
|
867 |
} |
|
868 |
String infraGenericMarker = "'unhandled infrageneric rank'"; |
|
869 |
if (rank != null){ |
|
870 |
try { |
|
871 |
infraGenericMarker = rank.getInfraGenericMarker(); |
|
872 |
} catch (UnknownCdmTypeException e) { |
|
873 |
infraGenericMarker = "'unhandled infrageneric rank'"; |
|
874 |
} |
|
875 |
} |
|
876 |
result = getUninomialPart(nonViralName); |
|
877 |
result += " " + infraGenericMarker + " " + (CdmUtils.Nz(nonViralName.getInfraGenericEpithet())).trim().replace("null", ""); |
|
878 |
result = addAppendedPhrase(result, nonViralName).trim(); |
|
879 |
return result; |
|
880 |
} |
|
881 |
|
|
882 |
// aggr.|agg.|group |
|
883 |
protected List<TaggedText> getSpeciesAggregateTaggedCache(NonViralName<?> nonViralName){ |
|
884 |
List<TaggedText> tags = getGenusAndSpeciesTaggedPart(nonViralName); |
|
581 | 885 |
|
582 |
protected String getInfraSpeciesNameCache(NonViralName nonViralName){ |
|
583 |
return getInfraSpeciesNameCache(nonViralName, true); |
|
886 |
addSpeciesAggregateTaggedEpithet(tags, nonViralName); |
|
887 |
addAppendedTaggedPhrase(tags, nonViralName); |
|
888 |
return tags; |
|
889 |
} |
|
890 |
|
|
891 |
private void addSpeciesAggregateTaggedEpithet(List<TaggedText> tags, NonViralName<?> nonViralName) { |
|
892 |
String marker; |
|
893 |
try { |
|
894 |
marker = nonViralName.getRank().getInfraGenericMarker(); |
|
895 |
} catch (UnknownCdmTypeException e) { |
|
896 |
marker = "'unknown aggregat type'"; |
|
897 |
} |
|
898 |
if (StringUtils.isNotBlank(marker)){ |
|
899 |
tags.add(new TaggedText(TagEnum.rank, marker)); |
|
584 | 900 |
} |
901 |
} |
|
902 |
|
|
903 |
// aggr.|agg.|group |
|
904 |
protected String getSpeciesAggregateCache(NonViralName<?> nonViralName){ |
|
905 |
String result = getGenusAndSpeciesPart(nonViralName); |
|
585 | 906 |
|
586 |
protected String getInfraSpeciesNameCache(NonViralName nonViralName, boolean includeMarker){ |
|
587 |
String result = getGenusAndSpeciesPart(nonViralName); |
|
588 |
if (includeMarker){ |
|
589 |
result += " " + (nonViralName.getRank().getAbbreviation()).trim().replace("null", ""); |
|
590 |
} |
|
591 |
String infrSpecEpi = CdmUtils.Nz(nonViralName.getInfraSpecificEpithet()); |
|
592 |
if (nonViralName.isTrinomHybrid()){ |
|
593 |
infrSpecEpi = NonViralNameParserImplRegExBase.hybridSign + infrSpecEpi; |
|
594 |
} |
|
595 |
result += " " + (infrSpecEpi).trim().replace("null", ""); |
|
596 |
result = addAppendedPhrase(result, nonViralName).trim(); |
|
597 |
return result; |
|
907 |
result += " " + getSpeciesAggregateEpithet(nonViralName); |
|
908 |
result = addAppendedPhrase(result, nonViralName).trim(); |
|
909 |
return result; |
|
910 |
} |
|
911 |
|
|
912 |
private String getSpeciesAggregateEpithet(NonViralName<?> nonViralName) { |
|
913 |
String marker; |
|
914 |
try { |
|
915 |
marker = nonViralName.getRank().getInfraGenericMarker(); |
|
916 |
} catch (UnknownCdmTypeException e) { |
|
917 |
marker = "'unknown aggregat type'"; |
|
598 | 918 |
} |
919 |
return marker; |
|
920 |
} |
|
599 | 921 |
|
922 |
|
|
923 |
protected List<TaggedText> getSpeciesTaggedNameCache(NonViralName<?> nonViralName){ |
|
924 |
List<TaggedText> tags = getGenusAndSpeciesTaggedPart(nonViralName); |
|
925 |
addAppendedTaggedPhrase(tags, nonViralName); |
|
926 |
return tags; |
|
927 |
} |
|
928 |
|
|
929 |
protected String getSpeciesNameCache(NonViralName<?> nonViralName){ |
|
930 |
String result = getGenusAndSpeciesPart(nonViralName); |
|
931 |
result = addAppendedPhrase(result, nonViralName).trim(); |
|
932 |
result = result.replace("\\s\\", " "); |
|
933 |
return result; |
|
934 |
} |
|
600 | 935 |
|
601 |
private String getGenusAndSpeciesPart(NonViralName nonViralName) { |
|
602 |
String result; |
|
603 |
//Uninomial |
|
604 |
result = getUninomialPart(nonViralName); |
|
605 |
|
|
606 |
//InfraGenericEpi |
|
607 |
boolean hasInfraGenericEpi = StringUtils.isNotBlank(nonViralName.getInfraGenericEpithet()); |
|
608 |
if (hasInfraGenericEpi){ |
|
609 |
String infrGenEpi = nonViralName.getInfraGenericEpithet().trim(); |
|
610 |
if (nonViralName.isBinomHybrid()){ |
|
611 |
infrGenEpi = NonViralNameParserImplRegExBase.hybridSign + infrGenEpi; |
|
612 |
} |
|
613 |
result += " (" + infrGenEpi + ")"; |
|
936 |
protected List<TaggedText> getInfraSpeciesTaggedNameCache(NonViralName<?> nonViralName){ |
|
937 |
return getInfraSpeciesTaggedNameCache(nonViralName, true); |
|
938 |
} |
|
939 |
|
|
940 |
protected List<TaggedText> getInfraSpeciesTaggedNameCache(NonViralName<?> nonViralName, boolean includeMarker){ |
|
941 |
List<TaggedText> tags = getGenusAndSpeciesTaggedPart(nonViralName); |
|
942 |
if (includeMarker){ |
|
943 |
String marker = (nonViralName.getRank().getAbbreviation()).trim().replace("null", ""); |
|
944 |
if (StringUtils.isNotBlank(marker)){ |
|
945 |
tags.add(new TaggedText(TagEnum.rank, marker)); |
|
614 | 946 |
} |
615 |
//Species Epi |
|
616 |
String specEpi = CdmUtils.Nz(nonViralName.getSpecificEpithet()).trim(); |
|
617 |
if (! hasInfraGenericEpi && nonViralName.isBinomHybrid() || |
|
618 |
hasInfraGenericEpi && nonViralName.isTrinomHybrid()){ |
|
619 |
specEpi = NonViralNameParserImplRegExBase.hybridSign + specEpi; |
|
947 |
} |
|
948 |
String infrSpecEpi = CdmUtils.Nz(nonViralName.getInfraSpecificEpithet()); |
|
949 |
if (nonViralName.isTrinomHybrid()){ |
|
950 |
addHybridPrefix(tags); |
|
951 |
} |
|
952 |
|
|
953 |
infrSpecEpi = infrSpecEpi.trim().replace("null", ""); |
|
954 |
if (StringUtils.isNotBlank(infrSpecEpi)){ |
|
955 |
tags.add(new TaggedText(TagEnum.name, infrSpecEpi)); |
|
956 |
} |
|
957 |
|
|
958 |
addAppendedTaggedPhrase(tags, nonViralName); |
|
959 |
return tags; |
|
960 |
} |
|
961 |
|
|
962 |
|
|
963 |
/** |
|
964 |
* Adds a tag for the hybrid sign and an empty separator to avoid trailing whitespaces. |
|
965 |
* @param tags |
|
966 |
*/ |
|
967 |
private void addHybridPrefix(List<TaggedText> tags) { |
|
968 |
tags.add(new TaggedText(TagEnum.hybridSign, NonViralNameParserImplRegExBase.hybridSign)); |
|
969 |
tags.add(new TaggedText(TagEnum.separator, "")); //no whitespace separator |
|
970 |
} |
|
971 |
|
|
972 |
protected String getInfraSpeciesNameCache(NonViralName<?> nonViralName){ |
|
973 |
return getInfraSpeciesNameCache(nonViralName, true); |
|
974 |
} |
|
975 |
|
|
976 |
|
|
977 |
protected String getInfraSpeciesNameCache(NonViralName<?> nonViralName, boolean includeMarker){ |
|
978 |
String result = getGenusAndSpeciesPart(nonViralName); |
|
979 |
if (includeMarker){ |
|
980 |
result += " " + (nonViralName.getRank().getAbbreviation()).trim().replace("null", ""); |
|
981 |
} |
|
982 |
String infrSpecEpi = CdmUtils.Nz(nonViralName.getInfraSpecificEpithet()); |
|
983 |
if (nonViralName.isTrinomHybrid()){ |
|
984 |
infrSpecEpi = NonViralNameParserImplRegExBase.hybridSign + infrSpecEpi; |
|
985 |
} |
|
986 |
result += " " + (infrSpecEpi).trim().replace("null", ""); |
|
987 |
result = addAppendedPhrase(result, nonViralName).trim(); |
|
988 |
return result; |
|
989 |
} |
|
990 |
|
|
991 |
|
|
992 |
private List<TaggedText> getGenusAndSpeciesTaggedPart(NonViralName<?> nonViralName) { |
|
993 |
//Uninomial |
|
994 |
List<TaggedText> tags = getUninomialTaggedPart(nonViralName); |
|
995 |
|
|
996 |
//InfraGenericEpi |
|
997 |
boolean hasInfraGenericEpi = StringUtils.isNotBlank(nonViralName.getInfraGenericEpithet()); |
|
998 |
if (hasInfraGenericEpi){ |
|
999 |
String infrGenEpi = nonViralName.getInfraGenericEpithet().trim(); |
|
1000 |
if (nonViralName.isBinomHybrid()){ |
|
1001 |
// addHybridPrefix(tags); FIXME hybridSign should be tag, but then we need to handle "(" ")" differently. |
|
1002 |
infrGenEpi = NonViralNameParserImplRegExBase.hybridSign + infrGenEpi; |
|
620 | 1003 |
} |
621 |
result += " " + (specEpi).replace("null", "");
|
|
622 |
return result;
|
|
1004 |
infrGenEpi = "(" + infrGenEpi + ")";
|
|
1005 |
tags.add(new TaggedText(TagEnum.name, infrGenEpi));
|
|
623 | 1006 |
} |
624 | 1007 |
|
1008 |
//Species Epi |
|
1009 |
String specEpi = CdmUtils.Nz(nonViralName.getSpecificEpithet()).trim().replace("null", ""); |
|
1010 |
if (! hasInfraGenericEpi && nonViralName.isBinomHybrid() || |
|
1011 |
hasInfraGenericEpi && nonViralName.isTrinomHybrid()){ |
|
1012 |
addHybridPrefix(tags); |
|
1013 |
} |
|
1014 |
if (StringUtils.isNotBlank(specEpi)){ |
|
1015 |
tags.add(new TaggedText(TagEnum.name, specEpi)); |
|
1016 |
} |
|
1017 |
return tags; |
|
1018 |
} |
|
1019 |
|
|
1020 |
private String getGenusAndSpeciesPart(NonViralName<?> nonViralName) { |
|
1021 |
String result; |
|
1022 |
//Uninomial |
|
1023 |
result = getUninomialPart(nonViralName); |
|
625 | 1024 |
|
626 |
protected String addAppendedPhrase(String resultString, NonViralName nonViralName){ |
|
627 |
String appendedPhrase = nonViralName ==null ? null : nonViralName.getAppendedPhrase(); |
|
628 |
if (resultString == null){ |
|
629 |
return appendedPhrase; |
|
630 |
}else if(appendedPhrase == null || "".equals(appendedPhrase.trim())) { |
|
631 |
return resultString; |
|
632 |
}else if ("".equals(resultString)){ |
|
633 |
return resultString + appendedPhrase; |
|
634 |
}else { |
|
635 |
return resultString + " " + appendedPhrase; |
|
1025 |
//InfraGenericEpi |
|
1026 |
boolean hasInfraGenericEpi = StringUtils.isNotBlank(nonViralName.getInfraGenericEpithet()); |
|
1027 |
if (hasInfraGenericEpi){ |
|
1028 |
String infrGenEpi = nonViralName.getInfraGenericEpithet().trim(); |
|
1029 |
if (nonViralName.isBinomHybrid()){ |
|
1030 |
infrGenEpi = NonViralNameParserImplRegExBase.hybridSign + infrGenEpi; |
|
636 | 1031 |
} |
1032 |
result += " (" + infrGenEpi + ")"; |
|
1033 |
} |
|
1034 |
//Species Epi |
|
1035 |
String specEpi = CdmUtils.Nz(nonViralName.getSpecificEpithet()).trim(); |
|
1036 |
if (! hasInfraGenericEpi && nonViralName.isBinomHybrid() || |
|
1037 |
hasInfraGenericEpi && nonViralName.isTrinomHybrid()){ |
|
1038 |
specEpi = NonViralNameParserImplRegExBase.hybridSign + specEpi; |
|
1039 |
} |
|
1040 |
result += " " + (specEpi).replace("null", ""); |
|
1041 |
return result; |
|
1042 |
} |
|
1043 |
|
|
1044 |
|
|
1045 |
/** |
|
1046 |
* Adds the tag for the appended phrase if an appended phrase exists |
|
1047 |
* @param tags |
|
1048 |
* @param nonViralName |
|
1049 |
*/ |
|
1050 |
protected void addAppendedTaggedPhrase(List<TaggedText> tags, NonViralName<?> nonViralName){ |
|
1051 |
String appendedPhrase = nonViralName ==null ? null : nonViralName.getAppendedPhrase(); |
|
1052 |
if (StringUtils.isNotEmpty(appendedPhrase)){ |
|
1053 |
tags.add(new TaggedText(TagEnum.name, appendedPhrase)); |
|
1054 |
} |
|
1055 |
} |
|
1056 |
|
|
1057 |
protected String addAppendedPhrase(String resultString, NonViralName<?> nonViralName){ |
|
1058 |
String appendedPhrase = nonViralName ==null ? null : nonViralName.getAppendedPhrase(); |
|
1059 |
if (resultString == null){ |
|
1060 |
return appendedPhrase; |
|
1061 |
}else if(appendedPhrase == null || "".equals(appendedPhrase.trim())) { |
|
1062 |
return resultString; |
|
1063 |
}else if ("".equals(resultString)){ |
|
1064 |
return resultString + appendedPhrase; |
|
1065 |
}else { |
|
1066 |
return resultString + " " + appendedPhrase; |
|
637 | 1067 |
} |
1068 |
} |
|
638 | 1069 |
|
639 | 1070 |
|
640 |
public String getLastEpithet(T taxonNameBase) { |
|
641 |
Rank rank = taxonNameBase.getRank(); |
|
642 |
if(rank.isGenus() || rank.isSupraGeneric()) { |
|
643 |
return taxonNameBase.getGenusOrUninomial(); |
|
644 |
} else if(rank.isInfraGeneric()) { |
|
645 |
return taxonNameBase.getInfraGenericEpithet(); |
|
646 |
} else if(rank.isSpecies()) { |
|
647 |
return taxonNameBase.getSpecificEpithet(); |
|
648 |
} else { |
|
649 |
return taxonNameBase.getInfraSpecificEpithet(); |
|
650 |
} |
|
1071 |
public String getLastEpithet(T taxonNameBase) { |
|
1072 |
Rank rank = taxonNameBase.getRank(); |
|
1073 |
if(rank.isGenus() || rank.isSupraGeneric()) { |
|
1074 |
return taxonNameBase.getGenusOrUninomial(); |
|
1075 |
} else if(rank.isInfraGeneric()) { |
|
1076 |
return taxonNameBase.getInfraGenericEpithet(); |
|
1077 |
} else if(rank.isSpecies()) { |
|
1078 |
return taxonNameBase.getSpecificEpithet(); |
|
1079 |
} else { |
|
1080 |
return taxonNameBase.getInfraSpecificEpithet(); |
|
651 | 1081 |
} |
1082 |
} |
|
652 | 1083 |
} |
Also available in: Unified diff
Refactoring nameCacheStrategy. Use same method for both caches (tagged + string)