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
.xml
.bind
.annotation
.XmlAccessType
;
14 import javax
.xml
.bind
.annotation
.XmlAccessorType
;
15 import javax
.xml
.bind
.annotation
.XmlElement
;
16 import javax
.xml
.bind
.annotation
.XmlSeeAlso
;
17 import javax
.xml
.bind
.annotation
.XmlType
;
19 import org
.apache
.log4j
.Logger
;
20 import org
.hibernate
.envers
.Audited
;
21 import org
.hibernate
.search
.annotations
.Indexed
;
23 import eu
.etaxonomy
.cdm
.model
.description
.Modifier
;
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
;
34 * @created 08-Nov-2007 13:06:23
36 @XmlAccessorType(XmlAccessType
.FIELD
)
37 @XmlType(name
= "OrderedTermBase", propOrder
= {
41 RelationshipTermBase
.class,
43 PresenceAbsenceTermBase
.class,
47 NomenclaturalStatusType
.class,
51 @Indexed(index
= "eu.etaxonomy.cdm.model.common.DefinedTermBase")
53 public abstract class OrderedTermBase
<T
extends OrderedTermBase
> extends DefinedTermBase
<T
> implements Comparable
<T
> {
54 private static final long serialVersionUID
= 8000797926720467399L;
55 @SuppressWarnings("unused")
56 private static final Logger logger
= Logger
.getLogger(OrderedTermBase
.class);
58 //Order index, value < 1 means that this Term is not in order yet
59 @XmlElement(name
= "OrderIndex")
60 protected int orderIndex
;
63 * Higher ordered terms have a lower order index,
64 * lower ordered terms have a higher order index:
66 * <b>a.oderIndex < b.oderIndex : a > b</b>
67 * @return the order index of a term
69 public int getOrderIndex() {
73 public OrderedTermBase() {
76 public OrderedTermBase(String term
, String label
, String labelAbbrev
) {
77 super(term
, label
, labelAbbrev
);
81 * Compares this OrderedTermBase with the specified OrderedTermBase for
82 * order. Returns a negative integer, zero, or a positive integer as the
83 * orderId of this object is greater than, equal to, or less than the
84 * specified object. This Integer compare logic of this method is the
85 * <b>inverse logic</b> of the the one implemented in
86 * {@link java.lang.Comparable#compareTo(java.lang.Object)}
88 public int compareTo(T orderedTerm
) {
89 if (this.vocabulary
== null || ! this.vocabulary
.getUuid().equals(orderedTerm
.vocabulary
.getUuid())){
90 throw new IllegalStateException("2 terms do not belong to the same vocabulary and therefore can not be compared");
96 orderThat
= orderedTerm
.orderIndex
;//OLD: this.getVocabulary().getTerms().indexOf(orderedTerm);
97 orderThis
= orderIndex
; //OLD: this.getVocabulary().getTerms().indexOf(this);
98 } catch (RuntimeException e
) {
101 if (orderThis
> orderThat
){
103 }else if (orderThis
< orderThat
){
110 // public int compareTo(IdentifiableEntity o) {
111 // if (o instanceof OrderedTermBase){
112 // return compareTo((OrderedTermBase)o);
114 // return super.compareTo(o);
119 * If this term is lower than the parameter term, true is returned, else false.
120 * If the parameter term is null, an Exception is thrown.
122 * @return boolean result of the comparison
124 public boolean isLower(T orderedTerm
){
125 return (this.compareTo(orderedTerm
) < 0 );
130 * If this term is higher than the parameter term, true is returned, else false.
131 * If the parameter term is null, an Exception is thrown.
133 * @return boolean result of the comparison
135 public boolean isHigher(T orderedTerm
){
136 return (this.compareTo(orderedTerm
) > 0 );
141 * @deprecated To be used only by OrderedTermVocabulary
144 protected boolean decreaseIndex(OrderedTermVocabulary
<T
> vocabulary
){
145 if (vocabulary
.indexChangeAllowed(this) == true){
154 * @deprecated To be used only by OrderedTermVocabulary
157 protected boolean incrementIndex(OrderedTermVocabulary
<T
> vocabulary
){
158 if (vocabulary
.indexChangeAllowed(this) == true){
167 public boolean equals(Object object
){
170 if((object
== null) || (!OrderedTermBase
.class.isAssignableFrom(object
.getClass()))) {
173 OrderedTermBase orderedTermBase
= (OrderedTermBase
)object
;
174 if (orderedTermBase
.getUuid().equals(this.getUuid())){