1 |
8e79f830
|
Andreas Müller
|
/**
|
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 |
|
|
import java.text.ParseException;
|
13 |
|
|
import java.util.HashMap;
|
14 |
|
|
import java.util.List;
|
15 |
|
|
import java.util.Map;
|
16 |
|
|
import java.util.UUID;
|
17 |
|
|
|
18 |
|
|
import javax.persistence.Entity;
|
19 |
|
|
import javax.xml.bind.annotation.XmlAccessType;
|
20 |
|
|
import javax.xml.bind.annotation.XmlAccessorType;
|
21 |
|
|
import javax.xml.bind.annotation.XmlAttribute;
|
22 |
|
|
import javax.xml.bind.annotation.XmlRootElement;
|
23 |
|
|
import javax.xml.bind.annotation.XmlType;
|
24 |
|
|
|
25 |
|
|
import org.apache.commons.lang.StringUtils;
|
26 |
|
|
import org.apache.log4j.Logger;
|
27 |
|
|
import org.hibernate.envers.Audited;
|
28 |
|
|
|
29 |
|
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
30 |
|
|
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
|
31 |
|
|
import eu.etaxonomy.cdm.model.common.Language;
|
32 |
|
|
import eu.etaxonomy.cdm.model.common.OrderedTermBase;
|
33 |
|
|
import eu.etaxonomy.cdm.model.common.TermType;
|
34 |
|
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
35 |
|
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
36 |
|
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
37 |
|
|
|
38 |
|
|
|
39 |
|
|
/**
|
40 |
|
|
* This class represents terms describing the {@link AbsenceTerm absence}
|
41 |
|
|
* (like "extinct") or the {@link PresenceTerm presence} (like "cultivated") of a
|
42 |
|
|
* {@link Taxon taxon} in a {@link NamedArea named area}. These terms are only
|
43 |
|
|
* used for {@link Distribution distributions}.
|
44 |
|
|
|
45 |
|
|
*
|
46 |
|
|
* @author m.doering
|
47 |
|
|
* @version 1.0
|
48 |
|
|
* @created 08-Nov-2007 13:06:44
|
49 |
|
|
* @author a.mueller
|
50 |
|
|
*/
|
51 |
|
|
@XmlAccessorType(XmlAccessType.FIELD)
|
52 |
|
|
@XmlType(name = "PresenceAbsenceTerm")
|
53 |
|
|
@XmlRootElement(name = "PresenceAbsenceTerm")
|
54 |
|
|
@Entity
|
55 |
|
|
//@Indexed disabled to reduce clutter in indexes, since this type is not used by any search
|
56 |
|
|
//@Indexed(index = "eu.etaxonomy.cdm.model.common.DefinedTermBase")
|
57 |
|
|
@Audited
|
58 |
|
|
public class PresenceAbsenceTerm extends OrderedTermBase<PresenceAbsenceTerm> {
|
59 |
|
|
private static final long serialVersionUID = 1036807546935584396L;
|
60 |
|
|
private static final Logger logger = Logger.getLogger(PresenceAbsenceTerm.class);
|
61 |
|
|
|
62 |
|
|
|
63 |
|
|
//presence base
|
64 |
|
|
private static final UUID uuidP=UUID.fromString("cef81d25-501c-48d8-bbea-542ec50de2c2");
|
65 |
|
|
private static final UUID uuidPD=UUID.fromString("75a60279-a4c2-4f53-bc57-466028a4b3db");
|
66 |
|
|
|
67 |
|
|
//presence
|
68 |
|
|
private static final UUID uuidN=UUID.fromString("ddeac4f2-d8fa-43b8-ad7e-ca13abdd32c7");
|
69 |
|
|
private static final UUID uuidNQ=UUID.fromString("925662c1-bb10-459a-8c53-da5a738ac770");
|
70 |
|
|
private static final UUID uuidND=UUID.fromString("310373bf-7df4-4d02-8cb3-bcc7448805fc");
|
71 |
|
|
private static final UUID uuidC=UUID.fromString("9eb99fe6-59e2-4445-8e6a-478365bd0fa9");
|
72 |
196284c8
|
Andreas Müller
|
private static final UUID uuidCQ=UUID.fromString("4f31bfc8-3058-4d83-aea5-3a1fe9773f9f");
|
73 |
8e79f830
|
Andreas Müller
|
private static final UUID uuidI=UUID.fromString("643cf9d1-a5f1-4622-9837-82ef961e880b");
|
74 |
|
|
private static final UUID uuidIQ=UUID.fromString("83eb0aa0-1a45-495a-a3ca-bf6958b74366");
|
75 |
|
|
private static final UUID uuidID=UUID.fromString("0c54761e-4887-4788-9dfa-7190c88746e3");
|
76 |
|
|
private static final UUID uuidIP=UUID.fromString("da159544-b0dd-4599-a9c9-640826af8c17");
|
77 |
|
|
private static final UUID uuidIA=UUID.fromString("42946bd6-9c22-45ad-a910-7427e8f60bfd");
|
78 |
|
|
private static final UUID uuidIN=UUID.fromString("e191e89a-a751-4b0c-b883-7f1de70915c9");
|
79 |
|
|
private static final UUID uuidIC=UUID.fromString("fac8c347-8262-44a1-b0a4-db4de451c021");
|
80 |
|
|
private static final UUID uuidE=UUID.fromString("c3ee7048-15b7-4be1-b687-9ce9c1a669d6");
|
81 |
|
|
private static final UUID uuidNA=UUID.fromString("4e04990a-66fe-4fdf-856c-f40772fbcf0a");
|
82 |
|
|
private static final UUID uuidIV=UUID.fromString("dc536e3d-a753-4bbe-a386-dd8aff35c234");
|
83 |
|
|
|
84 |
|
|
//absence
|
85 |
|
|
private static final UUID uuidAbsence=UUID.fromString("59709861-f7d9-41f9-bb21-92559cedd598");
|
86 |
|
|
private static final UUID uuidReportedInError = UUID.fromString("38604788-cf05-4607-b155-86db456f7680");
|
87 |
|
|
|
88 |
|
|
private static final UUID uuidNF=UUID.fromString("61cee840-801e-41d8-bead-015ad866c2f1");
|
89 |
|
|
private static final UUID uuidIF=UUID.fromString("aeec2947-2700-4623-8e32-9e3a430569d1");
|
90 |
|
|
private static final UUID uuidCF=UUID.fromString("9d4d3431-177a-4abe-8e4b-1558573169d6");
|
91 |
|
|
private static final UUID uuidNE=UUID.fromString("5c397f7b-59ef-4c11-a33c-45691ceda91b");
|
92 |
|
|
private static final UUID uuidIE=UUID.fromString("b74dc30b-ee93-496d-8c00-4d00abae1ec7");
|
93 |
|
|
|
94 |
|
|
|
95 |
|
|
protected static Map<UUID, PresenceAbsenceTerm> termMap = null;
|
96 |
|
|
|
97 |
|
|
private String defaultColor = "000000";
|
98 |
|
|
|
99 |
|
|
@XmlAttribute(name = "absenceTerm")
|
100 |
|
|
private boolean absenceTerm = false;
|
101 |
|
|
|
102 |
|
|
//********* METHODS **************************************/
|
103 |
|
|
/**
|
104 |
|
|
* Creates a new empty presence term.
|
105 |
|
|
*
|
106 |
|
|
* @see #NewInstance(String, String, String)
|
107 |
|
|
*/
|
108 |
|
|
public static PresenceAbsenceTerm NewInstance(){
|
109 |
|
|
return new PresenceAbsenceTerm();
|
110 |
|
|
}
|
111 |
|
|
|
112 |
|
|
/**
|
113 |
|
|
* Creates a new presence term with a description (in the {@link Language#DEFAULT() default language}),
|
114 |
|
|
* a label and a label abbreviation.
|
115 |
|
|
*
|
116 |
|
|
* @param term the string (in the default language) describing the
|
117 |
|
|
* new presence term to be created
|
118 |
|
|
* @param label the string identifying the new presence term to be created
|
119 |
|
|
* @param labelAbbrev the string identifying (in abbreviated form) the
|
120 |
|
|
* new presence term to be created
|
121 |
|
|
* @see #NewInstance()
|
122 |
|
|
*/
|
123 |
|
|
public static PresenceAbsenceTerm NewPresenceInstance(String term, String label, String labelAbbrev){
|
124 |
|
|
return new PresenceAbsenceTerm(term, label, labelAbbrev, false);
|
125 |
|
|
}
|
126 |
|
|
|
127 |
|
|
/**
|
128 |
|
|
* Creates a new absence term with a description (in the {@link Language#DEFAULT() default language}),
|
129 |
|
|
* a label and a label abbreviation.
|
130 |
|
|
*
|
131 |
|
|
* @param term the string (in the default language) describing the
|
132 |
|
|
* new presence term to be created
|
133 |
|
|
* @param label the string identifying the new presence term to be created
|
134 |
|
|
* @param labelAbbrev the string identifying (in abbreviated form) the
|
135 |
|
|
* new presence term to be created
|
136 |
|
|
* @see #NewInstance()
|
137 |
|
|
*/
|
138 |
|
|
public static PresenceAbsenceTerm NewAbsenceInstance(String term, String label, String labelAbbrev){
|
139 |
|
|
return new PresenceAbsenceTerm(term, label, labelAbbrev, true);
|
140 |
|
|
}
|
141 |
|
|
|
142 |
|
|
|
143 |
|
|
//********************************** Constructor *******************************************************************/
|
144 |
|
|
|
145 |
|
|
//for hibernate use only
|
146 |
|
|
@Deprecated
|
147 |
|
|
protected PresenceAbsenceTerm() {
|
148 |
|
|
super(TermType.PresenceAbsenceTerm);
|
149 |
|
|
}
|
150 |
|
|
|
151 |
|
|
/**
|
152 |
|
|
* Class constructor: creates a new presence or absence term with a description
|
153 |
|
|
* (in the {@link Language#DEFAULT() default language}), a label and a label abbreviation.
|
154 |
|
|
*
|
155 |
|
|
* @param term the string (in the default language) describing the
|
156 |
|
|
* new presence or absence term to be created
|
157 |
|
|
* @param label the string identifying the new presence or absence term to be created
|
158 |
|
|
* @param labelAbbrev the string identifying (in abbreviated form) the
|
159 |
|
|
* new presence or absence term to be created
|
160 |
|
|
* @param isAbsenceTerm boolean value indicating if this term represents an absence or not
|
161 |
|
|
* @see #PresenceAbsenceTermBase()
|
162 |
|
|
*/
|
163 |
|
|
protected PresenceAbsenceTerm(String term, String label, String labelAbbrev, boolean isAbsenceTerm) {
|
164 |
|
|
super(TermType.PresenceAbsenceTerm, term, label, labelAbbrev);
|
165 |
|
|
this.setAbsenceTerm(isAbsenceTerm);
|
166 |
|
|
}
|
167 |
|
|
|
168 |
|
|
|
169 |
|
|
//******************************* STATIC METHODS *****************************************
|
170 |
|
|
|
171 |
|
|
protected static PresenceAbsenceTerm getTermByUuid(UUID uuid){
|
172 |
|
|
if (termMap == null || termMap.isEmpty()){
|
173 |
|
|
return getTermByClassAndUUID(PresenceAbsenceTerm.class, uuid);
|
174 |
|
|
} else {
|
175 |
|
|
return termMap.get(uuid);
|
176 |
|
|
}
|
177 |
|
|
}
|
178 |
|
|
|
179 |
|
|
//TODO read from label(abbrevs) like in TDWGArea
|
180 |
|
|
public static PresenceAbsenceTerm getPresenceAbsenceTermByAbbreviation(String abbrev) {
|
181 |
|
|
if (abbrev == null) { throw new NullPointerException("abbrev is 'null' in getPresenceTermByAbbreviation");
|
182 |
|
|
} else if (abbrev.equalsIgnoreCase("c")) { return PresenceAbsenceTerm.CULTIVATED();
|
183 |
|
|
} else if (abbrev.equalsIgnoreCase("e")) { return PresenceAbsenceTerm.ENDEMIC_FOR_THE_RELEVANT_AREA();
|
184 |
|
|
} else if (abbrev.equalsIgnoreCase("i")) { return PresenceAbsenceTerm.INTRODUCED();
|
185 |
|
|
} else if (abbrev.equalsIgnoreCase("ia")) { return PresenceAbsenceTerm.INTRODUCED_ADVENTITIOUS();
|
186 |
|
|
} else if (abbrev.equalsIgnoreCase("ic")) { return PresenceAbsenceTerm.INTRODUCED_CULTIVATED();
|
187 |
|
|
} else if (abbrev.equalsIgnoreCase("id")) { return PresenceAbsenceTerm.INTRODUCED_DOUBTFULLY_INTRODUCED();
|
188 |
|
|
} else if (abbrev.equalsIgnoreCase("in")) { return PresenceAbsenceTerm.INTRODUCED_NATURALIZED();
|
189 |
|
|
} else if (abbrev.equalsIgnoreCase("ip")) { return PresenceAbsenceTerm.INTRODUCED_UNCERTAIN_DEGREE_OF_NATURALISATION();
|
190 |
|
|
} else if (abbrev.equalsIgnoreCase("iq")) { return PresenceAbsenceTerm.INTRODUCED_PRESENCE_QUESTIONABLE();
|
191 |
|
|
} else if (abbrev.equalsIgnoreCase("n")) { return PresenceAbsenceTerm.NATIVE();
|
192 |
|
|
} else if (abbrev.equalsIgnoreCase("nd")) { return PresenceAbsenceTerm.NATIVE_DOUBTFULLY_NATIVE();
|
193 |
|
|
} else if (abbrev.equalsIgnoreCase("nq")) { return PresenceAbsenceTerm.NATIVE_PRESENCE_QUESTIONABLE();
|
194 |
|
|
} else if (abbrev.equalsIgnoreCase("p")) { return PresenceAbsenceTerm.PRESENT();
|
195 |
|
|
} else if (abbrev.equalsIgnoreCase("na")) { return PresenceAbsenceTerm.NATURALISED();
|
196 |
|
|
} else if (abbrev.equalsIgnoreCase("iv")) { return PresenceAbsenceTerm.INVASIVE();
|
197 |
|
|
//absence
|
198 |
|
|
} else if (abbrev.equalsIgnoreCase("cf")) { return PresenceAbsenceTerm.CULTIVATED_REPORTED_IN_ERROR();
|
199 |
|
|
} else if (abbrev.equalsIgnoreCase("if")) { return PresenceAbsenceTerm.INTRODUCED_REPORTED_IN_ERROR();
|
200 |
|
|
} else if (abbrev.equalsIgnoreCase("nf")) { return PresenceAbsenceTerm.NATIVE_REPORTED_IN_ERROR();
|
201 |
|
|
} else if (abbrev.equalsIgnoreCase("ne")) { return PresenceAbsenceTerm.NATIVE_FORMERLY_NATIVE();
|
202 |
|
|
} else if (abbrev.equalsIgnoreCase("ie")) { return PresenceAbsenceTerm.INTRODUCED_FORMERLY_INTRODUCED();
|
203 |
|
|
} else {
|
204 |
|
|
logger.warn("Unknown presence or absence status term abbreviation: " + abbrev);
|
205 |
|
|
return null;
|
206 |
|
|
}
|
207 |
|
|
}
|
208 |
|
|
|
209 |
|
|
|
210 |
|
|
public static final PresenceAbsenceTerm PRESENT(){
|
211 |
|
|
return getTermByUuid(uuidP);
|
212 |
|
|
}
|
213 |
|
|
public static final PresenceAbsenceTerm PRESENT_DOUBTFULLY(){
|
214 |
|
|
return getTermByUuid(uuidPD);
|
215 |
|
|
}
|
216 |
|
|
public static final PresenceAbsenceTerm CULTIVATED(){
|
217 |
|
|
return getTermByUuid(uuidC);
|
218 |
|
|
}
|
219 |
196284c8
|
Andreas Müller
|
public static final PresenceAbsenceTerm CULTIVATED_PRESENCE_QUESTIONABLE(){
|
220 |
|
|
return getTermByUuid(uuidCQ);
|
221 |
|
|
}
|
222 |
8e79f830
|
Andreas Müller
|
public static final PresenceAbsenceTerm ENDEMIC_FOR_THE_RELEVANT_AREA(){
|
223 |
|
|
return getTermByUuid(uuidE);
|
224 |
|
|
}
|
225 |
|
|
public static final PresenceAbsenceTerm INTRODUCED(){
|
226 |
|
|
return getTermByUuid(uuidI);
|
227 |
|
|
}
|
228 |
|
|
public static final PresenceAbsenceTerm INTRODUCED_ADVENTITIOUS(){
|
229 |
|
|
return getTermByUuid(uuidIA);
|
230 |
|
|
}
|
231 |
|
|
|
232 |
|
|
public static final PresenceAbsenceTerm INTRODUCED_CULTIVATED(){
|
233 |
|
|
return getTermByUuid(uuidIC);
|
234 |
|
|
}
|
235 |
|
|
|
236 |
|
|
public static final PresenceAbsenceTerm INTRODUCED_DOUBTFULLY_INTRODUCED(){
|
237 |
|
|
return getTermByUuid(uuidID);
|
238 |
|
|
}
|
239 |
|
|
|
240 |
|
|
public static final PresenceAbsenceTerm INTRODUCED_NATURALIZED(){
|
241 |
|
|
return getTermByUuid(uuidIN);
|
242 |
|
|
}
|
243 |
|
|
|
244 |
|
|
public static final PresenceAbsenceTerm INTRODUCED_PRESENCE_QUESTIONABLE(){
|
245 |
|
|
return getTermByUuid(uuidIQ);
|
246 |
|
|
}
|
247 |
|
|
|
248 |
|
|
public static final PresenceAbsenceTerm INTRODUCED_UNCERTAIN_DEGREE_OF_NATURALISATION(){
|
249 |
|
|
return getTermByUuid(uuidIP);
|
250 |
|
|
}
|
251 |
|
|
|
252 |
|
|
public static final PresenceAbsenceTerm NATIVE(){
|
253 |
|
|
return getTermByUuid(uuidN);
|
254 |
|
|
}
|
255 |
|
|
|
256 |
|
|
public static final PresenceAbsenceTerm NATIVE_DOUBTFULLY_NATIVE(){
|
257 |
|
|
return getTermByUuid(uuidND);
|
258 |
|
|
}
|
259 |
|
|
|
260 |
|
|
public static final PresenceAbsenceTerm NATIVE_PRESENCE_QUESTIONABLE(){
|
261 |
|
|
return getTermByUuid(uuidNQ);
|
262 |
|
|
}
|
263 |
|
|
|
264 |
|
|
public static final PresenceAbsenceTerm INVASIVE(){
|
265 |
|
|
return getTermByUuid(uuidIV);
|
266 |
|
|
}
|
267 |
|
|
|
268 |
|
|
public static final PresenceAbsenceTerm NATURALISED(){
|
269 |
|
|
return getTermByUuid(uuidNA);
|
270 |
|
|
}
|
271 |
|
|
|
272 |
|
|
public static final PresenceAbsenceTerm ABSENT(){
|
273 |
|
|
return getTermByUuid(uuidAbsence);
|
274 |
|
|
}
|
275 |
|
|
|
276 |
|
|
public static final PresenceAbsenceTerm REPORTED_IN_ERROR(){
|
277 |
|
|
return getTermByUuid(uuidReportedInError);
|
278 |
|
|
}
|
279 |
|
|
|
280 |
|
|
public static final PresenceAbsenceTerm NATIVE_REPORTED_IN_ERROR(){
|
281 |
|
|
return getTermByUuid(uuidNF);
|
282 |
|
|
}
|
283 |
|
|
|
284 |
|
|
public static final PresenceAbsenceTerm CULTIVATED_REPORTED_IN_ERROR(){
|
285 |
|
|
return getTermByUuid(uuidCF);
|
286 |
|
|
}
|
287 |
|
|
|
288 |
|
|
public static final PresenceAbsenceTerm INTRODUCED_REPORTED_IN_ERROR(){
|
289 |
|
|
return getTermByUuid(uuidIF);
|
290 |
|
|
}
|
291 |
|
|
|
292 |
|
|
public static final PresenceAbsenceTerm NATIVE_FORMERLY_NATIVE(){
|
293 |
|
|
return getTermByUuid(uuidNE);
|
294 |
|
|
}
|
295 |
|
|
|
296 |
|
|
public static final PresenceAbsenceTerm INTRODUCED_FORMERLY_INTRODUCED(){
|
297 |
|
|
return getTermByUuid(uuidIE);
|
298 |
|
|
}
|
299 |
|
|
|
300 |
|
|
|
301 |
|
|
//******************************** METHODS ****************************/
|
302 |
|
|
|
303 |
|
|
@Override
|
304 |
|
|
public void resetTerms(){
|
305 |
|
|
termMap = null;
|
306 |
|
|
}
|
307 |
|
|
|
308 |
|
|
@Override
|
309 |
|
|
protected void setDefaultTerms(TermVocabulary<PresenceAbsenceTerm> termVocabulary) {
|
310 |
|
|
termMap = new HashMap<UUID, PresenceAbsenceTerm>();
|
311 |
|
|
for (PresenceAbsenceTerm term : termVocabulary.getTerms()){
|
312 |
|
|
termMap.put(term.getUuid(), term);
|
313 |
|
|
}
|
314 |
|
|
}
|
315 |
|
|
|
316 |
|
|
@Override
|
317 |
|
|
public PresenceAbsenceTerm readCsvLine(Class<PresenceAbsenceTerm> termClass, List<String> csvLine, Map<UUID,DefinedTermBase> terms, boolean abbrevAsId){
|
318 |
|
|
PresenceAbsenceTerm newInstance = super.readCsvLine(termClass, csvLine, terms, abbrevAsId);
|
319 |
|
|
String abbreviatedLabel = csvLine.get(4);
|
320 |
|
|
// String uuid = (String)csvLine.get(0);
|
321 |
|
|
// map.put(abbreviatedLabel, UUID.fromString(uuid));
|
322 |
|
|
String color = csvLine.get(5);
|
323 |
|
|
try {
|
324 |
|
|
newInstance.setDefaultColor(color);
|
325 |
|
|
} catch (ParseException e) {
|
326 |
|
|
throw new RuntimeException(e);
|
327 |
|
|
}
|
328 |
|
|
boolean isAbsence = csvLine.get(6).equals("1") ? true : false;
|
329 |
|
|
newInstance.setAbsenceTerm(isAbsence);
|
330 |
|
|
|
331 |
|
|
newInstance.getRepresentation(Language.DEFAULT()).setAbbreviatedLabel(abbreviatedLabel);
|
332 |
|
|
return newInstance;
|
333 |
|
|
}
|
334 |
|
|
|
335 |
|
|
/**
|
336 |
|
|
* @return the defaultColor
|
337 |
|
|
*/
|
338 |
|
|
public String getDefaultColor() {
|
339 |
|
|
return defaultColor;
|
340 |
|
|
}
|
341 |
|
|
|
342 |
|
|
/**
|
343 |
|
|
* @param defaultColor the defaultColor to set
|
344 |
|
|
* @throws ParseException
|
345 |
|
|
*/
|
346 |
|
|
//TODO make format checking a hibernate validation rule
|
347 |
|
|
public void setDefaultColor(String defaultColor) throws ParseException {
|
348 |
|
|
String regEx = "[0-9a-fA-F]{6}";
|
349 |
|
|
if (StringUtils.isEmpty(defaultColor)){
|
350 |
|
|
this.defaultColor = null;
|
351 |
|
|
}else if (StringUtils.isEmpty(defaultColor) || defaultColor.matches(regEx)){
|
352 |
|
|
this.defaultColor = defaultColor;
|
353 |
|
|
}else{
|
354 |
|
|
throw new java.text.ParseException("Default color is not of correct format. Required is 'FFFFFF'", -1);
|
355 |
|
|
}
|
356 |
|
|
}
|
357 |
|
|
|
358 |
|
|
/**
|
359 |
|
|
* Compares this OrderedTermBase with the specified OrderedTermBase for
|
360 |
|
|
* order. Returns a -1, 0, or +1 if the orderId of this object is greater
|
361 |
|
|
* than, equal to, or less than the specified object.
|
362 |
|
|
* <p>
|
363 |
|
|
* <b>Note:</b> The compare logic of this method is the <b>inverse logic</b>
|
364 |
|
|
* of the the one implemented in
|
365 |
|
|
* {@link java.lang.Comparable#compareTo(java.lang.Object)}
|
366 |
|
|
*
|
367 |
|
|
* @param orderedTerm
|
368 |
|
|
* the OrderedTermBase to be compared
|
369 |
|
|
* @param skipVocabularyCheck
|
370 |
|
|
* whether to skip checking if both terms to compare are in the
|
371 |
|
|
* same vocabulary
|
372 |
|
|
* @throws NullPointerException
|
373 |
|
|
* if the specified object is null
|
374 |
|
|
*/
|
375 |
|
|
@Override
|
376 |
|
|
protected int performCompareTo(PresenceAbsenceTerm presenceAbsenceTerm, boolean skipVocabularyCheck) {
|
377 |
|
|
|
378 |
|
|
PresenceAbsenceTerm presenceAbsenceTermLocal = CdmBase.deproxy(presenceAbsenceTerm, PresenceAbsenceTerm.class);
|
379 |
|
|
if(! skipVocabularyCheck){
|
380 |
|
|
if (this.vocabulary == null || presenceAbsenceTermLocal.vocabulary == null){
|
381 |
|
|
throw new IllegalStateException("An ordered term (" + this.toString() + " or " +
|
382 |
|
|
presenceAbsenceTermLocal.toString() + ") of class " + this.getClass() + " or " +
|
383 |
|
|
presenceAbsenceTermLocal.getClass() + " does not belong to a vocabulary and therefore "
|
384 |
|
|
+ "can not be compared");
|
385 |
|
|
}
|
386 |
|
|
if (presenceAbsenceTermLocal.isAbsenceTerm() != this.isAbsenceTerm() ){
|
387 |
|
|
if (presenceAbsenceTermLocal.isAbsenceTerm()){
|
388 |
|
|
return 1;
|
389 |
|
|
}else{
|
390 |
|
|
return -1;
|
391 |
|
|
}
|
392 |
|
|
|
393 |
|
|
}
|
394 |
|
|
}
|
395 |
|
|
|
396 |
|
|
int orderThat;
|
397 |
|
|
int orderThis;
|
398 |
|
|
try {
|
399 |
|
|
orderThat = presenceAbsenceTermLocal.orderIndex;//OLD: this.getVocabulary().getTerms().indexOf(orderedTerm);
|
400 |
|
|
orderThis = orderIndex; //OLD: this.getVocabulary().getTerms().indexOf(this);
|
401 |
|
|
} catch (RuntimeException e) {
|
402 |
|
|
throw e;
|
403 |
|
|
}
|
404 |
|
|
if (orderThis > orderThat){
|
405 |
|
|
return -1;
|
406 |
|
|
}else if (orderThis < orderThat){
|
407 |
|
|
return 1;
|
408 |
|
|
}else {
|
409 |
|
|
return 0;
|
410 |
|
|
}
|
411 |
|
|
}
|
412 |
|
|
|
413 |
|
|
|
414 |
|
|
public boolean isAbsenceTerm() {
|
415 |
|
|
return absenceTerm;
|
416 |
|
|
}
|
417 |
|
|
|
418 |
|
|
public void setAbsenceTerm(boolean isAbsenceTerm) {
|
419 |
|
|
this.absenceTerm = isAbsenceTerm;
|
420 |
|
|
}
|
421 |
|
|
|
422 |
|
|
|
423 |
ccf1f2f1
|
Andreas Müller
|
}
|