Project

General

Profile

Download (33.7 KB) Statistics
| Branch: | Tag: | Revision:
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.HashMap;
13
import java.util.List;
14
import java.util.Map;
15
import java.util.UUID;
16

    
17
import javax.persistence.Entity;
18
import javax.persistence.Transient;
19
import javax.xml.bind.annotation.XmlAccessType;
20
import javax.xml.bind.annotation.XmlAccessorType;
21
import javax.xml.bind.annotation.XmlType;
22

    
23
import org.apache.commons.lang.StringUtils;
24
import org.apache.log4j.Logger;
25
import org.hibernate.envers.Audited;
26
import org.hibernate.search.annotations.Indexed;
27

    
28
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
29
import eu.etaxonomy.cdm.model.common.Language;
30
import eu.etaxonomy.cdm.model.common.OrderedTermBase;
31
import eu.etaxonomy.cdm.model.common.Representation;
32
import eu.etaxonomy.cdm.model.common.TermVocabulary;
33
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException;
34

    
35
/**
36
 * The class representing the taxonomical ranks (like "Family", "Genus" or
37
 * "Species") used for {@link TaxonNameBase taxon names} across all {@link NomenclaturalCode nomenclatural codes}
38
 * for bacteria (ICNB), viruses (ICVCN), plants and fungi (ICBN),
39
 * cultivars (ICNCP) and animals (ICZN).
40
 * <P>
41
 * A standard (ordered) list of taxonomical rank instances will be automatically
42
 * created as the project starts. But this class allows to extend this standard
43
 * list by creating new instances of additional taxonomical ranks if needed. 
44
 * <P>
45
 * This class corresponds to: <ul>
46
 * <li> TaxonRankTerm according to the TDWG ontology
47
 * <li> TaxonomicRankEnum according to the TCS
48
 * <li> Rank according to the ABCD schema
49
 * </ul>
50
 * 
51
 * @author m.doering
52
 * @version 1.0
53
 * @created 08-Nov-2007 13:06:46
54
 */
