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.common;
|
11
|
|
12
|
import java.util.Set;
|
13
|
|
14
|
import javax.persistence.Entity;
|
15
|
import javax.xml.bind.annotation.XmlAccessType;
|
16
|
import javax.xml.bind.annotation.XmlAccessorType;
|
17
|
import javax.xml.bind.annotation.XmlElement;
|
18
|
import javax.xml.bind.annotation.XmlSeeAlso;
|
19
|
import javax.xml.bind.annotation.XmlType;
|
20
|
|
21
|
import org.apache.log4j.Logger;
|
22
|
import org.hibernate.envers.Audited;
|
23
|
|
24
|
import eu.etaxonomy.cdm.model.description.Modifier;
|
25
|
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTermBase;
|
26
|
import eu.etaxonomy.cdm.model.description.State;
|
27
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
28
|
import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
|
29
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
|
30
|
import eu.etaxonomy.cdm.model.name.Rank;
|
31
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
|
32
|
|
33
|
/**
|
34
|
* @author m.doering
|
35
|
* @version 1.0
|
36
|
* @created 08-Nov-2007 13:06:23
|
37
|
*/
|
38
|
@XmlAccessorType(XmlAccessType.FIELD)
|
39
|
@XmlType(name = "OrderedTermBase", propOrder = {
|
40
|
"orderIndex"
|
41
|
})
|
42
|
@XmlSeeAlso({
|
43
|
Keyword.class,
|
44
|
RelationshipTermBase.class,
|
45
|
Modifier.class,
|
46
|
PresenceAbsenceTermBase.class,
|
47
|
State.class,
|
48
|
NamedArea.class,
|
49
|
NamedAreaLevel.class,
|
50
|
NomenclaturalStatusType.class,
|
51
|
Rank.class,
|
52
|
SpecimenTypeDesignationStatus.class
|
53
|
})
|
54
|
@Entity
|
55
|
@Audited
|
56
|
public abstract class OrderedTermBase<T extends OrderedTermBase> extends DefinedTermBase<T> implements Comparable<T> {
|
57
|
private static final long serialVersionUID = 8000797926720467399L;
|
58
|
@SuppressWarnings("unused")
|
59
|
private static final Logger logger = Logger.getLogger(OrderedTermBase.class);
|
60
|
|
61
|
//Order index, value < 1 means that this Term is not in order yet
|
62
|
@XmlElement(name = "OrderIndex")
|
63
|
protected int orderIndex;
|
64
|
|
65
|
public OrderedTermBase() {
|
66
|
super();
|
67
|
}
|
68
|
public OrderedTermBase(String term, String label, String labelAbbrev) {
|
69
|
super(term, label, labelAbbrev);
|
70
|
}
|
71
|
|
72
|
/* (non-Javadoc)
|
73
|
* @see java.lang.Comparable#compareTo(java.lang.Object)
|
74
|
*/
|
75
|
public int compareTo(T orderedTerm) {
|
76
|
int orderThat;
|
77
|
int orderThis;
|
78
|
try {
|
79
|
orderThat = orderedTerm.orderIndex;//OLD: this.getVocabulary().getTerms().indexOf(orderedTerm);
|
80
|
orderThis = orderIndex; //OLD: this.getVocabulary().getTerms().indexOf(this);
|
81
|
} catch (RuntimeException e) {
|
82
|
throw e;
|
83
|
}
|
84
|
if (orderThis > orderThat){
|
85
|
return -1;
|
86
|
}else if (orderThis < orderThat){
|
87
|
return 1;
|
88
|
}else {
|
89
|
return 0;
|
90
|
}
|
91
|
}
|
92
|
|
93
|
/**
|
94
|
* If this term is lower than the parameter term, true is returned, else false.
|
95
|
* If the parameter term is null, an Exception is thrown.
|
96
|
* @param orderedTerm
|
97
|
* @return boolean result of the comparison
|
98
|
*/
|
99
|
public boolean isLower(T orderedTerm){
|
100
|
return (this.compareTo(orderedTerm) < 0 );
|
101
|
}
|
102
|
|
103
|
|
104
|
/**
|
105
|
* If this term is higher than the parameter term, true is returned, else false.
|
106
|
* If the parameter term is null, an Exception is thrown.
|
107
|
* @param orderedTerm
|
108
|
* @return boolean result of the comparison
|
109
|
*/
|
110
|
public boolean isHigher(T orderedTerm){
|
111
|
return (this.compareTo(orderedTerm) > 0 );
|
112
|
}
|
113
|
|
114
|
|
115
|
/** To be used only by OrderedTermVocabulary*/
|
116
|
@Deprecated
|
117
|
protected boolean decreaseIndex(OrderedTermVocabulary<T> vocabulary){
|
118
|
if (vocabulary.indexChangeAllowed(this) == true){
|
119
|
orderIndex--;
|
120
|
return true;
|
121
|
}else{
|
122
|
return false;
|
123
|
}
|
124
|
}
|
125
|
|
126
|
/** To be used only by OrderedTermVocabulary*/
|
127
|
@Deprecated
|
128
|
protected boolean incrementIndex(OrderedTermVocabulary<T> vocabulary){
|
129
|
if (vocabulary.indexChangeAllowed(this) == true){
|
130
|
orderIndex++;
|
131
|
return true;
|
132
|
}else{
|
133
|
return false;
|
134
|
}
|
135
|
}
|
136
|
|
137
|
@Override
|
138
|
public boolean equals(Object object){
|
139
|
if(this == object)
|
140
|
return true;
|
141
|
if((object == null) || (!OrderedTermBase.class.isAssignableFrom(object.getClass()))) {
|
142
|
return false;
|
143
|
}else{
|
144
|
OrderedTermBase orderedTermBase = (OrderedTermBase)object;
|
145
|
if (orderedTermBase.getUuid().equals(this.getUuid())){
|
146
|
return true;
|
147
|
}else{
|
148
|
return false;
|
149
|
}
|
150
|
}
|
151
|
}
|
152
|
}
|