Merge branch 'release/5.44.0'
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / description / State.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9
10 package eu.etaxonomy.cdm.model.description;
11
12
13 import java.util.HashMap;
14 import java.util.Map;
15 import java.util.UUID;
16
17 import javax.persistence.Entity;
18 import javax.xml.bind.annotation.XmlAccessType;
19 import javax.xml.bind.annotation.XmlAccessorType;
20 import javax.xml.bind.annotation.XmlRootElement;
21 import javax.xml.bind.annotation.XmlType;
22
23 import org.apache.logging.log4j.LogManager;
24 import org.apache.logging.log4j.Logger;
25 import org.hibernate.envers.Audited;
26
27 import eu.etaxonomy.cdm.model.common.Language;
28 import eu.etaxonomy.cdm.model.term.DefinedTermBase;
29 import eu.etaxonomy.cdm.model.term.TermType;
30 import eu.etaxonomy.cdm.model.term.TermVocabulary;
31
32 /**
33 * This class represents terms describing different states (like "oval" or
34 * "triangular") for {@link Feature features} that can be described with
35 * categorical values (like for instance shapes).
36 *
37 * @author m.doering
38 * @since 08-Nov-2007 13:06:53
39 */
40 @XmlAccessorType(XmlAccessType.FIELD)
41 @XmlType(name = "State")
42 @XmlRootElement(name = "State")
43 @Entity
44 //@Indexed disabled to reduce clutter in indexes, since this type is not used by any search
45 //@Indexed(index = "eu.etaxonomy.cdm.model.term.DefinedTermBase")
46 @Audited
47 public class State extends DefinedTermBase<State> {
48
49 private static final long serialVersionUID = -4816292463790262516L;
50 @SuppressWarnings("unused")
51 private static final Logger logger = LogManager.getLogger();
52
53 public static final UUID uuidPresent = UUID.fromString("4f90d908-2061-4627-b251-0683c55b9c2e");
54 public static final UUID uuidAbsent = UUID.fromString("f193112f-68b2-4c74-bb82-05791892d2c4");
55
56 protected static Map<UUID, State> termMap = null;
57
58 //********************************** Constructor *******************************************************************/
59
60 //for hibernate use only
61 @Deprecated
62 protected State() {
63 super(TermType.State);
64 }
65
66 /**
67 * Class constructor: creates a new state with a description (in the {@link Language#DEFAULT() default language}),
68 * a label and a label abbreviation.
69 *
70 * @param term the string (in the default language) describing the
71 * new state to be created
72 * @param label the string identifying the new state to be created
73 * @param labelAbbrev the string identifying (in abbreviated form) the
74 * new state to be created
75 * @see #State()
76 */
77 private State(String term, String label, String labelAbbrev) {
78 super(TermType.State, term, label, labelAbbrev);
79 }
80
81 //********* METHODS **************************************/
82 /**
83 * Creates a new empty state.
84 *
85 * @see #NewInstance(String, String, String)
86 */
87 public static State NewInstance(){
88 return new State();
89 }
90
91 /**
92 * Creates a new state with a description (in the {@link Language#DEFAULT() default language}),
93 * a label and a label abbreviation.
94 *
95 * @param term the string (in the default language) describing the
96 * new state to be created
97 * @param label the string identifying the new state to be created
98 * @param labelAbbrev the string identifying (in abbreviated form) the
99 * new state to be created
100 * @see #NewInstance()
101 */
102 public static State NewInstance(String term, String label, String labelAbbrev){
103 return new State(term, label, labelAbbrev);
104 }
105
106 public static State NewInstance(String term, String label, String labelAbbrev, Language language){
107 State result = new State(term, label, labelAbbrev);
108 result.getRepresentations().iterator().next().setLanguage(language);
109 return result;
110 }
111
112 //************************** METHODS ********************************
113
114 @Override
115 public void resetTerms(){
116 termMap = null;
117 }
118
119 @Override
120 protected void setDefaultTerms(TermVocabulary<State> termVocabulary){
121 termMap = new HashMap<>();
122 for (State term : termVocabulary.getTerms()){
123 termMap.put(term.getUuid(), term);
124 }
125 }
126 }