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.
10 package eu
.etaxonomy
.cdm
.model
.name
;
12 import java
.util
.ArrayList
;
13 import java
.util
.HashSet
;
14 import java
.util
.List
;
17 import javax
.persistence
.Entity
;
18 import javax
.persistence
.FetchType
;
19 import javax
.persistence
.OneToMany
;
20 import javax
.persistence
.Transient
;
22 import org
.apache
.log4j
.Logger
;
23 import org
.hibernate
.annotations
.Cascade
;
24 import org
.hibernate
.annotations
.CascadeType
;
26 import eu
.etaxonomy
.cdm
.model
.common
.AnnotatableEntity
;
27 import eu
.etaxonomy
.cdm
.model
.occurrence
.Specimen
;
28 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
29 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
30 import eu
.etaxonomy
.cdm
.strategy
.cache
.INameCacheStrategy
;
34 * A homotypical group represents all taxon names that share the same type
35 * specimens. This also includes suprageneric names like genera or families
36 * which usually have a name type designation that finally (a name type
37 * designation can also point to another suprageneric name) points to a species
38 * name, which in turn has a (set of) physical type specimen(s). This class
39 * allows to define the type designation only once for the homotypical group
40 * instead of defining a type designation for each one of the taxon names
41 * subsumed under one homotypical group.
47 public class HomotypicalGroup
extends AnnotatableEntity
{
48 static Logger logger
= Logger
.getLogger(HomotypicalGroup
.class);
50 protected Set
<TaxonNameBase
> typifiedNames
= new HashSet();
51 protected Set
<SpecimenTypeDesignation
> typeDesignations
= new HashSet();
53 public static HomotypicalGroup
NewInstance(){
54 return new HomotypicalGroup();
58 public HomotypicalGroup() {
63 @OneToMany(mappedBy
="homotypicalGroup", fetch
=FetchType
.EAGER
)
64 public Set
<TaxonNameBase
> getTypifiedNames() {
67 protected void setTypifiedNames(Set
<TaxonNameBase
> typifiedNames
) {
68 this.typifiedNames
= typifiedNames
;
70 public void addTypifiedName(TaxonNameBase typifiedName
) {
71 if (typifiedName
!= null){
72 typifiedName
.setHomotypicalGroup(this);
73 typifiedNames
.add(typifiedName
);
76 public void removeTypifiedName(TaxonNameBase typifiedName
) {
77 typifiedName
.setHomotypicalGroup(null);
78 typifiedNames
.remove(typifiedName
);
83 @Cascade({CascadeType
.SAVE_UPDATE
})
84 public Set
<SpecimenTypeDesignation
> getTypeDesignations() {
85 return typeDesignations
;
87 protected void setTypeDesignations(Set
<SpecimenTypeDesignation
> typeDesignations
) {
88 this.typeDesignations
= typeDesignations
;
90 public void addTypeDesignation(SpecimenTypeDesignation typeDesignation
, boolean addToAllNames
) {
91 if (typeDesignation
!= null){
92 typeDesignation
.setHomotypicalGroup(this);
93 typeDesignations
.add(typeDesignation
);
96 for (TaxonNameBase taxonNameBase
: this.typifiedNames
){
97 taxonNameBase
.addSpecimenTypeDesignation(typeDesignation
);
101 public void removeTypeDesignation(SpecimenTypeDesignation typeDesignation
) {
102 if (typeDesignation
!= null){
103 typeDesignation
.setHomotypicalGroup(null);
104 typeDesignations
.remove(typeDesignation
);
106 for (TaxonNameBase taxonNameBase
: this.typifiedNames
){
107 taxonNameBase
.removeSpecimenTypeDesignation(typeDesignation
);
113 * Retrieves the synonyms of reference sec that are part of this homotypical group.
114 * If other names are part of this group that are not considered synonyms in the respective sec-reference,
115 * then they will not be included in the resultset.
120 public List
<Synonym
> getSynonymsInGroup(ReferenceBase sec
){
121 List
<Synonym
> result
= new ArrayList();
122 for (TaxonNameBase
<TaxonNameBase
, INameCacheStrategy
> n
:this.getTypifiedNames()){
123 for (Synonym s
:n
.getSynonyms()){
124 if ( (s
.getSec() == null && sec
== null) ||
125 s
.getSec().equals(sec
)){
130 // TODO: sort result list according to date first published, see nomenclatural reference