55
@XmlAccessorType(XmlAccessType.FIELD)
56
@XmlType(name = "Rank")
57
@Entity
58
@Indexed(index = "eu.etaxonomy.cdm.model.common.DefinedTermBase")
59
@Audited
60
public class Rank extends OrderedTermBase<Rank> {
61
	private static final long serialVersionUID = -8648081681348758485L;
62
	private static final Logger logger = Logger.getLogger(Rank.class);
63
	
64
	private static final UUID uuidEmpire = UUID.fromString("ac470211-1586-4b24-95ca-1038050b618d");
65
	private static final UUID uuidDomain = UUID.fromString("ffca6ec8-8b88-417b-a6a0-f7c992aac19b");
66
	private static final UUID uuidSuperkingdom = UUID.fromString("64223610-7625-4cfd-83ad-b797bf7f0edd");
67
	private static final UUID uuidKingdom = UUID.fromString("fbe7109d-66b3-498c-a697-c6c49c686162");
68
	private static final UUID uuidSubkingdom = UUID.fromString("a71bd9d8-f3ab-4083-afb5-d89315d71655");
69
	private static final UUID uuidInfrakingdom = UUID.fromString("1e37930c-86cf-44f6-90fd-7822928df260");
70
	private static final UUID uuidSuperphylum = UUID.fromString("0d0cecb1-e254-4607-b210-6801e7ecbb04");
71
	private static final UUID uuidPhylum = UUID.fromString("773430d2-76b4-438c-b817-97a543a33287");
72
	private static final UUID uuidSubphylum = UUID.fromString("23a9b6ff-9408-49c9-bd9e-7a2ca5ab4725");
73
	private static final UUID uuidInfraphylum = UUID.fromString("1701de3a-7693-42a5-a2d3-42697f944190");
74
	private static final UUID uuidSuperdivision = UUID.fromString("a735a48f-4fc8-49a7-ae0c-6a984f658131");
75
	private static final UUID uuidDivision = UUID.fromString("7e56f5cc-123a-4fd1-8cbb-6fd80358b581");
76
	private static final UUID uuidSubdivision = UUID.fromString("931c840f-7a6b-4d76-ad38-bfdd77d7b2e8");
77
	private static final UUID uuidInfradivision = UUID.fromString("c0ede273-be52-4dee-b411-66ee08d30c94");
78
	private static final UUID uuidSuperclass = UUID.fromString("e65b4e1a-21ec-428d-9b9f-e87721ab967c");
79
	private static final UUID uuidClass = UUID.fromString("f23d14c4-1d34-4ee6-8b4e-eee2eb9a3daf");
80
	private static final UUID uuidSubclass = UUID.fromString("8cb26733-e2f5-46cb-ab5c-f99254f877aa");
81
	private static final UUID uuidInfraclass = UUID.fromString("ad23cfda-879a-4021-8629-c54d27caf717");
82
	private static final UUID uuidSuperorder = UUID.fromString("c8c67a22-301a-4219-b882-4a49121232ff");
83
	private static final UUID uuidOrder = UUID.fromString("b0785a65-c1c1-4eb4-88c7-dbd3df5aaad1");
84
	private static final UUID uuidSuborder = UUID.fromString("768ad378-fa85-42ab-b668-763225832f57");
85
	private static final UUID uuidInfraorder = UUID.fromString("84099182-a6f5-47d7-8586-33c9e9955a10");
86
	private static final UUID uuidSectionZoology = UUID.fromString("691d371e-10d7-43f0-93db-3d7fa1a62c54");
87
	private static final UUID uuidSubsectionZoology = UUID.fromString("0ed32d28-adc4-4303-a9ca-68e2acd67e33");
88
	private static final UUID uuidSuperfamily = UUID.fromString("2cfa510a-dcea-4a03-b66a-b1528f9b0796");
89
	private static final UUID uuidFamily = UUID.fromString("af5f2481-3192-403f-ae65-7c957a0f02b6");
90
	private static final UUID uuidSubfamily = UUID.fromString("862526ee-7592-4760-a23a-4ff3641541c5");
91
	private static final UUID uuidInfrafamily = UUID.fromString("c3f2e3bb-6eef-4a26-9fb7-b14f4c8c5e4f");
92
	private static final UUID uuidSupertribe = UUID.fromString("11e94828-8c61-499b-87d6-1de35ce2c51c");
93
	private static final UUID uuidTribe = UUID.fromString("4aa6890b-0363-4899-8d7c-ee0cb78e6166");
94
	private static final UUID uuidSubtribe = UUID.fromString("ae41ecc5-5165-4126-9d24-79939ae5d822");
95
	private static final UUID uuidInfratribe = UUID.fromString("1ec02e8f-f2b7-4c65-af9f-b436b34c79a3");
96
	private static final UUID uuidSupragenericTaxon = UUID.fromString("1fdc0b93-c354-441a-8406-091e0303ff5c");
97
	private static final UUID uuidGenus = UUID.fromString("1b11c34c-48a8-4efa-98d5-84f7f66ef43a");
98
	private static final UUID uuidSubgenus = UUID.fromString("78786e16-2a70-48af-a608-494023b91904");
99
	private static final UUID uuidInfragenus = UUID.fromString("a9972969-82cd-4d54-b693-a096422f13fa");
100
	private static final UUID uuidSectionBotany = UUID.fromString("3edff68f-8527-49b5-bf91-7e4398bb975c");
101
	private static final UUID uuidSubsectionBotany = UUID.fromString("d20f5b61-d463-4448-8f8a-c1ff1f262f59");
102
	private static final UUID uuidSeries = UUID.fromString("d7381ecf-48f8-429b-9c54-f461656978cd");
103
	private static final UUID uuidSubseries = UUID.fromString("80c9a263-f4db-4a13-b6c2-b7fec1aa1200");
104
	private static final UUID uuidSpeciesAggregate = UUID.fromString("1ecae058-4217-4f75-9c27-6d8ba099ac7a");
105
	private static final UUID uuidSpeciesGroup = UUID.fromString("d1988a11-292b-46fa-8fb7-bc64ea6d8fc6");
106
	private static final UUID uuidInfragenericTaxon = UUID.fromString("41bcc6ac-37d3-4fd4-bb80-3cc5b04298b9");
107
	private static final UUID uuidSpecies = UUID.fromString("b301f787-f319-4ccc-a10f-b4ed3b99a86d");
108
	private static final UUID uuidSubspecificAggregate = UUID.fromString("72c248b9-027d-4402-b375-dd4f0850c9ad");
109
	private static final UUID uuidSubspecies = UUID.fromString("462a7819-8b00-4190-8313-88b5be81fad5");
110
	private static final UUID uuidInfraspecies = UUID.fromString("f28ebc9e-bd50-4194-9af1-42f5cb971a2c");
111
	private static final UUID uuidNatio = UUID.fromString("965f2f38-7f97-4270-ab5a-1999bf050a22");
112
	private static final UUID uuidVariety = UUID.fromString("d5feb6a5-af5c-45ef-9878-bb4f36aaf490");
113
	private static final UUID uuidBioVariety = UUID.fromString("a3a364cb-1a92-43fc-a717-3c44980a0991");
114
	private static final UUID uuidPathoVariety = UUID.fromString("2f4f4303-a099-47e3-9048-d749d735423b");
115
	private static final UUID uuidSubvariety = UUID.fromString("9a83862a-7aee-480c-a98d-4bceaf8712ca");
116
	private static final UUID uuidSubsubvariety = UUID.fromString("bff22f84-553a-4429-a4e7-c4b3796c3a18");
117
	private static final UUID uuidConvar = UUID.fromString("2cc740c9-cebb-43c8-9b06-1bef79e6a56a");
118
	private static final UUID uuidForm = UUID.fromString("0461281e-458a-47b9-8d41-19a3d39356d5");
119
	private static final UUID uuidSpecialForm = UUID.fromString("bed20aee-2f5a-4635-9c02-eff06246d067");
120
	private static final UUID uuidSubform = UUID.fromString("47cfc5b0-0fb7-4ceb-b61d-e1dd8de8b569");
121
	private static final UUID uuidSubsubform = UUID.fromString("1c8ac389-4349-4ae0-87be-7239f6635068");
122
	private static final UUID uuidInfraspecificTaxon = UUID.fromString("eb75c27d-e154-4570-9d96-227b2df60474");
123
	private static final UUID uuidCandidate = UUID.fromString("ead9a1f5-dfd4-4de2-9121-70a47accb10b");
124
	private static final UUID uuidDenominationClass = UUID.fromString("49bdf74a-2170-40ed-8be2-887a0db517bf");
125
	private static final UUID uuidGrex = UUID.fromString("08dcb4ff-ac58-48a3-93af-efb3d836ac84");
126
	private static final UUID uuidGraftChimaera = UUID.fromString("6b4063bc-f934-4796-9bf3-0ef3aea5c1cb");
127
	private static final UUID uuidCultivarGroup = UUID.fromString("d763e7d3-e7de-4bb1-9d75-225ca6948659");
128
	private static final UUID uuidCultivar = UUID.fromString("5e98415b-dc6e-440b-95d6-ea33dbb39ad0");
129
	private static final UUID uuidUnknownRank = UUID.fromString("5c4d6755-2cf6-44ca-9220-cccf8881700b");
130
	private static final UUID uuidUnranked = UUID.fromString("a965befb-70a9-4747-a18f-624456c65223");
131
	
132
	private static Map<String, UUID> abbrevMap = null;
133
	private static Map<String, UUID> labelMap = null;
134

    
135
	protected static Map<UUID, Rank> termMap = null;		
136

    
137
	
138
// ********************* CONSTRUCTORS ************************************+/	
139
	/** 
140
	 * Class constructor: creates a new empty rank instance.
141
	 * 
142
	 * @see 	#Rank(String, String, String)
143
	 */
144
	public Rank() {
145
	}
146

    
147
	/** 
148
	 * Class constructor: creates an additional rank instance with a description
149
	 * (in the {@link eu.etaxonomy.cdm.model.common.Language#DEFAULT() default language}), a label and a label abbreviation.
150
	 * 
151
	 * @param	term  		 the string (in the default language) describing the
152
	 * 						 new rank to be created 
153
	 * @param	label  		 the string identifying the new rank to be created
154
	 * @param	labelAbbrev  the string identifying (in abbreviated form) the
155
	 * 						 new rank to be created
156
	 * @see 	#Rank()
157
	 */
158
	public Rank(String term, String label, String labelAbbrev) {
159
		super(term, label, labelAbbrev);
160
	}
161

    
162
	/** 
163
	 * Creates a new empty rank.
164
	 * 
165
	 * @see #NewInstance(String, String, String)
166
	 */
167
	private static Rank NewInstance(){
168
		return new Rank();
169
	}
170
	
171
	/** 
172
	 * Creates an additional rank with a description (in the {@link Language#DEFAULT() default language}),
173
	 * a label and a label abbreviation.
174
	 * 
175
	 * @param	term  		 the string (in the default language) describing the
176
	 * 						 new rank to be created 
177
	 * @param	label  		 the string identifying the new rank to be created
178
	 * @param	labelAbbrev  the string identifying (in abbreviated form) the
179
	 * 						 new rank to be created
180
	 * @see 				 #NewInstance()
181
	 */
182
	private static Rank NewInstance(String term, String label, String labelAbbrev){
183
		return new Rank(term, label, labelAbbrev);
184
	}
185

    
186
//********* METHODS **************************************/
187
	
188
	/* (non-Javadoc)
189
	 * @see eu.etaxonomy.cdm.model.common.DefinedTermBase#resetTerms()
190
	 */
191
	@Override
192
	public void resetTerms(){
193
		termMap = null;
194
	}
195

    
196
	
197
	
198
	protected static Rank getTermByUuid(UUID uuid){
199
		if (termMap == null){
200
			return null;  //better return null then initialize the termMap in an unwanted way 
201
		}
202
		return (Rank)termMap.get(uuid);
203
	}
204
	
205
	public static final Rank EMPIRE(){
206
	  return getTermByUuid(uuidEmpire);
207
	}
208
	public static final Rank DOMAIN(){
209
		  return getTermByUuid(uuidDomain);	
210
	}
211
	public static final Rank SUPERKINGDOM(){
212
		return getTermByUuid(uuidSuperkingdom);
213
	}
214
	public static final Rank KINGDOM(){
215
		return getTermByUuid(uuidKingdom);
216
	}
217
	public static final Rank SUBKINGDOM(){
218
		return getTermByUuid(uuidSubkingdom);
219
	}
220
	public static final Rank INFRAKINGDOM(){
221
		return getTermByUuid(uuidInfrakingdom);
222
	}
223
	public static final Rank SUPERPHYLUM(){
224
		return getTermByUuid(uuidSuperphylum);
225
	}
226
	public static final Rank PHYLUM(){
227
		return getTermByUuid(uuidPhylum);
228
	}
229
	public static final Rank SUBPHYLUM(){
230
		return getTermByUuid(uuidSubphylum);
231
	}
232
	public static final Rank INFRAPHYLUM(){
233
		return getTermByUuid(uuidInfraphylum);
234
	}
235
	public static final Rank SUPERDIVISION(){
236
		return getTermByUuid(uuidSuperdivision);
237
	}
238
	public static final Rank DIVISION(){
239
		return getTermByUuid(uuidDivision);
240
	}
241
	public static final Rank SUBDIVISION(){
242
		return getTermByUuid(uuidSubdivision);
243
	}
244
	public static final Rank INFRADIVISION(){
245
		return getTermByUuid(uuidInfradivision);
246
	}
247
	public static final Rank SUPERCLASS(){
248
		return getTermByUuid(uuidSuperclass);
249
	}
250
	public static final Rank CLASS(){
251
		return getTermByUuid(uuidClass);
252
	}
253
	public static final Rank SUBCLASS(){
254
		return getTermByUuid(uuidSubclass);
255
	}
256
	public static final Rank INFRACLASS(){
257
		return getTermByUuid(uuidInfraclass);
258
	}
259
	public static final Rank SUPERORDER(){
260
		return getTermByUuid(uuidSuperorder);
261
	}
262
	public static final Rank ORDER(){
263
		return getTermByUuid(uuidOrder);
264
	}
265
	public static final Rank SUBORDER(){
266
		return getTermByUuid(uuidSuborder);
267
	}
268
	public static final Rank INFRAORDER(){
269
		return getTermByUuid(uuidInfraorder);
270
	}
271
	public static final Rank SUPERFAMILY(){
272
		return getTermByUuid(uuidSuperfamily);
273
	}
274
	public static final Rank FAMILY(){
275
		return getTermByUuid(uuidFamily);
276
	}
277
	public static final Rank SUBFAMILY(){
278
		return getTermByUuid(uuidSubfamily);
279
	}
280
	public static final Rank INFRAFAMILY(){
281
		return getTermByUuid(uuidInfrafamily);
282
	}
283
	public static final Rank SUPERTRIBE(){
284
		return getTermByUuid(uuidSupertribe);
285
	}
286
	public static final Rank TRIBE(){
287
		return getTermByUuid(uuidTribe);
288
	}
289
	public static final Rank SUBTRIBE(){
290
		return getTermByUuid(uuidSubtribe);
291
	}
292
	public static final Rank INFRATRIBE(){
293
		return getTermByUuid(uuidInfratribe);
294
	}
295
	public static final Rank SUPRAGENERICTAXON(){
296
		return getTermByUuid(uuidSupragenericTaxon);
297
	}
298
	public static final Rank GENUS(){
299
		return getTermByUuid(uuidGenus);
300
	}
301
	public static final Rank SUBGENUS(){
302
		return getTermByUuid(uuidSubgenus);
303
	}
304
	public static final Rank INFRAGENUS(){
305
		return getTermByUuid(uuidInfragenus);
306
	}
307
	public static final Rank SECTION_BOTANY(){
308
		return getTermByUuid(uuidSectionBotany);
309
	}
310
	public static final Rank SUBSECTION_BOTANY(){
311
		return getTermByUuid(uuidSubsectionBotany);
312
	}
313
	public static final Rank SECTION_ZOOLOGY(){
314
		return getTermByUuid(uuidSectionZoology);
315
	}
316
	public static final Rank SUBSECTION_ZOOLOGY(){
317
		return getTermByUuid(uuidSubsectionZoology);
318
	}
319
	public static final Rank SERIES(){
320
		return getTermByUuid(uuidSeries);
321
	}
322
	public static final Rank SUBSERIES(){
323
		return getTermByUuid(uuidSubseries);
324
	}
325
	public static final Rank SPECIESAGGREGATE(){
326
		return getTermByUuid(uuidSpeciesAggregate);
327
	}
328
	public static final Rank SPECIESGROUP(){
329
		return getTermByUuid(uuidSpeciesGroup);
330
	}
331
	public static final Rank INFRAGENERICTAXON(){
332
		return getTermByUuid(uuidInfragenericTaxon);
333
	}
334
	public static final Rank SPECIES(){
335
		return getTermByUuid(uuidSpecies);
336
	}
337
	public static final Rank SUBSPECIFICAGGREGATE(){
338
		return getTermByUuid(uuidSubspecificAggregate);
339
	}
340
	public static final Rank SUBSPECIES(){
341
		return getTermByUuid(uuidSubspecies);
342
	}
343
	public static final Rank INFRASPECIES(){
344
		return getTermByUuid(uuidInfraspecies);
345
	}
346
	public static final Rank VARIETY(){
347
		return getTermByUuid(uuidVariety);
348
	}
349
	public static final Rank BIOVARIETY(){
350
		return getTermByUuid(uuidBioVariety);
351
	}
352
	public static final Rank PATHOVARIETY(){
353
		return getTermByUuid(uuidPathoVariety);
354
	}
355
	public static final Rank SUBVARIETY(){
356
		return getTermByUuid(uuidSubvariety);
357
	}
358
	public static final Rank SUBSUBVARIETY(){
359
		return getTermByUuid(uuidSubsubvariety );
360
	}
361
	public static final Rank CONVAR(){
362
		return getTermByUuid(uuidConvar);
363
	}
364
	public static final Rank FORM(){
365
		return getTermByUuid(uuidForm);
366
	}
367
	public static final Rank SPECIALFORM(){
368
		return getTermByUuid(uuidSpecialForm);
369
	}
370
	public static final Rank SUBFORM(){
371
		return getTermByUuid(uuidSubform);
372
	}
373
	public static final Rank SUBSUBFORM(){
374
		return getTermByUuid(uuidSubsubform);
375
	}
376
	public static final Rank INFRASPECIFICTAXON(){
377
		return getTermByUuid(uuidInfraspecificTaxon);
378
	}
379
	public static final Rank CANDIDATE(){
380
		return getTermByUuid(uuidCandidate);
381
	}
382
	public static final Rank DENOMINATIONCLASS(){
383
		return getTermByUuid(uuidDenominationClass);
384
	}
385
	public static final Rank GREX(){
386
		return getTermByUuid(uuidGrex);
387
	}
388
	public static final Rank GRAFTCHIMAERA(){
389
		return getTermByUuid(uuidGraftChimaera);
390
	}
391
	public static final Rank CULTIVARGROUP(){
392
		return getTermByUuid(uuidCultivarGroup);
393
	}
394
	public static final Rank CULTIVAR(){
395
		return getTermByUuid(uuidCultivar);
396
	}
397
	public static final Rank UNKNOWN_RANK(){
398
		return getTermByUuid(uuidUnknownRank);
399
	}
400
	public static final Rank NATIO(){
401
		return getTermByUuid(uuidNatio);
402
	}
403
	public static final Rank UNRANKED(){
404
		return getTermByUuid(uuidUnranked);
405
	}
406
	
407
	
408
	/**
409
	 * Returns the boolean value indicating whether <i>this</i> rank is higher than 
410
	 * the genus rank (true) or not (false). Returns false if <i>this</i> rank is null.
411
	 *
412
	 * @see  #isGenus()
413
	 * @see  #isInfraGeneric()
414
	 * @see  #isSpecies()
415
	 * @see  #isInfraSpecific()
416
	 */
417
	@Transient
418
	public boolean isSupraGeneric(){
419
		return (this.isHigher(Rank.GENUS()));
420
	}
421
	
422
	/**
423
	 * Returns the boolean value indicating whether <i>this</i> rank is the genus rank
424
	 * (true) or not (false). Returns false if <i>this</i> rank is null.
425
	 *
426
	 * @see  #isSupraGeneric()
427
	 * @see  #isInfraGeneric()
428
	 * @see  #isSpecies()
429
	 * @see  #isInfraSpecific()
430
	 */
431
	@Transient
432
	public boolean isGenus(){
433
		return (this.equals(Rank.GENUS()));
434
	}
435

    
436
	/**
437
	 * Returns the boolean value indicating whether <i>this</i> rank is higher than the
438
	 * species rank and lower than the genus rank (true) or not (false). Species groups or
439
	 * aggregates are also handled as infrageneric ranks.
440
	 * Returns false if <i>this</i> rank is null.
441
	 *
442
	 * @see  #isSupraGeneric()
443
	 * @see  #isGenus()
444
	 * @see  #isSpeciesAggregate()
445
	 * @see  #isSpecies()
446
	 * @see  #isInfraSpecific()
447
	 */
448
	@Transient
449
	public boolean isInfraGeneric(){
450
		return (this.isLower(Rank.GENUS()) && this.isHigher(Rank.SPECIES()));
451
	}
452

    
453
	/**
454
	 * Returns true if this rank indicates a rank that aggregates species
455
	 * like species aggregates or species groups, false otherwise. This methods 
456
	 * currently returns false for all user defined ranks.
457
	 * @return
458
	 */
459
	@Transient
460
	public boolean isSpeciesAggregate(){
461
		return (this.equals(Rank.SPECIESAGGREGATE()) || (this.isLower(Rank.SPECIESAGGREGATE()) && this.isHigher(Rank.SPECIES())));
462
	}	
463
	
464
	/**
465
	 * Returns the boolean value indicating whether <i>this</i> rank is the species
466
	 * rank (true) or not (false). Returns false if <i>this</i> rank is null.
467
	 *
468
	 * @see  #isSupraGeneric()
469
	 * @see  #isGenus()
470
	 * @see  #isInfraGeneric()
471
	 * @see  #isInfraSpecific()
472
	 */
473
	@Transient
474
	public boolean isSpecies(){
475
		return (this.equals(Rank.SPECIES()));
476
	}
477

    
478
	/**
479
	 * Returns the boolean value indicating whether <i>this</i> rank is lower than the
480
	 * species rank (true) or not (false). Returns false if <i>this</i> rank is null.
481
	 *
482
	 * @see  #isSupraGeneric()
483
	 * @see  #isGenus()
484
	 * @see  #isInfraGeneric()
485
	 * @see  #isSpecies()
486
	 */
487
	@Transient
488
	public boolean isInfraSpecific(){
489
		return (this.isLower(Rank.SPECIES()));
490
	}
491

    
492

    
493
	/**
494
	 * Returns the rank identified through a name (abbreviated or not).
495
	 * Preliminary implementation for BotanicalNameParser.
496
	 * 
497
	 * @param	strRank	the string identifying the rank
498
	 * @return  		the rank
499
	 */
500
	public static Rank getRankByNameOrAbbreviation(String strRank)
501
				throws UnknownCdmTypeException{
502
		return getRankByNameOrAbbreviation(strRank, false);
503
	}
504

    
505
	/**
506
	 * Returns the rank identified through a name (abbreviated or not) for a given nomenclatural code.
507
	 * Preliminary implementation for BotanicalNameParser.
508
	 * 
509
	 * @param	strRank	the string identifying the rank
510
	 * @param   nc      the nomenclatural code
511
	 * @return  		the rank
512
	 */
513
	public static Rank getRankByNameOrAbbreviation(String strRank, NomenclaturalCode nc)
514
				throws UnknownCdmTypeException{
515
		return getRankByNameOrAbbreviation(strRank, nc, false);
516
	}
517
	
518
	// TODO
519
	// Preliminary implementation for BotanicalNameParser.
520
	// not yet complete
521
	/**
522
	 * Returns the rank identified through a name (abbreviated or not).
523
	 * Preliminary implementation for BotanicalNameParser.
524
	 * 
525
	 * @param	strRank	the string identifying the rank
526
	 * @param 	useUnknown 	if true the rank UNKNOWN_RANK is returned if the abbrev is 
527
	 * 			unknown or not yet implemented
528
	 * @return  		the rank
529
	 */
530
	public static Rank getRankByNameOrAbbreviation(String strRank, boolean useUnknown)
531
			throws UnknownCdmTypeException{
532
		try {
533
			return getRankByAbbreviation(strRank);
534
		} catch (UnknownCdmTypeException e) {
535
			return getRankByName(strRank, useUnknown);
536
		}
537
	}
538
	
539
	// TODO
540
	// Preliminary implementation for BotanicalNameParser.
541
	// not yet complete
542
	/**
543
	 * Returns the rank identified through a name (abbreviated or not).
544
	 * Preliminary implementation for BotanicalNameParser.
545
	 * 
546
	 * @param	strRank	the string identifying the rank
547
	 * @param   nc      the nomenclatural code
548
	 * @param 	useUnknown 	if true the rank UNKNOWN_RANK is returned if the abbrev is 
549
	 * 			unknown or not yet implemented
550
	 * @return  		the rank
551
	 */
552
	public static Rank getRankByNameOrAbbreviation(String strRank, NomenclaturalCode nc, boolean useUnknown)
553
			throws UnknownCdmTypeException{
554
		try {
555
			return getRankByAbbreviation(strRank, nc);
556
		} catch (UnknownCdmTypeException e) {
557
			return getRankByName(strRank, nc, useUnknown);
558
		}
559
	}
560
	
561
	/**
562
	 * Returns the rank identified through an abbreviated name.
563
	 * Preliminary implementation for BotanicalNameParser.
564
	 * 
565
	 * @param	abbrev	the string for the name abbreviation
566
	 * @return  		the rank
567
	 */
568
	public static Rank getRankByAbbreviation(String abbrev) 
569
						throws UnknownCdmTypeException{
570
		return getRankByAbbreviation(abbrev, false);
571
	}
572
	
573
	/**
574
	 * Returns the rank identified through an abbreviated name for a given nomenclatural code.
575
	 * See also {@link #getRankByAbbreviation(String, boolean)}
576
	 * 
577
	 * @param	abbrev	the string for the name abbreviation
578
	 * @param	nc	    the nomenclatural code
579
	 * @return  		the rank
580
	 */
581
	public static Rank getRankByAbbreviation(String abbrev, NomenclaturalCode nc) throws UnknownCdmTypeException{
582
		return getRankByAbbreviation(abbrev, nc, false);
583
	}
584
	
585
	// TODO
586
	// Preliminary implementation for BotanicalNameParser.
587
	// not yet complete
588
	/**
589
	 * Returns the rank identified through an abbreviated representation.
590
	 * At the moment it uses the English abbreviations (being Latin because 
591
	 * we do not have Latin representations yet.
592
	 * TODO
593
	 * If no according abbreviation is available it throws either an UnknownCdmTypeException
594
	 * or an #Rank.UNKNOWN() object depending on the useUnknown flag. 
595
	 * 
596
	 * @param	abbrev		the string for the name abbreviation
597
	 * @param 	useUnknown 	if true the rank UNKNOWN_RANK is returned if the abbrev is 
598
	 * 			unknown or not yet existent
599
	 * @return  the rank
600
	 */
601
	public static Rank getRankByAbbreviation(String abbrev, boolean useUnknown) throws UnknownCdmTypeException{
602
		Rank result = null;
603
		if (abbrev == null){ 
604
			throw new NullPointerException("Abbrev is NULL in getRankByAbbreviation");
605
		}
606
		if (abbrev.trim().equals("")){
607
			//handle empty abbrev as unknown
608
			abbrev = "oija?m??";
609
		}
610
		if (abbrevMap == null){
611
			return null;
612
		}
613
		UUID uuid = abbrevMap.get(abbrev);
614
		if (uuid != null ){
615
			result = getTermByUuid(uuid);
616
		}
617
		if (result != null){
618
			return result;
619
		}else { 
620
			if (abbrev == null){
621
				abbrev = "(null)";
622
			}
623
			if (useUnknown){
624
				logger.info("Unknown rank name: " + abbrev + ". Rank 'UNKNOWN_RANK' created instead");
625
				return Rank.UNKNOWN_RANK();
626
			}else{
627
				throw new UnknownCdmTypeException("Unknown rank abbreviation: " + abbrev);
628
			}
629
		}
630
	}
631
	
632
	// TODO
633
	// Preliminary implementation to cover Botany and Zoology.
634
	/**
635
	 * Returns the rank identified through an abbreviated name for a given nomenclatural code.
636
	 * Preliminary implementation for ICBN and ICZN.
637
	 * See also {@link #getRankByAbbreviation(String, boolean)}
638

    
639
	 * 
640
	 * @param	abbrev		the string for the name abbreviation
641
	 * @param	nc	        the nomenclatural code
642
	 * @param 	useUnknown 	if true the rank UNKNOWN_RANK is returned if the abbrev is 
643
	 * 			unknown or not yet implemented
644
	 * @return  the rank
645
	 */
646
	public static Rank getRankByAbbreviation(String abbrev, NomenclaturalCode nc,  boolean useUnknown) 
647
	throws UnknownCdmTypeException{
648

    
649
		if (nc.equals(NomenclaturalCode.ICZN)) {
650
			if (abbrev.equalsIgnoreCase("sect.")) { return Rank.SECTION_ZOOLOGY();
651
			} else if (abbrev.equalsIgnoreCase("subsect.")) { return Rank.SUBSECTION_ZOOLOGY();
652
			}
653
		}
654
		return getRankByAbbreviation(abbrev, useUnknown);
655
	}
656
	
657
	// TODO
658
	// Preliminary implementation for BotanicalNameParser.
659
	// not yet complete
660
	/**
661
	 * Returns the rank identified through a name.
662
	 * Preliminary implementation for BotanicalNameParser.
663
	 * 
664
	 * @param	rankName	the string for the name of the rank
665
	 * @return  			the rank
666
	 */
667
	public static Rank getRankByName(String rankName) throws UnknownCdmTypeException{
668
		return getRankByName(rankName, false);
669
	}
670
	
671

    
672
	// TODO
673
	// Preliminary implementation for ICBN and ICZN.
674
	// not yet complete
675
	/**
676
	 * Returns the rank identified through a name for a given nomenclatural code.
677
	 * Preliminary implementation for ICBN and ICZN.
678
	 * 
679
	 * @param	rankName	the string for the name of the rank
680
	 * @param	nc	        the nomenclatural code
681
	 * @return  			the rank
682
	 */
683
	public static Rank getRankByName(String rankName, NomenclaturalCode nc) throws UnknownCdmTypeException{
684
		return getRankByName(rankName, nc, false);
685
	}
686

    
687
	/**
688
	 * Returns the rank identified through a name.
689
	 * Preliminary implementation for BotanicalNameParser.
690
	 * TODO At the moment we do not have Latin representations yet.
691
	 * 
692
	 * @param	rankName	the string for the name of the rank
693
	 * @param 	useUnknown 	if true the rank UNKNOWN_RANK is returned if the rank name is 
694
	 * 			unknown or not yet implemented
695
	 * @return  			the rank
696
	 */
697
	public static Rank getRankByName(String rankName, boolean useUnknown)
698
			throws UnknownCdmTypeException{
699
		if (rankName.equalsIgnoreCase("Regnum")){ return Rank.KINGDOM();
700
		}else if (rankName.equalsIgnoreCase("Subregnum")){ return Rank.SUBKINGDOM();
701
		}else if (rankName.equalsIgnoreCase("Phylum")){ return Rank.PHYLUM();
702
		}else if (rankName.equalsIgnoreCase("Subphylum")){ return Rank.SUBPHYLUM();
703
		}else if (rankName.equalsIgnoreCase("Divisio")){ return Rank.DIVISION();
704
		}else if (rankName.equalsIgnoreCase("Subdivisio")){ return Rank.SUBDIVISION();
705
		}else if (rankName.equalsIgnoreCase("Classis")){ return Rank.CLASS();
706
		}else if (rankName.equalsIgnoreCase("Subclassis")){ return Rank.SUBCLASS();
707
		}else if (rankName.equalsIgnoreCase("Superordo")){ return Rank.SUPERORDER();
708
		}else if (rankName.equalsIgnoreCase("Ordo")){ return Rank.ORDER();
709
		}else if (rankName.equalsIgnoreCase("Subordo")){ return Rank.SUBORDER();
710
		}else if (rankName.equalsIgnoreCase("Familia")){ return Rank.FAMILY();
711
		}else if (rankName.equalsIgnoreCase("Subfamilia")){ return Rank.SUBFAMILY();
712
		}else if (rankName.equalsIgnoreCase("Tribus")){ return Rank.TRIBE();
713
		}else if (rankName.equalsIgnoreCase("Subtribus")){ return Rank.SUBTRIBE();
714
		}else if (rankName.equalsIgnoreCase("Genus")){ return Rank.GENUS();
715
		}else if (rankName.equalsIgnoreCase("Subgenus")){ return Rank.SUBGENUS();
716
		}else if (rankName.equalsIgnoreCase("Sectio")){ return Rank.SECTION_BOTANY();
717
		}else if (rankName.equalsIgnoreCase("Subsectio")){ return Rank.SUBSECTION_BOTANY();
718
		}else if (rankName.equalsIgnoreCase("Series")){ return Rank.SERIES();
719
		}else if (rankName.equalsIgnoreCase("Subseries")){ return Rank.SUBSERIES();
720
		}else if (rankName.equalsIgnoreCase("Aggregate")){ return Rank.SPECIESAGGREGATE();
721
		}else if (rankName.equalsIgnoreCase("Speciesgroup")){ return Rank.SPECIESGROUP();
722
		}else if (rankName.equalsIgnoreCase("Species")){ return Rank.SPECIES();
723
		}else if (rankName.equalsIgnoreCase("Subspecies")){ return Rank.SUBSPECIES();
724
		}else if (rankName.equalsIgnoreCase("Convarietas")){ return Rank.CONVAR();
725
		}else if (rankName.equalsIgnoreCase("Varietas")){ return Rank.VARIETY();
726
		}else if (rankName.equalsIgnoreCase("Subvarietas")){ return Rank.SUBVARIETY();
727
		}else if (rankName.equalsIgnoreCase("Forma")){ return Rank.FORM();
728
		}else if (rankName.equalsIgnoreCase("Subforma")){ return Rank.SUBFORM();
729
		}else if (rankName.equalsIgnoreCase("Forma spec.")){ return Rank.SPECIALFORM();
730
		}else if (rankName.equalsIgnoreCase("tax.infragen.")){ return Rank.INFRAGENERICTAXON();
731
		}else if (rankName.equalsIgnoreCase("tax.infrasp.")){ return Rank.INFRASPECIFICTAXON();
732
		// old ranks 
733
		}else if (rankName.equalsIgnoreCase("proles")){ return Rank.INFRASPECIFICTAXON(); //to create the name put prol. and the infraspeciesepi to the field unnamed namephrase
734
		}else if (rankName.equalsIgnoreCase("race")){ return Rank.INFRASPECIFICTAXON(); //to create the name put prol. and the infraspeciesepi to the field unnamed namephrase
735
		}else if (rankName.equalsIgnoreCase("taxon")){ return Rank.INFRASPECIFICTAXON(); //to create the name put prol. and the infraspeciesepi to the field unnamed namephrase
736
		}else if (rankName.equalsIgnoreCase("sublusus")){ return Rank.INFRASPECIFICTAXON(); //to create the name put prol. and the infraspeciesepi to the field unnamed namephrase
737
		
738
		}else{ 
739
			if (rankName == null){
740
				rankName = "(null)";
741
			}
742
			if (useUnknown){
743
				logger.info("Unknown rank name: " + rankName+". Rank 'UNKNOWN_RANK' created instead");
744
				return Rank.UNKNOWN_RANK();
745
			}else{
746
				if (rankName == null){
747
					rankName = "(null)";
748
				}
749
				throw new UnknownCdmTypeException("Unknown rank name: " + rankName);
750
			}
751
		}
752
	}
753

    
754
	public static Rank getRankByEnglishName(String rankName, NomenclaturalCode nc, boolean useUnknown) throws UnknownCdmTypeException{
755
		Rank result = null;
756
		if (rankName == null){ 
757
			throw new NullPointerException("Abbrev is NULL in getRankByAbbreviation");
758
		}
759
		if (labelMap == null){
760
			return null;
761
		}
762
		//handle section and subsection (not unique representations)
763
		if (rankName.equalsIgnoreCase("Section")){ 
764
			if (nc != null && nc.equals(NomenclaturalCode.ICZN)){	return Rank.SECTION_ZOOLOGY();
765
			}else if (nc != null && nc.equals(NomenclaturalCode.ICBN)){return Rank.SECTION_BOTANY();
766
			}else{
767
				String errorWarning = "Section is only defined for ICZN and ICBN at the moment but here needed for " + ((nc == null)? "(null)": nc.toString());
768
				logger.warn(errorWarning);
769
				throw new UnknownCdmTypeException (errorWarning);
770
			}
771
		}else if (rankName.equalsIgnoreCase("Subsection")){ 
772
			if (nc != null && nc.equals(NomenclaturalCode.ICZN)){ return Rank.SECTION_ZOOLOGY();
773
			}else if (nc != null && nc.equals(NomenclaturalCode.ICBN)){ return Rank.SECTION_BOTANY();
774
			}else{
775
				String errorWarning = "Subsection is only defined for ICZN and ICBN at the moment but here needed for " + ((nc == null)? "(null)": nc.toString());
776
				logger.warn(errorWarning);
777
				throw new UnknownCdmTypeException (errorWarning);
778
			}
779
		}
780
		
781
		rankName = rankName.toLowerCase();
782
		
783
		UUID uuid = labelMap.get(rankName);
784
		if (uuid != null ){
785
			result = getTermByUuid(uuid);
786
		}
787
		if (result != null){
788
			return result;
789
		}else { 
790
			if (rankName == null){
791
				rankName = "(null)";
792
			}
793
			if (useUnknown){
794
				logger.info("Unknown rank name: " + rankName + ". Rank 'UNKNOWN_RANK' created instead");
795
				return Rank.UNKNOWN_RANK();
796
			}else{
797
				throw new UnknownCdmTypeException("Unknown rank: " + rankName);
798
			}
799
		}
800
	}
801

    
802
	
803
	public static Rank getRankByName(String rankName, NomenclaturalCode nc, boolean useUnknown)
804
		throws UnknownCdmTypeException {
805
		
806
		if (nc.equals(NomenclaturalCode.ICZN)) {
807
			if (rankName.equalsIgnoreCase("Sectio")) { return Rank.SECTION_ZOOLOGY();
808
			}else if (rankName.equalsIgnoreCase("Subsectio")) { return Rank.SUBSECTION_ZOOLOGY();
809
			}
810
		}
811
		return getRankByName(rankName, useUnknown);
812
	}
813
	
814
	/**
815
	 * Returns the abbreviated rank name for <i>this</i> rank according to the English representation
816
	 * abbreviated label. 
817
	 * TODO Needs to be changed to Latin as soon as Latin representations are available.
818
	 * 
819
	 * @return	the abbreviation string for <i>this</i> rank
820
	 */
821
	public String getAbbreviation(){
822
		Language language = Language.ENGLISH();
823
		String result = this.getRepresentation(language).getAbbreviatedLabel();
824
		if (result== null) {
825
			logger.warn("Abbreviation for this Rank " + this.toString() +  " not yet implemented");
826
			return "no abbreviation available.";
827
		}else{
828
			return result;
829
		}
830
	}
831
	@Transient
832
	public String getInfraGenericMarker() throws UnknownCdmTypeException{
833
		String result = null;
834
		if (! this.isInfraGeneric()){
835
			throw new IllegalStateException("An infrageneric marker is only available for a infrageneric rank but was asked for rank: " + this.toString());
836
		}else{
837
			result = this.getAbbreviation();
838
		}
839
		if (result == null){
840
			throw new UnknownCdmTypeException("Abbreviation for rank unknown: " + this.toString());
841
		}
842
		return result;
843
	}
844
	
845
	
846

    
847
	@Override
848
	public Rank readCsvLine(Class<Rank> termClass, List<String> csvLine, Map<UUID, DefinedTermBase> terms) {
849
		return super.readCsvLine(termClass, csvLine, terms);
850
	}
851

    
852
	@Override
853
	protected void setDefaultTerms(TermVocabulary<Rank> termVocabulary) {
854
		termMap = new HashMap<UUID, Rank>();
855
		for (Rank term : termVocabulary.getTerms()){
856
			termMap.put(term.getUuid(), (Rank)term);
857
			addRank(term);
858
		}
859
	}
860

    
861
	/**
862
	 * @param term
863
	 */
864
	private void addRank(Rank rank) {
865
		if (rank == null){
866
			logger.warn("rank is NULL");
867
			return;
868
		}
869
		if (rank.getUuid().equals(uuidSectionZoology) || rank.getUuid().equals(uuidSubsectionZoology )){
870
			//sect./subsect. is used for botanical sections, see also #getRankByAbbreviation(String, NomenclaturalCode, boolean)
871
			return;
872
		}
873
		Language lang = Language.DEFAULT();  //TODO should be Latin but at the moment we have only English representations 
874
		Representation representation = rank.getRepresentation(lang);
875
		String abbrevLabel = representation.getAbbreviatedLabel();
876
		String label = representation.getLabel();
877
		if (abbrevLabel == null){
878
			logger.warn("label is NULL");
879
			return;
880
		}
881
		//initialize maps
882
		if (abbrevMap == null){
883
			abbrevMap = new HashMap<String, UUID>();
884
		}
885
		if (labelMap == null){
886
			labelMap = new HashMap<String, UUID>();
887
		}
888
		//add to map
889
		abbrevMap.put(abbrevLabel, rank.getUuid());
890
		labelMap.put(label.toLowerCase(), rank.getUuid());	
891
	}
892

    
893
}
(16-16/26)