implemented user management, fixes #803. Minor refactorings.
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / model / NameHelper.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9
10 package eu.etaxonomy.taxeditor.model;
11
12 import eu.etaxonomy.cdm.common.CdmUtils;
13 import eu.etaxonomy.cdm.model.name.Rank;
14 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
15 import eu.etaxonomy.cdm.model.taxon.Taxon;
16 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
17
18 /**
19 * @author p.ciardelli
20 * @author n.hoffmann
21 * @created 18.03.2009
22 * @version 1.0
23 */
24 public class NameHelper {
25
26 @SuppressWarnings("unchecked")
27 public static String getDisplayName(TaxonNameBase name){
28 return name.getTitleCache();
29 }
30
31 public static String getDisplayName(TaxonBase<?> taxon){
32 return getDisplayName(taxon.getName());
33 }
34
35 @SuppressWarnings("unchecked")
36 public static String getDisplayNameWithRef(TaxonBase taxonBase) {
37 TaxonNameBase name = taxonBase.getName();
38 if (name != null) {
39 if (name.getFullTitleCache() == null || name.getFullTitleCache().length() == 0) {
40 return CdmUtils.Nz(name.getTitleCache());
41 } else {
42 return name.getFullTitleCache();
43 }
44 }
45 return "";
46 }
47
48 /**
49 * Checks whether name is the basionym for ALL names
50 * in its group.
51 * @param name
52 *
53 * @return
54 */
55 @SuppressWarnings("unchecked")
56 public static boolean isNameGroupBasionym(TaxonNameBase name) {
57 if (name == null) {
58 return false;
59 }
60 return name.isGroupsBasionym();
61 }
62
63
64 /**
65 * @param name
66 * @return
67 */
68 public static boolean isNameSupraSpecific(TaxonNameBase<?, ?> name) {
69 if (name == null || name.getRank() == null) {
70 return false;
71 }
72 return name.getRank().isHigher(Rank.SPECIES());
73 }
74
75 /**
76 * Checks whether name belongs to the same homotypic group as taxon's name.
77 *
78 * @param name
79 * @param taxon
80 * @return
81 */
82 public static boolean isNameHomotypic(TaxonNameBase<?, ?> name, Taxon taxon) {
83 return name.isHomotypic(taxon.getName());
84 }
85
86 }