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.lang.reflect.Method;
|
13
|
import java.util.HashSet;
|
14
|
import java.util.List;
|
15
|
import java.util.Map;
|
16
|
import java.util.Set;
|
17
|
|
18
|
import javax.persistence.Column;
|
19
|
import javax.persistence.Entity;
|
20
|
import javax.persistence.FetchType;
|
21
|
import javax.persistence.Inheritance;
|
22
|
import javax.persistence.InheritanceType;
|
23
|
import javax.persistence.ManyToMany;
|
24
|
import javax.persistence.ManyToOne;
|
25
|
import javax.persistence.OneToMany;
|
26
|
import javax.persistence.Transient;
|
27
|
import javax.validation.Valid;
|
28
|
import javax.validation.constraints.NotNull;
|
29
|
import javax.validation.constraints.Size;
|
30
|
import javax.xml.bind.annotation.XmlAccessType;
|
31
|
import javax.xml.bind.annotation.XmlAccessorType;
|
32
|
import javax.xml.bind.annotation.XmlAttribute;
|
33
|
import javax.xml.bind.annotation.XmlElement;
|
34
|
import javax.xml.bind.annotation.XmlElementWrapper;
|
35
|
import javax.xml.bind.annotation.XmlIDREF;
|
36
|
import javax.xml.bind.annotation.XmlRootElement;
|
37
|
import javax.xml.bind.annotation.XmlSchemaType;
|
38
|
import javax.xml.bind.annotation.XmlType;
|
39
|
|
40
|
import org.apache.log4j.Logger;
|
41
|
import org.hibernate.annotations.Cascade;
|
42
|
import org.hibernate.annotations.CascadeType;
|
43
|
import org.hibernate.annotations.Index;
|
44
|
import org.hibernate.annotations.Table;
|
45
|
import org.hibernate.envers.Audited;
|
46
|
import org.hibernate.search.annotations.Field;
|
47
|
import org.hibernate.search.annotations.IndexedEmbedded;
|
48
|
import org.hibernate.validator.constraints.NotEmpty;
|
49
|
import org.springframework.util.ReflectionUtils;
|
50
|
|
51
|
import eu.etaxonomy.cdm.model.common.IParsable;
|
52
|
import eu.etaxonomy.cdm.model.common.IReferencedEntity;
|
53
|
import eu.etaxonomy.cdm.model.common.IRelated;
|
54
|
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
|
55
|
import eu.etaxonomy.cdm.model.common.RelationshipBase;
|
56
|
import eu.etaxonomy.cdm.model.description.TaxonNameDescription;
|
57
|
import eu.etaxonomy.cdm.model.occurrence.Specimen;
|
58
|
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
|
59
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
60
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
61
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
62
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
63
|
import eu.etaxonomy.cdm.strategy.cache.name.CacheUpdate;
|
64
|
import eu.etaxonomy.cdm.strategy.cache.name.INameCacheStrategy;
|
65
|
import eu.etaxonomy.cdm.strategy.match.IMatchable;
|
66
|
import eu.etaxonomy.cdm.strategy.match.Match;
|
67
|
import eu.etaxonomy.cdm.strategy.match.Match.ReplaceMode;
|
68
|
import eu.etaxonomy.cdm.strategy.match.MatchMode;
|
69
|
import eu.etaxonomy.cdm.strategy.merge.Merge;
|
70
|
import eu.etaxonomy.cdm.strategy.merge.MergeMode;
|
71
|
import eu.etaxonomy.cdm.strategy.parser.ParserProblem;
|
72
|
import eu.etaxonomy.cdm.validation.Level2;
|
73
|
import eu.etaxonomy.cdm.validation.annotation.NullOrNotEmpty;
|
74
|
|
75
|
/**
|
76
|
* The upmost (abstract) class for scientific taxon names regardless of any
|
77
|
* particular {@link NomenclaturalCode nomenclature code}. The scientific taxon name does not depend
|
78
|
* on the use made of it in a publication or a treatment
|
79
|
* ({@link eu.etaxonomy.cdm.model.taxon.TaxonBase taxon concept respectively potential taxon})
|
80
|
* as an {@link eu.etaxonomy.cdm.model.taxon.Taxon "accepted" respectively "correct" (taxon) name}
|
81
|
* or as a {@link eu.etaxonomy.cdm.model.taxon.Synonym synonym}.
|
82
|
* <P>
|
83
|
* This class corresponds partially to: <ul>
|
84
|
* <li> TaxonName according to the TDWG ontology
|
85
|
* <li> ScientificName and CanonicalName according to the TCS
|
86
|
* <li> ScientificName according to the ABCD schema
|
87
|
* </ul>
|
88
|
*
|
89
|
* @author m.doering
|
90
|
* @version 1.0
|
91
|
* @created 08-Nov-2007 13:06:57
|
92
|
*/
|
93
|
@XmlAccessorType(XmlAccessType.FIELD)
|
94
|
@XmlType(name = "TaxonNameBase", propOrder = {
|
95
|
"appendedPhrase",
|
96
|
"nomenclaturalMicroReference",
|
97
|
"nomenclaturalReference",
|
98
|
"rank",
|
99
|
"fullTitleCache",
|
100
|
"protectedFullTitleCache",
|
101
|
"homotypicalGroup",
|
102
|
"typeDesignations",
|
103
|
"relationsFromThisName",
|
104
|
"relationsToThisName",
|
105
|
"status",
|
106
|
"descriptions",
|
107
|
"taxonBases"
|
108
|
})
|
109
|
@XmlRootElement(name = "TaxonNameBase")
|
110
|
@Entity
|
111
|
@Audited
|
112
|
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
|
113
|
@Table(appliesTo="TaxonNameBase", indexes = { @Index(name = "taxonNameBaseTitleCacheIndex", columnNames = { "titleCache" }) })
|
114
|
public abstract class TaxonNameBase<T extends TaxonNameBase<?,?>, S extends INameCacheStrategy> extends IdentifiableEntity<S> implements IReferencedEntity, IParsable, IRelated, IMatchable, Cloneable {
|
115
|
private static final long serialVersionUID = -4530368639601532116L;
|
116
|
private static final Logger logger = Logger.getLogger(TaxonNameBase.class);
|
117
|
|
118
|
@XmlElement(name = "FullTitleCache")
|
119
|
@Column(length=330, name="fullTitleCache")
|
120
|
@Match(value=MatchMode.CACHE, cacheReplaceMode=ReplaceMode.ALL)
|
121
|
@CacheUpdate(noUpdate ="titleCache")
|
122
|
@NotEmpty(groups = Level2.class)
|
123
|
@Size(max = 330)
|
124
|
protected String fullTitleCache;
|
125
|
|
126
|
//if true titleCache will not be automatically generated/updated
|
127
|
@XmlElement(name = "ProtectedFullTitleCache")
|
128
|
@CacheUpdate(value ="fullTitleCache", noUpdate ="titleCache")
|
129
|
private boolean protectedFullTitleCache;
|
130
|
|
131
|
@XmlElementWrapper(name = "Descriptions")
|
132
|
@XmlElement(name = "Description")
|
133
|
@OneToMany(mappedBy="taxonName", fetch= FetchType.LAZY)
|
134
|
@Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.DELETE, CascadeType.DELETE_ORPHAN})
|
135
|
@NotNull
|
136
|
private Set<TaxonNameDescription> descriptions = new HashSet<TaxonNameDescription>();
|
137
|
|
138
|
@XmlElement(name = "AppendedPhrase")
|
139
|
@Field(index= org.hibernate.search.annotations.Index.TOKENIZED)
|
140
|
@CacheUpdate(value ="nameCache")
|
141
|
@NullOrNotEmpty
|
142
|
@Size(max = 255)
|
143
|
private String appendedPhrase;
|
144
|
|
145
|
@XmlElement(name = "NomenclaturalMicroReference")
|
146
|
@Field(index= org.hibernate.search.annotations.Index.TOKENIZED)
|
147
|
@CacheUpdate(noUpdate ="titleCache")
|
148
|
@NullOrNotEmpty
|
149
|
@Size(max = 255)
|
150
|
private String nomenclaturalMicroReference;
|
151
|
|
152
|
@XmlAttribute
|
153
|
@CacheUpdate(noUpdate ={"titleCache","fullTitleCache"})
|
154
|
private int parsingProblem = 0;
|
155
|
|
156
|
@XmlAttribute
|
157
|
@CacheUpdate(noUpdate ={"titleCache","fullTitleCache"})
|
158
|
private int problemStarts = -1;
|
159
|
|
160
|
@XmlAttribute
|
161
|
@CacheUpdate(noUpdate ={"titleCache","fullTitleCache"})
|
162
|
private int problemEnds = -1;
|
163
|
|
164
|
@XmlElementWrapper(name = "TypeDesignations")
|
165
|
@XmlElement(name = "TypeDesignation")
|
166
|
@XmlIDREF
|
167
|
@XmlSchemaType(name = "IDREF")
|
168
|
@ManyToMany(fetch = FetchType.LAZY)
|
169
|
// @JoinTable(
|
170
|
// name="TypeDesignationBase_TaxonNameBase",
|
171
|
// joinColumns=@JoinColumn(name="typifiednames_id"),
|
172
|
// inverseJoinColumns=@javax.persistence.JoinColumn(name="TypeDesignationBase_id")
|
173
|
// )
|
174
|
@Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.DELETE, CascadeType.DELETE_ORPHAN})
|
175
|
@NotNull
|
176
|
private Set<TypeDesignationBase<?>> typeDesignations = new HashSet<TypeDesignationBase<?>>();
|
177
|
|
178
|
@XmlElement(name = "HomotypicalGroup")
|
179
|
@XmlIDREF
|
180
|
@XmlSchemaType(name = "IDREF")
|
181
|
@ManyToOne(fetch = FetchType.LAZY)
|
182
|
@Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE})
|
183
|
@Match(MatchMode.IGNORE)
|
184
|
@CacheUpdate(noUpdate ="titleCache")
|
185
|
@NotNull
|
186
|
private HomotypicalGroup homotypicalGroup;
|
187
|
|
188
|
@XmlElementWrapper(name = "RelationsFromThisName")
|
189
|
@XmlElement(name = "RelationFromThisName")
|
190
|
@OneToMany(mappedBy="relatedFrom", fetch= FetchType.LAZY)
|
191
|
@Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.DELETE_ORPHAN})
|
192
|
@Merge(MergeMode.RELATION)
|
193
|
@NotNull
|
194
|
@Valid
|
195
|
private Set<NameRelationship> relationsFromThisName = new HashSet<NameRelationship>();
|
196
|
|
197
|
@XmlElementWrapper(name = "RelationsToThisName")
|
198
|
@XmlElement(name = "RelationToThisName")
|
199
|
@XmlIDREF
|
200
|
@XmlSchemaType(name = "IDREF")
|
201
|
@OneToMany(mappedBy="relatedTo", fetch= FetchType.LAZY)
|
202
|
@Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE , CascadeType.DELETE_ORPHAN })
|
203
|
@Merge(MergeMode.RELATION)
|
204
|
@NotNull
|
205
|
@Valid
|
206
|
private Set<NameRelationship> relationsToThisName = new HashSet<NameRelationship>();
|
207
|
|
208
|
@XmlElementWrapper(name = "NomenclaturalStatuses")
|
209
|
@XmlElement(name = "NomenclaturalStatus")
|
210
|
@OneToMany(fetch= FetchType.LAZY)
|
211
|
@Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE,CascadeType.DELETE,CascadeType.DELETE_ORPHAN})
|
212
|
@NotNull
|
213
|
private Set<NomenclaturalStatus> status = new HashSet<NomenclaturalStatus>();
|
214
|
|
215
|
@XmlElementWrapper(name = "TaxonBases")
|
216
|
@XmlElement(name = "TaxonBase")
|
217
|
@XmlIDREF
|
218
|
@XmlSchemaType(name = "IDREF")
|
219
|
@OneToMany(mappedBy="name", fetch= FetchType.LAZY)
|
220
|
@NotNull
|
221
|
private Set<TaxonBase> taxonBases = new HashSet<TaxonBase>();
|
222
|
|
223
|
@XmlElement(name = "Rank")
|
224
|
@XmlIDREF
|
225
|
@XmlSchemaType(name = "IDREF")
|
226
|
@ManyToOne(fetch = FetchType.EAGER)
|
227
|
@CacheUpdate(value ="nameCache")
|
228
|
@NotNull
|
229
|
private Rank rank;
|
230
|
|
231
|
@XmlElement(name = "NomenclaturalReference")
|
232
|
@XmlIDREF
|
233
|
@XmlSchemaType(name = "IDREF")
|
234
|
@ManyToOne(fetch = FetchType.LAZY)
|
235
|
@Cascade({CascadeType.SAVE_UPDATE})
|
236
|
@CacheUpdate(noUpdate ="titleCache")
|
237
|
@IndexedEmbedded
|
238
|
private Reference nomenclaturalReference;
|
239
|
|
240
|
// ************* CONSTRUCTORS *************/
|
241
|
/**
|
242
|
* Class constructor: creates a new empty taxon name.
|
243
|
*
|
244
|
* @see #TaxonNameBase(Rank)
|
245
|
* @see #TaxonNameBase(HomotypicalGroup)
|
246
|
* @see #TaxonNameBase(Rank, HomotypicalGroup)
|
247
|
*/
|
248
|
public TaxonNameBase() {
|
249
|
super();
|
250
|
}
|
251
|
/**
|
252
|
* Class constructor: creates a new taxon name
|
253
|
* only containing its {@link Rank rank}.
|
254
|
*
|
255
|
* @param rank the rank to be assigned to <i>this</i> taxon name
|
256
|
* @see #TaxonNameBase()
|
257
|
* @see #TaxonNameBase(HomotypicalGroup)
|
258
|
* @see #TaxonNameBase(Rank, HomotypicalGroup)
|
259
|
*/
|
260
|
public TaxonNameBase(Rank rank) {
|
261
|
this(rank, null);
|
262
|
}
|
263
|
/**
|
264
|
* Class constructor: creates a new taxon name
|
265
|
* only containing its {@link HomotypicalGroup homotypical group}.
|
266
|
* The new taxon name will be also added to the set of taxon names
|
267
|
* belonging to this homotypical group.
|
268
|
*
|
269
|
* @param homotypicalGroup the homotypical group to which <i>this</i> taxon name belongs
|
270
|
* @see #TaxonNameBase()
|
271
|
* @see #TaxonNameBase(Rank)
|
272
|
* @see #TaxonNameBase(Rank, HomotypicalGroup)
|
273
|
*/
|
274
|
public TaxonNameBase(HomotypicalGroup homotypicalGroup) {
|
275
|
this(null, homotypicalGroup);
|
276
|
}
|
277
|
/**
|
278
|
* Class constructor: creates a new taxon name
|
279
|
* only containing its {@link Rank rank} and
|
280
|
* its {@link HomotypicalGroup homotypical group}.
|
281
|
* The new taxon name will be also added to the set of taxon names
|
282
|
* belonging to this homotypical group.
|
283
|
*
|
284
|
* @param rank the rank to be assigned to <i>this</i> taxon name
|
285
|
* @param homotypicalGroup the homotypical group to which <i>this</i> taxon name belongs
|
286
|
* @see #TaxonNameBase()
|
287
|
* @see #TaxonNameBase(Rank)
|
288
|
* @see #TaxonNameBase(HomotypicalGroup)
|
289
|
*/
|
290
|
public TaxonNameBase(Rank rank, HomotypicalGroup homotypicalGroup) {
|
291
|
super();
|
292
|
this.setRank(rank);
|
293
|
if (homotypicalGroup == null){
|
294
|
homotypicalGroup = new HomotypicalGroup();
|
295
|
}
|
296
|
homotypicalGroup.addTypifiedName(this);
|
297
|
}
|
298
|
|
299
|
abstract protected Map<String, java.lang.reflect.Field> getAllFields();
|
300
|
|
301
|
//********* METHODS **************************************/
|
302
|
|
303
|
/**
|
304
|
* Returns the boolean value "false" since the components of <i>this</i> taxon name
|
305
|
* cannot follow the rules of a corresponding {@link NomenclaturalCode nomenclatural code}
|
306
|
* which is not defined for this class. The nomenclature code depends on
|
307
|
* the concrete name subclass ({@link BacterialName BacterialName},
|
308
|
* {@link BotanicalName BotanicalName}, {@link CultivarPlantName CultivarPlantName},
|
309
|
* {@link ZoologicalName ZoologicalName} or {@link ViralName ViralName})
|
310
|
* to which a taxon name belongs.
|
311
|
*
|
312
|
* @return false
|
313
|
*/
|
314
|
@Transient
|
315
|
public abstract boolean isCodeCompliant();
|
316
|
|
317
|
public abstract String generateFullTitle();
|
318
|
|
319
|
|
320
|
|
321
|
@Transient
|
322
|
public List<Object> getTaggedName(){
|
323
|
return getCacheStrategy().getTaggedNameDeprecated(this);
|
324
|
}
|
325
|
|
326
|
@Transient
|
327
|
public String getFullTitleCache(){
|
328
|
if (protectedFullTitleCache){
|
329
|
return this.fullTitleCache;
|
330
|
}
|
331
|
if (fullTitleCache == null ){
|
332
|
this.fullTitleCache = getTruncatedCache(generateFullTitle());
|
333
|
}
|
334
|
return fullTitleCache;
|
335
|
}
|
336
|
|
337
|
|
338
|
public void setFullTitleCache(String fullTitleCache){
|
339
|
setFullTitleCache(fullTitleCache, PROTECTED);
|
340
|
}
|
341
|
|
342
|
public void setFullTitleCache(String fullTitleCache, boolean protectCache){
|
343
|
fullTitleCache = getTruncatedCache(fullTitleCache);
|
344
|
this.fullTitleCache = fullTitleCache;
|
345
|
this.setProtectedFullTitleCache(protectCache);
|
346
|
}
|
347
|
|
348
|
|
349
|
public boolean isProtectedFullTitleCache() {
|
350
|
return protectedFullTitleCache;
|
351
|
}
|
352
|
|
353
|
public void setProtectedFullTitleCache(boolean protectedFullTitleCache) {
|
354
|
this.protectedFullTitleCache = protectedFullTitleCache;
|
355
|
}
|
356
|
|
357
|
/**
|
358
|
* Returns the set of all {@link NameRelationship name relationships}
|
359
|
* in which <i>this</i> taxon name is involved. A taxon name can be both source
|
360
|
* in some name relationships or target in some others.
|
361
|
*
|
362
|
* @see #getRelationsToThisName()
|
363
|
* @see #getRelationsFromThisName()
|
364
|
* @see #addNameRelationship(NameRelationship)
|
365
|
* @see #addRelationshipToName(TaxonNameBase, NameRelationshipType, String)
|
366
|
* @see #addRelationshipFromName(TaxonNameBase, NameRelationshipType, String)
|
367
|
*/
|
368
|
@Transient
|
369
|
public Set<NameRelationship> getNameRelations() {
|
370
|
Set<NameRelationship> rels = new HashSet<NameRelationship>();
|
371
|
rels.addAll(getRelationsFromThisName());
|
372
|
rels.addAll(getRelationsToThisName());
|
373
|
return rels;
|
374
|
}
|
375
|
|
376
|
/**
|
377
|
* Creates a new {@link NameRelationship#NameRelationship(TaxonNameBase, TaxonNameBase, NameRelationshipType, String) name relationship} from <i>this</i> taxon name to another taxon name
|
378
|
* and adds it both to the set of {@link #getRelationsFromThisName() relations from <i>this</i> taxon name} and
|
379
|
* to the set of {@link #getRelationsToThisName() relations to the other taxon name}.
|
380
|
*
|
381
|
* @param toName the taxon name of the target for this new name relationship
|
382
|
* @param type the type of this new name relationship
|
383
|
* @param ruleConsidered the string which specifies the rule on which this name relationship is based
|
384
|
* @see #getRelationsToThisName()
|
385
|
* @see #getNameRelations()
|
386
|
* @see #addRelationshipFromName(TaxonNameBase, NameRelationshipType, String)
|
387
|
* @see #addNameRelationship(NameRelationship)
|
388
|
*/
|
389
|
public void addRelationshipToName(TaxonNameBase toName, NameRelationshipType type, String ruleConsidered){
|
390
|
addRelationshipToName(toName, type, null, null, ruleConsidered);
|
391
|
// NameRelationship rel = new NameRelationship(toName, this, type, ruleConsidered);
|
392
|
}
|
393
|
|
394
|
/**
|
395
|
* Creates a new {@link NameRelationship#NameRelationship(TaxonNameBase, TaxonNameBase, NameRelationshipType, String) name relationship} from <i>this</i> taxon name to another taxon name
|
396
|
* and adds it both to the set of {@link #getRelationsFromThisName() relations from <i>this</i> taxon name} and
|
397
|
* to the set of {@link #getRelationsToThisName() relations to the other taxon name}.
|
398
|
*
|
399
|
* @param toName the taxon name of the target for this new name relationship
|
400
|
* @param type the type of this new name relationship
|
401
|
* @param ruleConsidered the string which specifies the rule on which this name relationship is based
|
402
|
* @return
|
403
|
* @see #getRelationsToThisName()
|
404
|
* @see #getNameRelations()
|
405
|
* @see #addRelationshipFromName(TaxonNameBase, NameRelationshipType, String)
|
406
|
* @see #addNameRelationship(NameRelationship)
|
407
|
*/
|
408
|
public NameRelationship addRelationshipToName(TaxonNameBase toName, NameRelationshipType type, Reference citation, String microCitation, String ruleConsidered){
|
409
|
if (toName == null){
|
410
|
throw new NullPointerException("Null is not allowed as name for a name relationship");
|
411
|
}
|
412
|
NameRelationship rel = new NameRelationship(toName, this, type, citation, microCitation, ruleConsidered);
|
413
|
return rel;
|
414
|
}
|
415
|
|
416
|
/**
|
417
|
* Creates a new {@link NameRelationship#NameRelationship(TaxonNameBase, TaxonNameBase, NameRelationshipType, String) name relationship} from another taxon name to <i>this</i> taxon name
|
418
|
* and adds it both to the set of {@link #getRelationsToThisName() relations to <i>this</i> taxon name} and
|
419
|
* to the set of {@link #getRelationsFromThisName() relations from the other taxon name}.
|
420
|
*
|
421
|
* @param fromName the taxon name of the source for this new name relationship
|
422
|
* @param type the type of this new name relationship
|
423
|
* @param ruleConsidered the string which specifies the rule on which this name relationship is based
|
424
|
* @param citation the reference in which this relation was described
|
425
|
* @param microCitation the reference detail for this relation (e.g. page)
|
426
|
* @see #getRelationsFromThisName()
|
427
|
* @see #getNameRelations()
|
428
|
* @see #addRelationshipToName(TaxonNameBase, NameRelationshipType, String)
|
429
|
* @see #addNameRelationship(NameRelationship)
|
430
|
*/
|
431
|
public void addRelationshipFromName(TaxonNameBase fromName, NameRelationshipType type, String ruleConsidered){
|
432
|
fromName.addRelationshipToName(this, type, null, null, ruleConsidered);
|
433
|
// NameRelationship rel = new NameRelationship(this, fromName, type, ruleConsidered);
|
434
|
}
|
435
|
/**
|
436
|
* Creates a new {@link NameRelationship#NameRelationship(TaxonNameBase, TaxonNameBase, NameRelationshipType, String) name relationship} from another taxon name to <i>this</i> taxon name
|
437
|
* and adds it both to the set of {@link #getRelationsToThisName() relations to <i>this</i> taxon name} and
|
438
|
* to the set of {@link #getRelationsFromThisName() relations from the other taxon name}.
|
439
|
*
|
440
|
* @param fromName the taxon name of the source for this new name relationship
|
441
|
* @param type the type of this new name relationship
|
442
|
* @param ruleConsidered the string which specifies the rule on which this name relationship is based
|
443
|
* @param citation the reference in which this relation was described
|
444
|
* @param microCitation the reference detail for this relation (e.g. page)
|
445
|
* @see #getRelationsFromThisName()
|
446
|
* @see #getNameRelations()
|
447
|
* @see #addRelationshipToName(TaxonNameBase, NameRelationshipType, String)
|
448
|
* @see #addNameRelationship(NameRelationship)
|
449
|
*/
|
450
|
public void addRelationshipFromName(TaxonNameBase fromName, NameRelationshipType type, Reference citation, String microCitation, String ruleConsidered){
|
451
|
fromName.addRelationshipToName(this, type, citation, microCitation, ruleConsidered);
|
452
|
}
|
453
|
|
454
|
/**
|
455
|
* Adds an existing {@link NameRelationship name relationship} either to the set of
|
456
|
* {@link #getRelationsToThisName() relations to <i>this</i> taxon name} or to the set of
|
457
|
* {@link #getRelationsFromThisName() relations from <i>this</i> taxon name}. If neither the
|
458
|
* source nor the target of the name relationship match with <i>this</i> taxon name
|
459
|
* no addition will be carried out.
|
460
|
*
|
461
|
* @param rel the name relationship to be added to one of <i>this</i> taxon name's name relationships sets
|
462
|
* @see #getNameRelations()
|
463
|
* @see #addRelationshipToName(TaxonNameBase, NameRelationshipType, String)
|
464
|
* @see #addRelationshipFromName(TaxonNameBase, NameRelationshipType, String)
|
465
|
*/
|
466
|
protected void addNameRelationship(NameRelationship rel) {
|
467
|
if (rel!=null && rel.getToName().equals(this)){
|
468
|
this.relationsToThisName.add(rel);
|
469
|
}else if(rel!=null && rel.getFromName().equals(this)){
|
470
|
this.relationsFromThisName.add(rel);
|
471
|
}else{
|
472
|
throw new RuntimeException("NameRelationship is either null or the relationship does not reference this name");
|
473
|
}
|
474
|
}
|
475
|
/**
|
476
|
* Removes one {@link NameRelationship name relationship} from one of both sets of
|
477
|
* {@link #getNameRelations() name relationships} in which <i>this</i> taxon name is involved.
|
478
|
* The name relationship will also be removed from one of both sets belonging
|
479
|
* to the second taxon name involved. Furthermore the fromName and toName
|
480
|
* attributes of the name relationship object will be nullified.
|
481
|
*
|
482
|
* @param nameRelation the name relationship which should be deleted from one of both sets
|
483
|
* @see #getNameRelations()
|
484
|
*/
|
485
|
public void removeNameRelationship(NameRelationship nameRelation) {
|
486
|
|
487
|
TaxonNameBase fromName = nameRelation.getFromName();
|
488
|
TaxonNameBase toName = nameRelation.getToName();
|
489
|
|
490
|
if (nameRelation != null) {
|
491
|
nameRelation.setToName(null);
|
492
|
nameRelation.setFromName(null);
|
493
|
}
|
494
|
|
495
|
if (fromName != null) {
|
496
|
fromName.removeNameRelationship(nameRelation);
|
497
|
}
|
498
|
|
499
|
if (toName != null) {
|
500
|
toName.removeNameRelationship(nameRelation);
|
501
|
}
|
502
|
|
503
|
this.relationsToThisName.remove(nameRelation);
|
504
|
this.relationsFromThisName.remove(nameRelation);
|
505
|
}
|
506
|
|
507
|
public void removeRelationToTaxonName(TaxonNameBase toTaxonName) {
|
508
|
Set<NameRelationship> nameRelationships = new HashSet<NameRelationship>();
|
509
|
// nameRelationships.addAll(this.getNameRelations());
|
510
|
nameRelationships.addAll(this.getRelationsFromThisName());
|
511
|
nameRelationships.addAll(this.getRelationsToThisName());
|
512
|
for(NameRelationship nameRelationship : nameRelationships) {
|
513
|
// remove name relationship from this side
|
514
|
if (nameRelationship.getFromName().equals(this) && nameRelationship.getToName().equals(toTaxonName)) {
|
515
|
this.removeNameRelationship(nameRelationship);
|
516
|
}
|
517
|
}
|
518
|
}
|
519
|
|
520
|
|
521
|
/**
|
522
|
* Does exactly the same as the addNameRelationship method provided that
|
523
|
* the given relationship is a name relationship.
|
524
|
*
|
525
|
* @param relation the relationship to be added to one of <i>this</i> taxon name's name relationships sets
|
526
|
* @see #addNameRelationship(NameRelationship)
|
527
|
* @see #getNameRelations()
|
528
|
* @see NameRelationship
|
529
|
* @see eu.etaxonomy.cdm.model.common.RelationshipBase
|
530
|
*/
|
531
|
public void addRelationship(RelationshipBase relation) {
|
532
|
if (relation instanceof NameRelationship){
|
533
|
addNameRelationship((NameRelationship)relation);
|
534
|
NameRelationshipType type = (NameRelationshipType)relation.getType();
|
535
|
if (type != null && ( type.isBasionymRelation() || type.isReplacedSynonymRelation() ) ){
|
536
|
TaxonNameBase fromName = ((NameRelationship)relation).getFromName();
|
537
|
TaxonNameBase toName = ((NameRelationship)relation).getToName();
|
538
|
fromName.mergeHomotypicGroups(toName);
|
539
|
}
|
540
|
}else{
|
541
|
logger.warn("Relationship not of type NameRelationship!");
|
542
|
throw new IllegalArgumentException("Relationship not of type NameRelationship");
|
543
|
}
|
544
|
}
|
545
|
|
546
|
|
547
|
/**
|
548
|
* Returns the set of all {@link NameRelationship name relationships}
|
549
|
* in which <i>this</i> taxon name is involved as a source.
|
550
|
*
|
551
|
* @see #getNameRelations()
|
552
|
* @see #getRelationsToThisName()
|
553
|
* @see #addRelationshipFromName(TaxonNameBase, NameRelationshipType, String)
|
554
|
*/
|
555
|
public Set<NameRelationship> getRelationsFromThisName() {
|
556
|
if(relationsFromThisName == null) {
|
557
|
this.relationsFromThisName = new HashSet<NameRelationship>();
|
558
|
}
|
559
|
return relationsFromThisName;
|
560
|
}
|
561
|
|
562
|
/**
|
563
|
* Returns the set of all {@link NameRelationship name relationships}
|
564
|
* in which <i>this</i> taxon name is involved as a target.
|
565
|
*
|
566
|
* @see #getNameRelations()
|
567
|
* @see #getRelationsFromThisName()
|
568
|
* @see #addRelationshipToName(TaxonNameBase, NameRelationshipType, String)
|
569
|
*/
|
570
|
public Set<NameRelationship> getRelationsToThisName() {
|
571
|
if(relationsToThisName == null) {
|
572
|
this.relationsToThisName = new HashSet<NameRelationship>();
|
573
|
}
|
574
|
return relationsToThisName;
|
575
|
}
|
576
|
|
577
|
/**
|
578
|
* Returns the set of {@link NomenclaturalStatus nomenclatural status} assigned
|
579
|
* to <i>this</i> taxon name according to its corresponding nomenclature code.
|
580
|
* This includes the {@link NomenclaturalStatusType type} of the nomenclatural status
|
581
|
* and the nomenclatural code rule considered.
|
582
|
*
|
583
|
* @see NomenclaturalStatus
|
584
|
* @see NomenclaturalStatusType
|
585
|
*/
|
586
|
public Set<NomenclaturalStatus> getStatus() {
|
587
|
if(status == null) {
|
588
|
this.status = new HashSet<NomenclaturalStatus>();
|
589
|
}
|
590
|
return status;
|
591
|
}
|
592
|
|
593
|
/**
|
594
|
* Adds a new {@link NomenclaturalStatus nomenclatural status}
|
595
|
* to <i>this</i> taxon name's set of nomenclatural status.
|
596
|
*
|
597
|
* @param nomStatus the nomenclatural status to be added
|
598
|
* @see #getStatus()
|
599
|
*/
|
600
|
public void addStatus(NomenclaturalStatus nomStatus) {
|
601
|
this.status.add(nomStatus);
|
602
|
}
|
603
|
|
604
|
/**
|
605
|
* Removes one element from the set of nomenclatural status of <i>this</i> taxon name.
|
606
|
* Type and ruleConsidered attributes of the nomenclatural status object
|
607
|
* will be nullified.
|
608
|
*
|
609
|
* @param nomStatus the nomenclatural status of <i>this</i> taxon name which should be deleted
|
610
|
* @see #getStatus()
|
611
|
*/
|
612
|
public void removeStatus(NomenclaturalStatus nomStatus) {
|
613
|
//TODO to be implemented?
|
614
|
logger.warn("not yet fully implemented?");
|
615
|
this.status.remove(nomStatus);
|
616
|
}
|
617
|
|
618
|
|
619
|
/**
|
620
|
* Indicates whether <i>this</i> taxon name is a {@link NameRelationshipType#BASIONYM() basionym}
|
621
|
* or a {@link NameRelationshipType#REPLACED_SYNONYM() replaced synonym}
|
622
|
* of any other taxon name. Returns "true", if a basionym or a replaced
|
623
|
* synonym {@link NameRelationship relationship} from <i>this</i> taxon name to another taxon name exists,
|
624
|
* false otherwise (also in case <i>this</i> taxon name is the only one in the
|
625
|
* homotypical group).
|
626
|
*/
|
627
|
@Transient
|
628
|
public boolean isOriginalCombination(){
|
629
|
Set<NameRelationship> relationsFromThisName = this.getRelationsFromThisName();
|
630
|
for (NameRelationship relation : relationsFromThisName) {
|
631
|
if (relation.getType().isBasionymRelation() ||
|
632
|
relation.getType().isReplacedSynonymRelation()) {
|
633
|
return true;
|
634
|
}
|
635
|
}
|
636
|
return false;
|
637
|
}
|
638
|
|
639
|
/**
|
640
|
* Returns the taxon name which is the {@link NameRelationshipType#BASIONYM() basionym} of <i>this</i> taxon name.
|
641
|
* The basionym of a taxon name is its epithet-bringing synonym.
|
642
|
* For instance <i>Pinus abies</i> L. was published by Linnaeus and the botanist
|
643
|
* Karsten transferred later <i>this</i> taxon to the genus Picea. Therefore,
|
644
|
* <i>Pinus abies</i> L. is the basionym of the new combination <i>Picea abies</i> (L.) H. Karst.
|
645
|
*
|
646
|
* If more than one basionym exists one is choosen at radom.
|
647
|
*
|
648
|
* If no basionym exists null is returned.
|
649
|
*/
|
650
|
@Transient
|
651
|
public TaxonNameBase getBasionym(){
|
652
|
Set<TaxonNameBase> basionyms = getBasionyms();
|
653
|
if (basionyms.size() == 0){
|
654
|
return null;
|
655
|
}else{
|
656
|
return basionyms.iterator().next();
|
657
|
}
|
658
|
}
|
659
|
|
660
|
/**
|
661
|
* Returns the set of taxon names which are the {@link NameRelationshipType#BASIONYM() basionyms} of <i>this</i> taxon name.
|
662
|
* The basionym of a taxon name is its epithet-bringing synonym.
|
663
|
* For instance <i>Pinus abies</i> L. was published by Linnaeus and the botanist
|
664
|
* Karsten transferred later <i>this</i> taxon to the genus Picea. Therefore,
|
665
|
* <i>Pinus abies</i> L. is the basionym of the new combination <i>Picea abies</i> (L.) H. Karst.
|
666
|
*/
|
667
|
@Transient
|
668
|
public Set<TaxonNameBase> getBasionyms(){
|
669
|
Set<TaxonNameBase> result = new HashSet<TaxonNameBase>();
|
670
|
Set<NameRelationship> rels = this.getRelationsToThisName();
|
671
|
for (NameRelationship rel : rels){
|
672
|
if (rel.getType().isBasionymRelation()){
|
673
|
TaxonNameBase basionym = rel.getFromName();
|
674
|
result.add(basionym);
|
675
|
}
|
676
|
}
|
677
|
return result;
|
678
|
}
|
679
|
|
680
|
/**
|
681
|
* Assigns a taxon name as {@link NameRelationshipType#BASIONYM() basionym} of <i>this</i> taxon name.
|
682
|
* The basionym {@link NameRelationship relationship} will be added to <i>this</i> taxon name
|
683
|
* and to the basionym. The basionym cannot have itself a basionym.
|
684
|
* The {@link HomotypicalGroup homotypical groups} of <i>this</i> taxon name and of the basionym
|
685
|
* will be {@link HomotypicalGroup#merge(HomotypicalGroup) merged}.
|
686
|
*
|
687
|
* @param basionym the taxon name to be set as the basionym of <i>this</i> taxon name
|
688
|
* @see #getBasionym()
|
689
|
* @see #addBasionym(TaxonNameBase, String)
|
690
|
*/
|
691
|
public void addBasionym(T basionym){
|
692
|
addBasionym(basionym, null, null, null);
|
693
|
}
|
694
|
/**
|
695
|
* Assigns a taxon name as {@link NameRelationshipType#BASIONYM() basionym} of <i>this</i> taxon name
|
696
|
* and keeps the nomenclatural rule considered for it. The basionym
|
697
|
* {@link NameRelationship relationship} will be added to <i>this</i> taxon name and to the basionym.
|
698
|
* The basionym cannot have itself a basionym.
|
699
|
* The {@link HomotypicalGroup homotypical groups} of <i>this</i> taxon name and of the basionym
|
700
|
* will be {@link HomotypicalGroup#merge(HomotypicalGroup) merged}.
|
701
|
*
|
702
|
* @param basionym the taxon name to be set as the basionym of <i>this</i> taxon name
|
703
|
* @param ruleConsidered the string identifying the nomenclatural rule
|
704
|
* @return
|
705
|
* @see #getBasionym()
|
706
|
* @see #addBasionym(TaxonNameBase)
|
707
|
*/
|
708
|
public NameRelationship addBasionym(T basionym, Reference citation, String microcitation, String ruleConsidered){
|
709
|
if (basionym != null){
|
710
|
return basionym.addRelationshipToName(this, NameRelationshipType.BASIONYM(), citation, microcitation, ruleConsidered);
|
711
|
}else{
|
712
|
return null;
|
713
|
}
|
714
|
}
|
715
|
|
716
|
/**
|
717
|
* Assigns a taxon name as {@link NameRelationshipType#REPLACED_SYNONYM() replaced synonym} of <i>this</i> taxon name
|
718
|
* and keeps the nomenclatural rule considered for it. The replaced synonym
|
719
|
* {@link NameRelationship relationship} will be added to <i>this</i> taxon name and to the replaced synonym.
|
720
|
* The {@link HomotypicalGroup homotypical groups} of <i>this</i> taxon name and of the replaced synonym
|
721
|
* will be {@link HomotypicalGroup#merge(HomotypicalGroup) merged}.
|
722
|
*
|
723
|
* @param basionym the taxon name to be set as the basionym of <i>this</i> taxon name
|
724
|
* @param ruleConsidered the string identifying the nomenclatural rule
|
725
|
* @see #getBasionym()
|
726
|
* @see #addBasionym(TaxonNameBase)
|
727
|
*/
|
728
|
//TODO: Check if true: The replaced synonym cannot have itself a replaced synonym (?).
|
729
|
public void addReplacedSynonym(T replacedSynonym, Reference citation, String microcitation, String ruleConsidered){
|
730
|
if (replacedSynonym != null){
|
731
|
replacedSynonym.addRelationshipToName(this, NameRelationshipType.REPLACED_SYNONYM(), citation, microcitation, ruleConsidered);
|
732
|
}
|
733
|
}
|
734
|
|
735
|
/**
|
736
|
* Removes the {@link NameRelationshipType#BASIONYM() basionym} {@link NameRelationship relationship} from the set of
|
737
|
* {@link #getRelationsToThisName() name relationships to} <i>this</i> taxon name. The same relationhip will be
|
738
|
* removed from the set of {@link #getRelationsFromThisName() name relationships from} the taxon name
|
739
|
* previously used as basionym.
|
740
|
*
|
741
|
* @see #getBasionym()
|
742
|
* @see #addBasionym(TaxonNameBase)
|
743
|
*/
|
744
|
public void removeBasionyms(){
|
745
|
Set<NameRelationship> removeRelations = new HashSet<NameRelationship>();
|
746
|
for (NameRelationship nameRelation : this.getRelationsToThisName()){
|
747
|
if (nameRelation.getType().isBasionymRelation()){
|
748
|
removeRelations.add(nameRelation);
|
749
|
}
|
750
|
}
|
751
|
// Removing relations from a set through which we are iterating causes a
|
752
|
// ConcurrentModificationException. Therefore, we delete the targeted
|
753
|
// relations in a second step.
|
754
|
for (NameRelationship relation : removeRelations){
|
755
|
this.removeNameRelationship(relation);
|
756
|
}
|
757
|
}
|
758
|
|
759
|
/**
|
760
|
* Returns the taxonomic {@link Rank rank} of <i>this</i> taxon name.
|
761
|
*
|
762
|
* @see Rank
|
763
|
*/
|
764
|
public Rank getRank(){
|
765
|
return this.rank;
|
766
|
}
|
767
|
|
768
|
/**
|
769
|
* @see #getRank()
|
770
|
*/
|
771
|
public void setRank(Rank rank){
|
772
|
this.rank = rank;
|
773
|
}
|
774
|
|
775
|
/**
|
776
|
* Returns the {@link eu.etaxonomy.cdm.model.reference.INomenclaturalReference nomenclatural reference} of <i>this</i> taxon name.
|
777
|
* The nomenclatural reference is here meant to be the one publication
|
778
|
* <i>this</i> taxon name was originally published in while fulfilling the formal
|
779
|
* requirements as specified by the corresponding {@link NomenclaturalCode nomenclatural code}.
|
780
|
*
|
781
|
* @see eu.etaxonomy.cdm.model.reference.INomenclaturalReference
|
782
|
* @see eu.etaxonomy.cdm.model.reference.Reference
|
783
|
*/
|
784
|
public INomenclaturalReference getNomenclaturalReference(){
|
785
|
return this.nomenclaturalReference;
|
786
|
}
|
787
|
/**
|
788
|
* Assigns a {@link eu.etaxonomy.cdm.model.reference.INomenclaturalReference nomenclatural reference} to <i>this</i> taxon name.
|
789
|
* The corresponding {@link eu.etaxonomy.cdm.model.reference.Reference.isNomenclaturallyRelevant nomenclaturally relevant flag} will be set to true
|
790
|
* as it is obviously used for nomenclatural purposes.
|
791
|
*
|
792
|
* @throws IllegalArgumentException if parameter <code>nomenclaturalReference</code> is not assignable from {@link INomenclaturalReference}
|
793
|
* @see #getNomenclaturalReference()
|
794
|
*/
|
795
|
public void setNomenclaturalReference(INomenclaturalReference nomenclaturalReference){
|
796
|
if(nomenclaturalReference != null){
|
797
|
if(!INomenclaturalReference.class.isAssignableFrom(nomenclaturalReference.getClass())){
|
798
|
throw new IllegalArgumentException("Parameter nomenclaturalReference is not assignable from INomenclaturalReference");
|
799
|
}
|
800
|
this.nomenclaturalReference = (Reference)nomenclaturalReference;
|
801
|
} else {
|
802
|
this.nomenclaturalReference = null;
|
803
|
}
|
804
|
}
|
805
|
|
806
|
/**
|
807
|
* Returns the appended phrase string assigned to <i>this</i> taxon name.
|
808
|
* The appended phrase is a non-atomised addition to a name. It is
|
809
|
* not ruled by a nomenclatural code.
|
810
|
*/
|
811
|
public String getAppendedPhrase(){
|
812
|
return this.appendedPhrase;
|
813
|
}
|
814
|
|
815
|
/**
|
816
|
* @see #getAppendedPhrase()
|
817
|
*/
|
818
|
public void setAppendedPhrase(String appendedPhrase){
|
819
|
this.appendedPhrase = appendedPhrase;
|
820
|
}
|
821
|
|
822
|
/**
|
823
|
* Returns the details string of the {@link #getNomenclaturalReference() nomenclatural reference} assigned
|
824
|
* to <i>this</i> taxon name. The details describe the exact localisation within
|
825
|
* the publication used as nomenclature reference. These are mostly
|
826
|
* (implicitly) pages but can also be figures or tables or any other
|
827
|
* element of a publication. A nomenclatural micro reference (details)
|
828
|
* requires the existence of a nomenclatural reference.
|
829
|
*/
|
830
|
//Details of the nomenclatural reference (protologue).
|
831
|
public String getNomenclaturalMicroReference(){
|
832
|
return this.nomenclaturalMicroReference;
|
833
|
}
|
834
|
/**
|
835
|
* @see #getNomenclaturalMicroReference()
|
836
|
*/
|
837
|
public void setNomenclaturalMicroReference(String nomenclaturalMicroReference){
|
838
|
this.nomenclaturalMicroReference = nomenclaturalMicroReference;
|
839
|
}
|
840
|
|
841
|
/* (non-Javadoc)
|
842
|
* @see eu.etaxonomy.cdm.model.common.IParsable#getHasProblem()
|
843
|
*/
|
844
|
public int getParsingProblem(){
|
845
|
return this.parsingProblem;
|
846
|
}
|
847
|
|
848
|
/* (non-Javadoc)
|
849
|
* @see eu.etaxonomy.cdm.model.common.IParsable#setHasProblem(int)
|
850
|
*/
|
851
|
public void setParsingProblem(int parsingProblem){
|
852
|
this.parsingProblem = parsingProblem;
|
853
|
}
|
854
|
|
855
|
/* (non-Javadoc)
|
856
|
* @see eu.etaxonomy.cdm.model.common.IParsable#addProblem(eu.etaxonomy.cdm.strategy.parser.NameParserWarning)
|
857
|
*/
|
858
|
public void addParsingProblem(ParserProblem problem){
|
859
|
parsingProblem = ParserProblem.addProblem(parsingProblem, problem);
|
860
|
}
|
861
|
|
862
|
/* (non-Javadoc)
|
863
|
* @see eu.etaxonomy.cdm.model.common.IParsable#removeParsingProblem(eu.etaxonomy.cdm.strategy.parser.ParserProblem)
|
864
|
*/
|
865
|
public void removeParsingProblem(ParserProblem problem) {
|
866
|
parsingProblem = ParserProblem.removeProblem(parsingProblem, problem);
|
867
|
}
|
868
|
|
869
|
/**
|
870
|
* @param warnings
|
871
|
*/
|
872
|
public void addParsingProblems(int problems){
|
873
|
parsingProblem = ParserProblem.addProblems(parsingProblem, problems);
|
874
|
}
|
875
|
|
876
|
/* (non-Javadoc)
|
877
|
* @see eu.etaxonomy.cdm.model.common.IParsable#hasProblem()
|
878
|
*/
|
879
|
public boolean hasProblem(){
|
880
|
return parsingProblem != 0;
|
881
|
}
|
882
|
|
883
|
|
884
|
|
885
|
/* (non-Javadoc)
|
886
|
* @see eu.etaxonomy.cdm.model.common.IParsable#hasProblem(eu.etaxonomy.cdm.strategy.parser.ParserProblem)
|
887
|
*/
|
888
|
public boolean hasProblem(ParserProblem problem) {
|
889
|
return getParsingProblems().contains(problem);
|
890
|
}
|
891
|
|
892
|
|
893
|
/* (non-Javadoc)
|
894
|
* @see eu.etaxonomy.cdm.model.common.IParsable#problemStarts()
|
895
|
*/
|
896
|
public int getProblemStarts(){
|
897
|
return this.problemStarts;
|
898
|
}
|
899
|
|
900
|
/* (non-Javadoc)
|
901
|
* @see eu.etaxonomy.cdm.model.common.IParsable#setProblemStarts(int)
|
902
|
*/
|
903
|
public void setProblemStarts(int start) {
|
904
|
this.problemStarts = start;
|
905
|
}
|
906
|
|
907
|
/* (non-Javadoc)
|
908
|
* @see eu.etaxonomy.cdm.model.common.IParsable#problemEnds()
|
909
|
*/
|
910
|
public int getProblemEnds(){
|
911
|
return this.problemEnds;
|
912
|
}
|
913
|
|
914
|
/* (non-Javadoc)
|
915
|
* @see eu.etaxonomy.cdm.model.common.IParsable#setProblemEnds(int)
|
916
|
*/
|
917
|
public void setProblemEnds(int end) {
|
918
|
this.problemEnds = end;
|
919
|
}
|
920
|
|
921
|
//*********************** TYPE DESIGNATION *********************************************//
|
922
|
|
923
|
/**
|
924
|
* Returns the set of {@link TypeDesignationBase type designations} assigned
|
925
|
* to <i>this</i> taxon name.
|
926
|
* @see NameTypeDesignation
|
927
|
* @see SpecimenTypeDesignation
|
928
|
*/
|
929
|
public Set<TypeDesignationBase<?>> getTypeDesignations() {
|
930
|
if(typeDesignations == null) {
|
931
|
this.typeDesignations = new HashSet<TypeDesignationBase<?>>();
|
932
|
}
|
933
|
return typeDesignations;
|
934
|
}
|
935
|
|
936
|
/**
|
937
|
* Removes one element from the set of {@link TypeDesignationBase type designations} assigned to
|
938
|
* <i>this</i> taxon name. The type designation itself will be nullified.
|
939
|
*
|
940
|
* @param typeDesignation the type designation which should be deleted
|
941
|
*/
|
942
|
public void removeTypeDesignation(TypeDesignationBase typeDesignation) {
|
943
|
logger.warn("not yet fully implemented: nullify the specimen type designation itself?");
|
944
|
this.typeDesignations.remove(typeDesignation);
|
945
|
}
|
946
|
|
947
|
/**
|
948
|
* Returns the set of {@link SpecimenTypeDesignation specimen type designations} assigned
|
949
|
* to <i>this</i> taxon name. The {@link Rank rank} of <i>this</i> taxon name is generally
|
950
|
* "species" or below. The specimen type designations include all the
|
951
|
* specimens on which the typification of this name is based (which are
|
952
|
* exclusively used to typify taxon names belonging to the same
|
953
|
* {@link HomotypicalGroup homotypical group} to which <i>this</i> taxon name
|
954
|
* belongs) and eventually the status of these designations.
|
955
|
*
|
956
|
* @see SpecimenTypeDesignation
|
957
|
* @see NameTypeDesignation
|
958
|
* @see HomotypicalGroup
|
959
|
*/
|
960
|
@Transient
|
961
|
public Set<SpecimenTypeDesignation> getSpecimenTypeDesignationsOfHomotypicalGroup() {
|
962
|
return this.getHomotypicalGroup().getSpecimenTypeDesignations();
|
963
|
}
|
964
|
|
965
|
//*********************** NAME TYPE DESIGNATION *********************************************//
|
966
|
|
967
|
/**
|
968
|
* Returns the set of {@link NameTypeDesignation name type designations} assigned
|
969
|
* to <i>this</i> taxon name the rank of which must be above "species".
|
970
|
* The name type designations include all the taxon names used to typify
|
971
|
* <i>this</i> taxon name and eventually the rejected or conserved status
|
972
|
* of these designations.
|
973
|
*
|
974
|
* @see NameTypeDesignation
|
975
|
* @see SpecimenTypeDesignation
|
976
|
*/
|
977
|
@Transient
|
978
|
public Set<NameTypeDesignation> getNameTypeDesignations() {
|
979
|
Set<NameTypeDesignation> result = new HashSet<NameTypeDesignation>();
|
980
|
for (TypeDesignationBase typeDesignation : this.typeDesignations){
|
981
|
if (typeDesignation instanceof NameTypeDesignation){
|
982
|
result.add((NameTypeDesignation)typeDesignation);
|
983
|
}
|
984
|
}
|
985
|
return result;
|
986
|
}
|
987
|
|
988
|
/**
|
989
|
* Creates and adds a new {@link NameTypeDesignation name type designation}
|
990
|
* to <i>this</i> taxon name's set of type designations.
|
991
|
*
|
992
|
* @param typeSpecies the taxon name to be used as type of <i>this</i> taxon name
|
993
|
* @param citation the reference for this new designation
|
994
|
* @param citationMicroReference the string with the details (generally pages) within the reference
|
995
|
* @param originalNameString the taxon name string used in the reference to assert this designation
|
996
|
* @param isRejectedType the boolean status for a rejected name type designation
|
997
|
* @param isConservedType the boolean status for a conserved name type designation
|
998
|
* @param isLectoType the boolean status for a lectotype name type designation
|
999
|
* @param isNotDesignated the boolean status for a name type designation without name type
|
1000
|
* @param addToAllHomotypicNames the boolean indicating whether the name type designation should be
|
1001
|
* added to all taxon names of the homotypical group this taxon name belongs to
|
1002
|
* @return
|
1003
|
* @see #getNameTypeDesignations()
|
1004
|
* @see NameTypeDesignation
|
1005
|
* @see TypeDesignationBase#isNotDesignated()
|
1006
|
*/
|
1007
|
public NameTypeDesignation addNameTypeDesignation(TaxonNameBase typeSpecies,
|
1008
|
Reference citation,
|
1009
|
String citationMicroReference,
|
1010
|
String originalNameString,
|
1011
|
NameTypeDesignationStatus status,
|
1012
|
boolean isRejectedType,
|
1013
|
boolean isConservedType,
|
1014
|
/*boolean isLectoType, */
|
1015
|
boolean isNotDesignated,
|
1016
|
boolean addToAllHomotypicNames) {
|
1017
|
NameTypeDesignation nameTypeDesignation = new NameTypeDesignation(typeSpecies, citation, citationMicroReference, originalNameString, status, isRejectedType, isConservedType, isNotDesignated);
|
1018
|
//nameTypeDesignation.setLectoType(isLectoType);
|
1019
|
addTypeDesignation(nameTypeDesignation, addToAllHomotypicNames);
|
1020
|
return nameTypeDesignation;
|
1021
|
}
|
1022
|
|
1023
|
/**
|
1024
|
* Creates and adds a new {@link NameTypeDesignation name type designation}
|
1025
|
* to <i>this</i> taxon name's set of type designations.
|
1026
|
*
|
1027
|
* @param typeSpecies the taxon name to be used as type of <i>this</i> taxon name
|
1028
|
* @param citation the reference for this new designation
|
1029
|
* @param citationMicroReference the string with the details (generally pages) within the reference
|
1030
|
* @param originalNameString the taxon name string used in the reference to assert this designation
|
1031
|
* @param status the name type designation status
|
1032
|
* @param addToAllHomotypicNames the boolean indicating whether the name type designation should be
|
1033
|
* added to all taxon names of the homotypical group this taxon name belongs to
|
1034
|
* @return
|
1035
|
* @see #getNameTypeDesignations()
|
1036
|
* @see NameTypeDesignation
|
1037
|
* @see TypeDesignationBase#isNotDesignated()
|
1038
|
*/
|
1039
|
public NameTypeDesignation addNameTypeDesignation(TaxonNameBase typeSpecies,
|
1040
|
Reference citation,
|
1041
|
String citationMicroReference,
|
1042
|
String originalNameString,
|
1043
|
NameTypeDesignationStatus status,
|
1044
|
boolean addToAllHomotypicNames) {
|
1045
|
NameTypeDesignation nameTypeDesignation = new NameTypeDesignation(typeSpecies, status, citation, citationMicroReference, originalNameString);
|
1046
|
addTypeDesignation(nameTypeDesignation, addToAllHomotypicNames);
|
1047
|
return nameTypeDesignation;
|
1048
|
}
|
1049
|
|
1050
|
//*********************** SPECIMEN TYPE DESIGNATION *********************************************//
|
1051
|
|
1052
|
/**
|
1053
|
* Returns the set of {@link SpecimenTypeDesignation specimen type designations}
|
1054
|
* that typify <i>this</i> taxon name.
|
1055
|
*/
|
1056
|
@Transient
|
1057
|
public Set<SpecimenTypeDesignation> getSpecimenTypeDesignations() {
|
1058
|
Set<SpecimenTypeDesignation> result = new HashSet<SpecimenTypeDesignation>();
|
1059
|
for (TypeDesignationBase typeDesignation : this.typeDesignations){
|
1060
|
if (typeDesignation instanceof SpecimenTypeDesignation){
|
1061
|
result.add((SpecimenTypeDesignation)typeDesignation);
|
1062
|
}
|
1063
|
}
|
1064
|
return result;
|
1065
|
}
|
1066
|
|
1067
|
|
1068
|
/**
|
1069
|
* Creates and adds a new {@link SpecimenTypeDesignation specimen type designation}
|
1070
|
* to <i>this</i> taxon name's set of type designations.
|
1071
|
*
|
1072
|
* @param typeSpecimen the specimen to be used as a type for <i>this</i> taxon name
|
1073
|
* @param status the specimen type designation status
|
1074
|
* @param citation the reference for this new specimen type designation
|
1075
|
* @param citationMicroReference the string with the details (generally pages) within the reference
|
1076
|
* @param originalNameString the taxon name used in the reference to assert this designation
|
1077
|
* @param isNotDesignated the boolean status for a specimen type designation without specimen type
|
1078
|
* @param addToAllHomotypicNames the boolean indicating whether the specimen type designation should be
|
1079
|
* added to all taxon names of the homotypical group the typified
|
1080
|
* taxon name belongs to
|
1081
|
* @return
|
1082
|
* @see #getSpecimenTypeDesignations()
|
1083
|
* @see SpecimenTypeDesignationStatus
|
1084
|
* @see SpecimenTypeDesignation
|
1085
|
* @see TypeDesignationBase#isNotDesignated()
|
1086
|
*/
|
1087
|
public SpecimenTypeDesignation addSpecimenTypeDesignation(Specimen typeSpecimen,
|
1088
|
SpecimenTypeDesignationStatus status,
|
1089
|
Reference citation,
|
1090
|
String citationMicroReference,
|
1091
|
String originalNameString,
|
1092
|
boolean isNotDesignated,
|
1093
|
boolean addToAllHomotypicNames) {
|
1094
|
SpecimenTypeDesignation specimenTypeDesignation = new SpecimenTypeDesignation(typeSpecimen, status, citation, citationMicroReference, originalNameString, isNotDesignated);
|
1095
|
addTypeDesignation(specimenTypeDesignation, addToAllHomotypicNames);
|
1096
|
return specimenTypeDesignation;
|
1097
|
}
|
1098
|
|
1099
|
//used by merge strategy
|
1100
|
private boolean addTypeDesignation(TypeDesignationBase typeDesignation){
|
1101
|
return addTypeDesignation(typeDesignation, true);
|
1102
|
}
|
1103
|
|
1104
|
/**
|
1105
|
* Adds a {@link TypeDesignationBase type designation} to <code>this</code> taxon name's set of type designations
|
1106
|
*
|
1107
|
* @param typeDesignation the typeDesignation to be added to <code>this</code> taxon name
|
1108
|
* @param addToAllNames the boolean indicating whether the type designation should be
|
1109
|
* added to all taxon names of the homotypical group the typified
|
1110
|
* taxon name belongs to
|
1111
|
* @return true if the operation was succesful
|
1112
|
*
|
1113
|
* @throws IllegalArgumentException if the type designation already has typified names, an {@link IllegalArgumentException exception}
|
1114
|
* is thrown. We do this to prevent a type designation to be used for multiple taxon names.
|
1115
|
*
|
1116
|
*/
|
1117
|
public boolean addTypeDesignation(TypeDesignationBase typeDesignation, boolean addToAllNames){
|
1118
|
//at them moment typeDesignations are not persisted with the homotypical group
|
1119
|
//so explicit adding to the homotypical group is not necessary.
|
1120
|
if (typeDesignation != null){
|
1121
|
checkHomotypicalGroup(typeDesignation);
|
1122
|
this.typeDesignations.add(typeDesignation);
|
1123
|
typeDesignation.addTypifiedName(this);
|
1124
|
|
1125
|
if (addToAllNames){
|
1126
|
for (TaxonNameBase taxonName : this.getHomotypicalGroup().getTypifiedNames()){
|
1127
|
if (taxonName != this){
|
1128
|
taxonName.addTypeDesignation(typeDesignation, false);
|
1129
|
}
|
1130
|
}
|
1131
|
}
|
1132
|
}
|
1133
|
return true;
|
1134
|
}
|
1135
|
|
1136
|
/**
|
1137
|
* Throws an Exception this type designation already has typified names from another homotypical group.
|
1138
|
* @param typeDesignation
|
1139
|
*/
|
1140
|
private void checkHomotypicalGroup(TypeDesignationBase typeDesignation) {
|
1141
|
if(typeDesignation.getTypifiedNames().size() > 0){
|
1142
|
Set<HomotypicalGroup> groups = new HashSet<HomotypicalGroup>();
|
1143
|
Set<TaxonNameBase> names = typeDesignation.getTypifiedNames();
|
1144
|
for (TaxonNameBase taxonName: names){
|
1145
|
groups.add(taxonName.getHomotypicalGroup());
|
1146
|
}
|
1147
|
if (groups.size() > 1){
|
1148
|
throw new IllegalArgumentException("TypeDesignation already has typified names from another homotypical group.");
|
1149
|
}
|
1150
|
}
|
1151
|
}
|
1152
|
|
1153
|
|
1154
|
|
1155
|
//*********************** HOMOTYPICAL GROUP *********************************************//
|
1156
|
|
1157
|
|
1158
|
/**
|
1159
|
* Returns the {@link HomotypicalGroup homotypical group} to which
|
1160
|
* <i>this</i> taxon name belongs. A homotypical group represents all taxon names
|
1161
|
* that share the same types.
|
1162
|
*
|
1163
|
* @see HomotypicalGroup
|
1164
|
*/
|
1165
|
|
1166
|
public HomotypicalGroup getHomotypicalGroup() {
|
1167
|
return homotypicalGroup;
|
1168
|
}
|
1169
|
|
1170
|
/*
|
1171
|
* @see #getHomotypicalGroup()
|
1172
|
*/
|
1173
|
public void setHomotypicalGroup(HomotypicalGroup homotypicalGroup) {
|
1174
|
if (homotypicalGroup == null){
|
1175
|
throw new IllegalArgumentException("HomotypicalGroup of name should never be null but was set to 'null'");
|
1176
|
}
|
1177
|
this.homotypicalGroup = homotypicalGroup;
|
1178
|
if (! homotypicalGroup.typifiedNames.contains(this)){
|
1179
|
homotypicalGroup.addTypifiedName(this);
|
1180
|
}
|
1181
|
}
|
1182
|
|
1183
|
|
1184
|
|
1185
|
// *************************************************************************//
|
1186
|
|
1187
|
/**
|
1188
|
* @see #getNomenclaturalReference()
|
1189
|
*/
|
1190
|
@Transient
|
1191
|
public Reference getCitation(){
|
1192
|
//TODO What is the purpose of this method differing from the getNomenclaturalReference method?
|
1193
|
logger.warn("getCitation not yet implemented");
|
1194
|
return null;
|
1195
|
}
|
1196
|
|
1197
|
/**
|
1198
|
* Returns the complete string containing the
|
1199
|
* {@link eu.etaxonomy.cdm.model.reference.INomenclaturalReference#getNomenclaturalCitation() nomenclatural reference citation}
|
1200
|
* and the {@link #getNomenclaturalMicroReference() details} assigned to <i>this</i> taxon name.
|
1201
|
*
|
1202
|
* @return the string containing the nomenclatural reference of <i>this</i> taxon name
|
1203
|
* @see eu.etaxonomy.cdm.model.reference.INomenclaturalReference#getNomenclaturalCitation()
|
1204
|
* @see #getNomenclaturalReference()
|
1205
|
* @see #getNomenclaturalMicroReference()
|
1206
|
*/
|
1207
|
@Transient
|
1208
|
public String getCitationString(){
|
1209
|
return getNomenclaturalReference().getNomenclaturalCitation(getNomenclaturalMicroReference());
|
1210
|
}
|
1211
|
|
1212
|
/**
|
1213
|
* Returns the parsing problems
|
1214
|
* @return
|
1215
|
*/
|
1216
|
public List<ParserProblem> getParsingProblems(){
|
1217
|
return ParserProblem.warningList(this.parsingProblem);
|
1218
|
}
|
1219
|
|
1220
|
/**
|
1221
|
* Returns the string containing the publication date (generally only year)
|
1222
|
* of the {@link #getNomenclaturalReference() nomenclatural reference} for <i>this</i> taxon name, null if there is
|
1223
|
* no nomenclatural reference.
|
1224
|
*
|
1225
|
* @return the string containing the publication date of <i>this</i> taxon name
|
1226
|
* @see eu.etaxonomy.cdm.model.reference.INomenclaturalReference#getYear()
|
1227
|
*/
|
1228
|
@Transient
|
1229
|
public String getReferenceYear(){
|
1230
|
if (this.getNomenclaturalReference() != null ){
|
1231
|
return this.getNomenclaturalReference().getYear();
|
1232
|
}else{
|
1233
|
return null;
|
1234
|
}
|
1235
|
}
|
1236
|
|
1237
|
/**
|
1238
|
* Returns the set of {@link eu.etaxonomy.cdm.model.taxon.TaxonBase taxon bases} that refer to <i>this</i> taxon name.
|
1239
|
* In this context a taxon base means the use of a taxon name by a reference
|
1240
|
* either as a {@link eu.etaxonomy.cdm.model.taxon.Taxon taxon} ("accepted/correct" name) or
|
1241
|
* as a (junior) {@link eu.etaxonomy.cdm.model.taxon.Synonym synonym}.
|
1242
|
* A taxon name can be used by several distinct {@link eu.etaxonomy.cdm.model.reference.Reference references} but only once
|
1243
|
* within a taxonomic treatment (identified by one reference).
|
1244
|
*
|
1245
|
* @see #getTaxa()
|
1246
|
* @see #getSynonyms()
|
1247
|
*/
|
1248
|
public Set<TaxonBase> getTaxonBases() {
|
1249
|
if(taxonBases == null) {
|
1250
|
this.taxonBases = new HashSet<TaxonBase>();
|
1251
|
}
|
1252
|
return this.taxonBases;
|
1253
|
}
|
1254
|
|
1255
|
/**
|
1256
|
* Adds a new {@link eu.etaxonomy.cdm.model.taxon.TaxonBase taxon base}
|
1257
|
* to the set of taxon bases using <i>this</i> taxon name.
|
1258
|
*
|
1259
|
* @param taxonBase the taxon base to be added
|
1260
|
* @see #getTaxonBases()
|
1261
|
* @see #removeTaxonBase(TaxonBase)
|
1262
|
*/
|
1263
|
//TODO protected
|
1264
|
public void addTaxonBase(TaxonBase taxonBase){
|
1265
|
Method method = ReflectionUtils.findMethod(TaxonBase.class, "setName", new Class[] {TaxonNameBase.class});
|
1266
|
ReflectionUtils.makeAccessible(method);
|
1267
|
ReflectionUtils.invokeMethod(method, taxonBase, new Object[] {this});
|
1268
|
taxonBases.add(taxonBase);
|
1269
|
}
|
1270
|
/**
|
1271
|
* Removes one element from the set of {@link eu.etaxonomy.cdm.model.taxon.TaxonBase taxon bases} that refer to <i>this</i> taxon name.
|
1272
|
*
|
1273
|
* @param taxonBase the taxon base which should be removed from the corresponding set
|
1274
|
* @see #getTaxonBases()
|
1275
|
* @see #addTaxonBase(TaxonBase)
|
1276
|
*/
|
1277
|
public void removeTaxonBase(TaxonBase taxonBase){
|
1278
|
Method method = ReflectionUtils.findMethod(TaxonBase.class, "setName", new Class[] {TaxonNameBase.class});
|
1279
|
ReflectionUtils.makeAccessible(method);
|
1280
|
ReflectionUtils.invokeMethod(method, taxonBase, new Object[] {null});
|
1281
|
taxonBases.remove(taxonBase);
|
1282
|
}
|
1283
|
|
1284
|
/**
|
1285
|
* Returns the set of {@link eu.etaxonomy.cdm.model.taxon.Taxon taxa} ("accepted/correct" names according to any
|
1286
|
* reference) that are based on <i>this</i> taxon name. This set is a subset of
|
1287
|
* the set returned by getTaxonBases().
|
1288
|
*
|
1289
|
* @see eu.etaxonomy.cdm.model.taxon.Taxon
|
1290
|
* @see #getTaxonBases()
|
1291
|
* @see #getSynonyms()
|
1292
|
*/
|
1293
|
@Transient
|
1294
|
public Set<Taxon> getTaxa(){
|
1295
|
Set<Taxon> result = new HashSet<Taxon>();
|
1296
|
for (TaxonBase taxonBase : this.taxonBases){
|
1297
|
if (taxonBase instanceof Taxon){
|
1298
|
result.add((Taxon)taxonBase);
|
1299
|
}
|
1300
|
}
|
1301
|
return result;
|
1302
|
}
|
1303
|
|
1304
|
/**
|
1305
|
* Returns the set of {@link eu.etaxonomy.cdm.model.taxon.Synonym (junior) synonyms} (according to any
|
1306
|
* reference) that are based on <i>this</i> taxon name. This set is a subset of
|
1307
|
* the set returned by getTaxonBases().
|
1308
|
*
|
1309
|
* @see eu.etaxonomy.cdm.model.taxon.Synonym
|
1310
|
* @see #getTaxonBases()
|
1311
|
* @see #getTaxa()
|
1312
|
*/
|
1313
|
@Transient
|
1314
|
public Set<Synonym> getSynonyms() {
|
1315
|
Set<Synonym> result = new HashSet<Synonym>();
|
1316
|
for (TaxonBase taxonBase : this.taxonBases){
|
1317
|
if (taxonBase instanceof Synonym){
|
1318
|
result.add((Synonym)taxonBase);
|
1319
|
}
|
1320
|
}
|
1321
|
return result;
|
1322
|
}
|
1323
|
|
1324
|
|
1325
|
// *********** DESCRIPTIONS *************************************
|
1326
|
|
1327
|
/**
|
1328
|
* Returns the set of {@link eu.etaxonomy.cdm.model.description.TaxonNameDescription taxon name descriptions} assigned
|
1329
|
* to <i>this</i> taxon name. A taxon name description is a piece of information
|
1330
|
* concerning the taxon name like for instance the content of its first
|
1331
|
* publication (protolog) or a picture of this publication.
|
1332
|
*
|
1333
|
* @see #addDescription(TaxonNameDescription)
|
1334
|
* @see #removeDescription(TaxonNameDescription)
|
1335
|
* @see eu.etaxonomy.cdm.model.description.TaxonNameDescription
|
1336
|
*/
|
1337
|
public Set<TaxonNameDescription> getDescriptions() {
|
1338
|
return descriptions;
|
1339
|
}
|
1340
|
|
1341
|
/**
|
1342
|
* Adds a new {@link eu.etaxonomy.cdm.model.description.TaxonNameDescription taxon name description}
|
1343
|
* to the set of taxon name descriptions assigned to <i>this</i> taxon name. The
|
1344
|
* content of the {@link eu.etaxonomy.cdm.model.description.TaxonNameDescription#getTaxonName() taxonName attribute} of the
|
1345
|
* taxon name description itself will be replaced with <i>this</i> taxon name.
|
1346
|
*
|
1347
|
* @param description the taxon name description to be added
|
1348
|
* @see #getDescriptions()
|
1349
|
* @see #removeDescription(TaxonNameDescription)
|
1350
|
*/
|
1351
|
public void addDescription(TaxonNameDescription description) {
|
1352
|
java.lang.reflect.Field field = ReflectionUtils.findField(TaxonNameDescription.class, "taxonName", TaxonNameBase.class);
|
1353
|
ReflectionUtils.makeAccessible(field);
|
1354
|
ReflectionUtils.setField(field, description, this);
|
1355
|
descriptions.add(description);
|
1356
|
}
|
1357
|
/**
|
1358
|
* Removes one element from the set of {@link eu.etaxonomy.cdm.model.description.TaxonNameDescription taxon name descriptions} assigned
|
1359
|
* to <i>this</i> taxon name. The content of the {@link eu.etaxonomy.cdm.model.description.TaxonNameDescription#getTaxonName() taxonName attribute}
|
1360
|
* of the description itself will be set to "null".
|
1361
|
*
|
1362
|
* @param description the taxon name description which should be removed
|
1363
|
* @see #getDescriptions()
|
1364
|
* @see #addDescription(TaxonNameDescription)
|
1365
|
* @see eu.etaxonomy.cdm.model.description.TaxonNameDescription#getTaxonName()
|
1366
|
*/
|
1367
|
public void removeDescription(TaxonNameDescription description) {
|
1368
|
java.lang.reflect.Field field = ReflectionUtils.findField(TaxonNameDescription.class, "taxonName", TaxonNameBase.class);
|
1369
|
ReflectionUtils.makeAccessible(field);
|
1370
|
ReflectionUtils.setField(field, description, null);
|
1371
|
descriptions.remove(description);
|
1372
|
}
|
1373
|
|
1374
|
// *********** HOMOTYPIC GROUP METHODS **************************************************
|
1375
|
|
1376
|
@Transient
|
1377
|
public void mergeHomotypicGroups(TaxonNameBase name){
|
1378
|
this.getHomotypicalGroup().merge(name.getHomotypicalGroup());
|
1379
|
//HomotypicalGroup thatGroup = name.homotypicalGroup;
|
1380
|
name.setHomotypicalGroup(this.homotypicalGroup);
|
1381
|
}
|
1382
|
|
1383
|
/**
|
1384
|
* Returns the boolean value indicating whether a given taxon name belongs
|
1385
|
* to the same {@link HomotypicalGroup homotypical group} as <i>this</i> taxon name (true)
|
1386
|
* or not (false). Returns "true" only if the homotypical groups of both
|
1387
|
* taxon names exist and if they are identical.
|
1388
|
*
|
1389
|
* @param homoTypicName the taxon name the homotypical group of which is to be checked
|
1390
|
* @return the boolean value of the check
|
1391
|
* @see HomotypicalGroup
|
1392
|
*/
|
1393
|
@Transient
|
1394
|
public boolean isHomotypic(TaxonNameBase homoTypicName) {
|
1395
|
if (homoTypicName == null) {
|
1396
|
return false;
|
1397
|
}
|
1398
|
HomotypicalGroup homotypicGroup = homoTypicName.getHomotypicalGroup();
|
1399
|
if (homotypicGroup == null || this.getHomotypicalGroup() == null) {
|
1400
|
return false;
|
1401
|
}
|
1402
|
if (homotypicGroup.equals(this.getHomotypicalGroup())) {
|
1403
|
return true;
|
1404
|
}
|
1405
|
return false;
|
1406
|
}
|
1407
|
|
1408
|
|
1409
|
/**
|
1410
|
* Checks whether name is a basionym for ALL names
|
1411
|
* in its homotypical group.
|
1412
|
* Returns <code>false</code> if there are no other names in the group
|
1413
|
* @param name
|
1414
|
* @return
|
1415
|
*/
|
1416
|
@Transient
|
1417
|
public boolean isGroupsBasionym() {
|
1418
|
Set<TaxonNameBase> typifiedNames = homotypicalGroup.getTypifiedNames();
|
1419
|
|
1420
|
// Check whether there are any other names in the group
|
1421
|
if (typifiedNames.size() == 1) {
|
1422
|
return false;
|
1423
|
}
|
1424
|
|
1425
|
boolean isBasionymToAll = true;
|
1426
|
|
1427
|
for (TaxonNameBase taxonName : typifiedNames) {
|
1428
|
if (!taxonName.equals(this)) {
|
1429
|
if (! isBasionymFor(taxonName)) {
|
1430
|
return false;
|
1431
|
}
|
1432
|
}
|
1433
|
}
|
1434
|
return true;
|
1435
|
}
|
1436
|
|
1437
|
/**
|
1438
|
* Checks whether a basionym relationship exists between fromName and toName.
|
1439
|
*
|
1440
|
* @param fromName
|
1441
|
* @param toName
|
1442
|
* @return
|
1443
|
*/
|
1444
|
@Transient
|
1445
|
public boolean isBasionymFor(TaxonNameBase newCombinationName) {
|
1446
|
Set<NameRelationship> relations = newCombinationName.getRelationsToThisName();
|
1447
|
for (NameRelationship relation : relations) {
|
1448
|
if (relation.getType().equals(NameRelationshipType.BASIONYM()) &&
|
1449
|
relation.getFromName().equals(this)) {
|
1450
|
return true;
|
1451
|
}
|
1452
|
}
|
1453
|
return false;
|
1454
|
}
|
1455
|
|
1456
|
/**
|
1457
|
* Creates a basionym relationship to all other names in this names homotypical
|
1458
|
* group.
|
1459
|
*
|
1460
|
* @see HomotypicalGroup.setGroupBasionym(TaxonNameBase basionymName)
|
1461
|
|
1462
|
*/
|
1463
|
/* (non-Javadoc)
|
1464
|
* @see eu.etaxonomy.cdm.model.name.HomotypicalGroup#setGroupBasionym(TaxonNameBase)
|
1465
|
*/
|
1466
|
@Transient
|
1467
|
public void makeGroupsBasionym() {
|
1468
|
this.homotypicalGroup.setGroupBasionym(this);
|
1469
|
}
|
1470
|
|
1471
|
|
1472
|
//********* Rank comparison shortcuts ********************//
|
1473
|
/**
|
1474
|
* Returns the boolean value indicating whether the taxonomic {@link Rank rank} of <i>this</i>
|
1475
|
* taxon name is higher than the genus rank (true) or not (false).
|
1476
|
* Suprageneric non viral names are monomials.
|
1477
|
* Returns false if rank is null.
|
1478
|
*
|
1479
|
* @see #isGenus()
|
1480
|
* @see #isInfraGeneric()
|
1481
|
* @see #isSpecies()
|
1482
|
* @see #isInfraSpecific()
|
1483
|
*/
|
1484
|
@Transient
|
1485
|
public boolean isSupraGeneric() {
|
1486
|
if (rank == null){
|
1487
|
return false;
|
1488
|
}
|
1489
|
return getRank().isSupraGeneric();
|
1490
|
}
|
1491
|
/**
|
1492
|
* Returns the boolean value indicating whether the taxonomic {@link Rank rank} of <i>this</i>
|
1493
|
* taxon name is the genus rank (true) or not (false). Non viral names with
|
1494
|
* genus rank are monomials. Returns false if rank is null.
|
1495
|
*
|
1496
|
* @see #isSupraGeneric()
|
1497
|
* @see #isInfraGeneric()
|
1498
|
* @see #isSpecies()
|
1499
|
* @see #isInfraSpecific()
|
1500
|
*/
|
1501
|
@Transient
|
1502
|
public boolean isGenus() {
|
1503
|
if (rank == null){
|
1504
|
return false;
|
1505
|
}
|
1506
|
return getRank().isGenus();
|
1507
|
}
|
1508
|
/**
|
1509
|
* Returns the boolean value indicating whether the taxonomic {@link Rank rank} of <i>this</i>
|
1510
|
* taxon name is higher than the species rank and lower than the
|
1511
|
* genus rank (true) or not (false). Infrageneric non viral names are
|
1512
|
* binomials. Returns false if rank is null.
|
1513
|
*
|
1514
|
* @see #isSupraGeneric()
|
1515
|
* @see #isGenus()
|
1516
|
* @see #isSpecies()
|
1517
|
* @see #isInfraSpecific()
|
1518
|
*/
|
1519
|
@Transient
|
1520
|
public boolean isInfraGeneric() {
|
1521
|
if (rank == null){
|
1522
|
return false;
|
1523
|
}
|
1524
|
return getRank().isInfraGeneric();
|
1525
|
}
|
1526
|
|
1527
|
/**
|
1528
|
* Returns the boolean value indicating whether the taxonomic {@link Rank rank} of <i>this</i>
|
1529
|
* taxon name is higher than the species rank (true) or not (false).
|
1530
|
* Returns false if rank is null.
|
1531
|
*
|
1532
|
* @see #isGenus()
|
1533
|
* @see #isInfraGeneric()
|
1534
|
* @see #isSpecies()
|
1535
|
* @see #isInfraSpecific()
|
1536
|
*/
|
1537
|
@Transient
|
1538
|
public boolean isSupraSpecific(){
|
1539
|
if (rank == null) {
|
1540
|
return false;
|
1541
|
}
|
1542
|
return getRank().isHigher(Rank.SPECIES());
|
1543
|
}
|
1544
|
|
1545
|
/**
|
1546
|
* Returns the boolean value indicating whether the taxonomic {@link Rank rank} of <i>this</i>
|
1547
|
* taxon name is the species rank (true) or not (false). Non viral names
|
1548
|
* with species rank are binomials.
|
1549
|
* Returns false if rank is null.
|
1550
|
*
|
1551
|
* @see #isSupraGeneric()
|
1552
|
* @see #isGenus()
|
1553
|
* @see #isInfraGeneric()
|
1554
|
* @see #isInfraSpecific()
|
1555
|
*/
|
1556
|
@Transient
|
1557
|
public boolean isSpecies() {
|
1558
|
if (rank == null){
|
1559
|
return false;
|
1560
|
}
|
1561
|
return getRank().isSpecies();
|
1562
|
}
|
1563
|
/**
|
1564
|
* Returns the boolean value indicating whether the taxonomic {@link Rank rank} of <i>this</i>
|
1565
|
* taxon name is lower than the species rank (true) or not (false).
|
1566
|
* Infraspecific non viral names are trinomials.
|
1567
|
* Returns false if rank is null.
|
1568
|
*
|
1569
|
* @see #isSupraGeneric()
|
1570
|
* @see #isGenus()
|
1571
|
* @see #isInfraGeneric()
|
1572
|
* @see #isSpecies()
|
1573
|
*/
|
1574
|
@Transient
|
1575
|
public boolean isInfraSpecific() {
|
1576
|
if (rank == null){
|
1577
|
return false;
|
1578
|
}
|
1579
|
return getRank().isInfraSpecific();
|
1580
|
}
|
1581
|
|
1582
|
|
1583
|
/**
|
1584
|
* Returns null as the {@link NomenclaturalCode nomenclatural code} that governs
|
1585
|
* the construction of <i>this</i> taxon name since there is no specific
|
1586
|
* nomenclatural code defined. The real implementention takes place in the
|
1587
|
* subclasses {@link ViralName ViralName}, {@link BacterialName BacterialName},
|
1588
|
* {@link BotanicalName BotanicalName}, {@link CultivarPlantName CultivarPlantName} and
|
1589
|
* {@link ZoologicalName ZoologicalName}. Each taxon name is governed by one
|
1590
|
* and only one nomenclatural code.
|
1591
|
*
|
1592
|
* @return null
|
1593
|
* @see #isCodeCompliant()
|
1594
|
* @see #getHasProblem()
|
1595
|
*/
|
1596
|
abstract public NomenclaturalCode getNomenclaturalCode();
|
1597
|
|
1598
|
/* (non-Javadoc)
|
1599
|
* @see eu.etaxonomy.cdm.model.common.IdentifiableEntity#generateTitle()
|
1600
|
*/
|
1601
|
/**
|
1602
|
* Generates and returns the string with the scientific name of <i>this</i>
|
1603
|
* taxon name (only non viral taxon names can be generated from their
|
1604
|
* components). This string may be stored in the inherited
|
1605
|
* {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#getTitleCache() titleCache} attribute.
|
1606
|
* This method overrides the generic and inherited
|
1607
|
* {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#generateTitle() method} from
|
1608
|
* {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity IdentifiableEntity}.
|
1609
|
*
|
1610
|
* @return the string with the composed name of this non viral taxon name with authorship (and maybe year)
|
1611
|
* @see eu.etaxonomy.cdm.model.common.IdentifiableEntity#generateTitle()
|
1612
|
* @see eu.etaxonomy.cdm.model.common.IdentifiableEntity#getTitleCache()
|
1613
|
*/
|
1614
|
// @Override
|
1615
|
// public abstract String generateTitle();
|
1616
|
|
1617
|
/**
|
1618
|
* Creates a basionym relationship between this name and
|
1619
|
* each name in its homotypic group.
|
1620
|
*
|
1621
|
* @param basionymName
|
1622
|
*/
|
1623
|
@Transient
|
1624
|
public void setAsGroupsBasionym() {
|
1625
|
|
1626
|
|
1627
|
HomotypicalGroup homotypicalGroup = this.getHomotypicalGroup();
|
1628
|
|
1629
|
if (homotypicalGroup == null) {
|
1630
|
return;
|
1631
|
}
|
1632
|
|
1633
|
Set<NameRelationship> relations = new HashSet<NameRelationship>();
|
1634
|
Set<NameRelationship> removeRelations = new HashSet<NameRelationship>();
|
1635
|
|
1636
|
for(TaxonNameBase<?, ?> typifiedName : homotypicalGroup.getTypifiedNames()){
|
1637
|
|
1638
|
Set<NameRelationship> nameRelations = typifiedName.getRelationsFromThisName();
|
1639
|
|
1640
|
for(NameRelationship nameRelation : nameRelations){
|
1641
|
relations.add(nameRelation);
|
1642
|
}
|
1643
|
}
|
1644
|
|
1645
|
for (NameRelationship relation : relations) {
|
1646
|
|
1647
|
// If this is a basionym relation, and toName is in the homotypical group,
|
1648
|
// remove the relationship.
|
1649
|
if (relation.getType().equals(NameRelationshipType.BASIONYM()) &&
|
1650
|
relation.getToName().getHomotypicalGroup().equals(homotypicalGroup)) {
|
1651
|
removeRelations.add(relation);
|
1652
|
}
|
1653
|
}
|
1654
|
|
1655
|
// Removing relations from a set through which we are iterating causes a
|
1656
|
// ConcurrentModificationException. Therefore, we delete the targeted
|
1657
|
// relations in a second step.
|
1658
|
for (NameRelationship relation : removeRelations) {
|
1659
|
this.removeNameRelationship(relation);
|
1660
|
}
|
1661
|
|
1662
|
|
1663
|
for (TaxonNameBase<?, ?> name : homotypicalGroup.getTypifiedNames()) {
|
1664
|
if (!name.equals(this)) {
|
1665
|
|
1666
|
// First check whether the relationship already exists
|
1667
|
if (!this.isBasionymFor(name)) {
|
1668
|
|
1669
|
// Then create it
|
1670
|
name.addRelationshipFromName(this,
|
1671
|
NameRelationshipType.BASIONYM(), null);
|
1672
|
}
|
1673
|
}
|
1674
|
}
|
1675
|
}
|
1676
|
|
1677
|
/**
|
1678
|
* Removes basionym relationship between this name and
|
1679
|
* each name in its homotypic group.
|
1680
|
*
|
1681
|
* @param basionymName
|
1682
|
*/
|
1683
|
@Transient
|
1684
|
public void removeAsGroupsBasionym() {
|
1685
|
|
1686
|
HomotypicalGroup homotypicalGroup = this.getHomotypicalGroup();
|
1687
|
|
1688
|
if (homotypicalGroup == null) {
|
1689
|
return;
|
1690
|
}
|
1691
|
|
1692
|
Set<NameRelationship> relations = new HashSet<NameRelationship>();
|
1693
|
Set<NameRelationship> removeRelations = new HashSet<NameRelationship>();
|
1694
|
|
1695
|
for(TaxonNameBase<?, ?> typifiedName : homotypicalGroup.getTypifiedNames()){
|
1696
|
|
1697
|
Set<NameRelationship> nameRelations = typifiedName.getRelationsFromThisName();
|
1698
|
|
1699
|
for(NameRelationship nameRelation : nameRelations){
|
1700
|
relations.add(nameRelation);
|
1701
|
}
|
1702
|
}
|
1703
|
|
1704
|
for (NameRelationship relation : relations) {
|
1705
|
|
1706
|
// If this is a basionym relation, and toName is in the homotypical group,
|
1707
|
// and fromName is basionymName, remove the relationship.
|
1708
|
if (relation.getType().equals(NameRelationshipType.BASIONYM()) &&
|
1709
|
relation.getFromName().equals(this) &&
|
1710
|
relation.getToName().getHomotypicalGroup().equals(homotypicalGroup)) {
|
1711
|
removeRelations.add(relation);
|
1712
|
}
|
1713
|
}
|
1714
|
|
1715
|
// Removing relations from a set through which we are iterating causes a
|
1716
|
// ConcurrentModificationException. Therefore, we delete the targeted
|
1717
|
// relations in a second step.
|
1718
|
for (NameRelationship relation : removeRelations) {
|
1719
|
this.removeNameRelationship(relation);
|
1720
|
}
|
1721
|
}
|
1722
|
|
1723
|
//*********************** CLONE ********************************************************/
|
1724
|
|
1725
|
/**
|
1726
|
* Clones <i>this</i> taxon name. This is a shortcut that enables to create
|
1727
|
* a new instance that differs only slightly from <i>this</i> taxon name by
|
1728
|
* modifying only some of the attributes.<BR><BR>
|
1729
|
* Usages of this name in a taxon concept are <b>not</b> cloned.<BR>
|
1730
|
* <b>The name gets a newly created homotypical group</b><BR>
|
1731
|
* (CAUTION: this behaviour needs to be discussed and may change in future).<BR><BR>
|
1732
|
* {@link TaxonNameDescription Name descriptions} are cloned and not reused.<BR>
|
1733
|
* {@link TypeDesignationBase Type designations} are cloned and not reused.<BR>
|
1734
|
*
|
1735
|
* @see eu.etaxonomy.cdm.model.media.IdentifiableEntity#clone()
|
1736
|
* @see java.lang.Object#clone()
|
1737
|
*/
|
1738
|
@Override
|
1739
|
public Object clone() {
|
1740
|
TaxonNameBase result;
|
1741
|
try {
|
1742
|
result = (TaxonNameBase)super.clone();
|
1743
|
|
1744
|
//taxonBases -> empty
|
1745
|
result.taxonBases = new HashSet<TaxonBase>();
|
1746
|
|
1747
|
//empty caches
|
1748
|
if (! protectedFullTitleCache){
|
1749
|
result.fullTitleCache = null;
|
1750
|
}
|
1751
|
|
1752
|
//descriptions
|
1753
|
result.descriptions = new HashSet<TaxonNameDescription>();
|
1754
|
for (TaxonNameDescription taxonNameDescription : getDescriptions()){
|
1755
|
TaxonNameDescription newDescription = (TaxonNameDescription)taxonNameDescription.clone();
|
1756
|
result.descriptions.add(newDescription);
|
1757
|
}
|
1758
|
|
1759
|
//status
|
1760
|
result.status = new HashSet<NomenclaturalStatus>();
|
1761
|
for (NomenclaturalStatus nomenclaturalStatus : getStatus()){
|
1762
|
NomenclaturalStatus newStatus = (NomenclaturalStatus)nomenclaturalStatus.clone();
|
1763
|
result.status.add(newStatus);
|
1764
|
}
|
1765
|
|
1766
|
|
1767
|
//To Relations
|
1768
|
result.relationsToThisName = new HashSet<NameRelationship>();
|
1769
|
for (NameRelationship toRelationship : getRelationsToThisName()){
|
1770
|
NameRelationship newRelationship = (NameRelationship)toRelationship.clone();
|
1771
|
newRelationship.setRelatedTo(result);
|
1772
|
result.relationsToThisName.add(newRelationship);
|
1773
|
}
|
1774
|
|
1775
|
//From Relations
|
1776
|
result.relationsFromThisName = new HashSet<NameRelationship>();
|
1777
|
for (NameRelationship fromRelationship : getRelationsFromThisName()){
|
1778
|
NameRelationship newRelationship = (NameRelationship)fromRelationship.clone();
|
1779
|
newRelationship.setRelatedFrom(result);
|
1780
|
result.relationsFromThisName.add(newRelationship);
|
1781
|
}
|
1782
|
|
1783
|
//type designations
|
1784
|
result.typeDesignations = new HashSet<TypeDesignationBase>();
|
1785
|
for (TypeDesignationBase typeDesignation : getTypeDesignations()){
|
1786
|
TypeDesignationBase newDesignation = (TypeDesignationBase)typeDesignation.clone();
|
1787
|
result.typeDesignations.add(newDesignation);
|
1788
|
newDesignation.addTypifiedName(result);
|
1789
|
}
|
1790
|
|
1791
|
//homotypicalGroup
|
1792
|
//TODO still needs to be discussed
|
1793
|
homotypicalGroup = HomotypicalGroup.NewInstance();
|
1794
|
homotypicalGroup.addTypifiedName(this);
|
1795
|
|
1796
|
//no changes to: appendedPharse, nomenclaturalReference,
|
1797
|
//nomenclaturalMicroReference, parsingProblem, problemEnds, problemStarts
|
1798
|
//protectedFullTitleCache, rank
|
1799
|
return result;
|
1800
|
} catch (CloneNotSupportedException e) {
|
1801
|
logger.warn("Object does not implement cloneable");
|
1802
|
e.printStackTrace();
|
1803
|
return null;
|
1804
|
}
|
1805
|
|
1806
|
}
|
1807
|
}
|