95e68a2cd26d9a196e803a7f21725def4011f24d
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.model
.common
;
12 import javax
.persistence
.Entity
;
13 import javax
.persistence
.Transient
;
14 import javax
.xml
.bind
.annotation
.XmlAccessType
;
15 import javax
.xml
.bind
.annotation
.XmlAccessorType
;
16 import javax
.xml
.bind
.annotation
.XmlElement
;
17 import javax
.xml
.bind
.annotation
.XmlSeeAlso
;
18 import javax
.xml
.bind
.annotation
.XmlType
;
20 import org
.apache
.log4j
.Logger
;
21 import org
.hibernate
.envers
.Audited
;
22 import org
.hibernate
.search
.annotations
.Indexed
;
24 import eu
.etaxonomy
.cdm
.model
.description
.PresenceAbsenceTermBase
;
25 import eu
.etaxonomy
.cdm
.model
.description
.State
;
26 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
27 import eu
.etaxonomy
.cdm
.model
.location
.NamedAreaLevel
;
28 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalStatusType
;
29 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
33 * @created 08-Nov-2007 13:06:23
35 @XmlAccessorType(XmlAccessType
.FIELD
)
36 @XmlType(name
= "OrderedTermBase", propOrder
= {
40 RelationshipTermBase
.class,
41 PresenceAbsenceTermBase
.class,
45 NomenclaturalStatusType
.class,
49 @Indexed(index
= "eu.etaxonomy.cdm.model.common.DefinedTermBase")
51 public abstract class OrderedTermBase
<T
extends OrderedTermBase
<?
>> extends DefinedTermBase
<T
> implements Comparable
<T
> {
52 private static final long serialVersionUID
= 8000797926720467399L;
53 @SuppressWarnings("unused")
54 private static final Logger logger
= Logger
.getLogger(OrderedTermBase
.class);
56 //Order index, value < 1 means that this Term is not in order yet
57 @XmlElement(name
= "OrderIndex")
58 protected int orderIndex
;
61 * Higher ordered terms have a lower order index,
62 * lower ordered terms have a higher order index:
64 * <b>a.oderIndex < b.oderIndex : a > b</b>
65 * @return the order index of a term
67 public int getOrderIndex() {
71 // *********************** CONSTRUCTOR *************************/
73 //for JAXB only, TODO needed?
75 protected OrderedTermBase(){}
77 protected OrderedTermBase(TermType type
) {
80 public OrderedTermBase(TermType type
, String term
, String label
, String labelAbbrev
) {
81 super(type
, term
, label
, labelAbbrev
);
84 // **************************** METHODS ******************************/
87 * Compares this OrderedTermBase with the specified OrderedTermBase for
88 * order. Returns a -1, 0, or +1 if the orderId of this object is greater
89 * than, equal to, or less than the specified object. In case the parameter
90 * is <code>null</code> the
92 * <b>Note:</b> The compare logic of this method is the <b>inverse logic</b>
93 * of the the one implemented in
94 * {@link java.lang.Comparable#compareTo(java.lang.Object)}
97 * the OrderedTermBase to be compared
98 * @throws NullPointerException
99 * if the specified object is null
102 public int compareTo(T orderedTerm
) {
103 return performCompareTo(orderedTerm
, false);
107 * Compares this OrderedTermBase with the specified OrderedTermBase for
108 * order. Returns a -1, 0, or +1 if the orderId of this object is greater
109 * than, equal to, or less than the specified object.
111 * <b>Note:</b> The compare logic of this method is the <b>inverse logic</b>
112 * of the the one implemented in
113 * {@link java.lang.Comparable#compareTo(java.lang.Object)}
116 * the OrderedTermBase to be compared
117 * @param skipVocabularyCheck
118 * whether to skip checking if both terms to compare are in the
120 * @throws NullPointerException
121 * if the specified object is null
123 protected int performCompareTo(T orderedTerm
, boolean skipVocabularyCheck
) {
125 OrderedTermBase
<?
> orderedTermLocal
= CdmBase
.deproxy(orderedTerm
, OrderedTermBase
.class);
126 if(!skipVocabularyCheck
){
127 if (this.vocabulary
== null || orderedTermLocal
.vocabulary
== null){
128 throw new IllegalStateException("An ordered term (" + this.toString() + " or " + orderedTermLocal
.toString() + ") of class " + this.getClass() + " or " + orderedTermLocal
.getClass() + " does not belong to a vocabulary and therefore can not be compared");
130 if (! this.getVocabulary().getUuid().equals(orderedTermLocal
.vocabulary
.getUuid())){
131 throw new IllegalStateException("2 terms do not belong to the same vocabulary and therefore can not be compared");
138 orderThat
= orderedTermLocal
.orderIndex
;//OLD: this.getVocabulary().getTerms().indexOf(orderedTerm);
139 orderThis
= orderIndex
; //OLD: this.getVocabulary().getTerms().indexOf(this);
140 } catch (RuntimeException e
) {
143 if (orderThis
> orderThat
){
145 }else if (orderThis
< orderThat
){
152 // public int compareTo(IdentifiableEntity o) {
153 // if (o instanceof OrderedTermBase){
154 // return compareTo((OrderedTermBase)o);
156 // return super.compareTo(o);
161 * If this term is lower than the parameter term, true is returned, else false.
162 * If the parameter term is null, an Exception is thrown.
164 * @return boolean result of the comparison
166 public boolean isLower(T orderedTerm
){
167 return (this.compareTo(orderedTerm
) < 0 );
172 * If this term is higher than the parameter term, true is returned, else false.
173 * If the parameter term is null, an Exception is thrown.
175 * @return boolean result of the comparison
177 public boolean isHigher(T orderedTerm
){
178 return (this.compareTo(orderedTerm
) > 0 );
183 * @deprecated To be used only by OrderedTermVocabulary
186 protected boolean decreaseIndex(OrderedTermVocabulary
<T
> vocabulary
){
187 if (vocabulary
.indexChangeAllowed(this) == true){
196 * @deprecated To be used only by OrderedTermVocabulary
199 protected boolean incrementIndex(OrderedTermVocabulary
<T
> vocabulary
){
200 if (vocabulary
.indexChangeAllowed(this) == true){
209 public boolean equals(Object object
){
213 if((object
== null) || (!OrderedTermBase
.class.isAssignableFrom(object
.getClass()))) {
216 OrderedTermBase
<?
> orderedTermBase
= (OrderedTermBase
<?
>)object
;
217 if (orderedTermBase
.getUuid().equals(this.getUuid())){
226 public T
getNextHigherTerm(){ //#3327
227 if (getVocabulary() == null){
230 @SuppressWarnings("unchecked")
231 OrderedTermBase
<T
> result
= CdmBase
.deproxy(getVocabulary(), OrderedTermVocabulary
.class).getNextHigherTerm(this);
237 public T
getNextLowerTerm(){ //#3327
238 if (getVocabulary() == null){
241 @SuppressWarnings("unchecked")
242 OrderedTermBase
<T
> result
= CdmBase
.deproxy(getVocabulary(), OrderedTermVocabulary
.class).getNextLowerTerm(this);
247 //*********************** CLONE ********************************************************/
250 * Clones <i>this</i> OrderedTermBase. This is a shortcut that enables to create
251 * a new instance that differs only slightly from <i>this</i> OrderedTermBase.
253 * @see eu.etaxonomy.cdm.model.common.DefinedTermBase#clone()
254 * @see java.lang.Object#clone()
257 public Object
clone() {
258 OrderedTermBase
<?
> result
= (OrderedTermBase
<?
>) super.clone();
259 //no changes to orderIndex