(no commit message)
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / name / HomotypicalGroup.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9
10 package eu.etaxonomy.cdm.model.name;
11
12 import java.util.ArrayList;
13 import java.util.HashSet;
14 import java.util.List;
15 import java.util.Set;
16
17 import javax.persistence.Entity;
18 import javax.persistence.OneToMany;
19 import javax.persistence.Transient;
20
21 import org.apache.log4j.Logger;
22 import org.hibernate.annotations.Cascade;
23 import org.hibernate.annotations.CascadeType;
24
25 import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
26 import eu.etaxonomy.cdm.model.occurrence.Specimen;
27 import eu.etaxonomy.cdm.model.reference.ReferenceBase;
28 import eu.etaxonomy.cdm.model.taxon.Synonym;
29 import eu.etaxonomy.cdm.model.taxon.SynonymRelationship;
30 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
31
32 /**
33 * A homotypical group represents all names that share the same type specimens.
34 * This also includes supergeneric names like genera or families which usually have a name type designation
35 * that finally (a name type designation can also point to another supergeneric name) points to a species name,
36 * which in turn has a (set of) physical type specimen(s).
37 * @author markus
38 *
39 */
40 @Entity
41 public class HomotypicalGroup extends AnnotatableEntity {
42 static Logger logger = Logger.getLogger(HomotypicalGroup.class);
43
44 protected Set<TaxonNameBase> typifiedNames = new HashSet();
45 protected Set<SpecimenTypeDesignation> typeDesignations = new HashSet();
46
47 public HomotypicalGroup() {
48 super();
49 }
50
51
52 @OneToMany
53 public Set<TaxonNameBase> getTypifiedNames() {
54 return typifiedNames;
55 }
56 protected void setTypifiedNames(Set<TaxonNameBase> typifiedNames) {
57 this.typifiedNames = typifiedNames;
58 }
59 public void addTypifiedName(TaxonNameBase typifiedName) {
60 typifiedName.setHomotypicalGroup(this);
61 }
62 public void removeTypifiedName(TaxonNameBase typifiedName) {
63 typifiedName.setHomotypicalGroup(null);
64 }
65
66
67 @OneToMany
68 @Cascade({CascadeType.SAVE_UPDATE})
69 public Set<SpecimenTypeDesignation> getTypeDesignations() {
70 return typeDesignations;
71 }
72 protected void setTypeDesignations(Set<SpecimenTypeDesignation> typeDesignations) {
73 this.typeDesignations = typeDesignations;
74 }
75 public void addTypeDesignation(SpecimenTypeDesignation typeDesignation) {
76 typeDesignation.setHomotypicalGroup(this);
77 }
78 public void removeTypeDesignation(SpecimenTypeDesignation typeDesignation) {
79 typeDesignation.setHomotypicalGroup(null);
80 }
81 public void addTypeDesignation(Specimen typeSpecimen, TypeDesignationStatus status, ReferenceBase citation, String citationMicroReference, String originalNameString) {
82 SpecimenTypeDesignation td = new SpecimenTypeDesignation(this, typeSpecimen, status, citation, citationMicroReference, originalNameString);
83 td.setHomotypicalGroup(this);
84 }
85
86 /**
87 * Retrieves the synonyms of reference sec that are part of this homotypical group.
88 * If other names are part of this group that are not considered synonyms in the respective sec-reference,
89 * then they will not be included in the resultset.
90 * @param sec
91 * @return
92 */
93 @Transient
94 public List<Synonym> getSynonymsInGroup(ReferenceBase sec){
95 List<Synonym> result = new ArrayList();
96 for (TaxonNameBase n:this.getTypifiedNames()){
97 for (Synonym s:n.getSynonyms()){
98 if (s.getSec().equals(sec)){
99 result.add(s);
100 }
101 }
102 }
103 // TODO: sort result list according to date first published, see nomenclatural reference
104 return result;
105 }
106 }