Project

General

Profile

Download (4.41 KB) Statistics
| Branch: | Tag: | Revision:
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> {
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
	/**
73
	 * Compares this OrderedTermBase with the specified OrderedTermBase for
74
	 * order. Returns a negative integer, zero, or a positive integer as the
75
	 * orderId of this object is greater than, equal to, or less than the
76
	 * specified object. This Integer compare logic of this method is the
77
	 * <b>inverse logic</b> of the the one implemented in
78
	 * {@link java.lang.Comparable#compareTo(java.lang.Object)}
79
	 */
80
	public int compareTo(T orderedTerm) {
81
		int orderThat;
82
		int orderThis;
83
		try {
84
			orderThat = orderedTerm.orderIndex;//OLD: this.getVocabulary().getTerms().indexOf(orderedTerm);
85
			orderThis = orderIndex; //OLD: this.getVocabulary().getTerms().indexOf(this);
86
		} catch (RuntimeException e) {
87
			throw e;
88
		}
89
		if (orderThis > orderThat){
90
			return -1;
91
		}else if (orderThis < orderThat){
92
			return 1;
93
		}else {
94
			return 0;
95
		}
96
	}
97
	
98
	public int compareTo(Object o) {
99
		return 0;
100
	}
101
	
102
	/**
103
	 * If this term is lower than the parameter term, true is returned, else false.
104
	 * If the parameter term is null, an Exception is thrown.
105
	 * @param orderedTerm
106
	 * @return boolean result of the comparison
107
	 */
108
	public boolean isLower(T orderedTerm){
109
		return (this.compareTo(orderedTerm) < 0 );
110
	}
111

    
112
	
113
	/**
114
	 * If this term is higher than the parameter term, true is returned, else false.
115
	 * If the parameter term is null, an Exception is thrown.
116
	 * @param orderedTerm
117
	 * @return boolean result of the comparison
118
	 */
119
	public boolean isHigher(T orderedTerm){
120
		return (this.compareTo(orderedTerm) > 0 );
121
	}
122
	
123
	
124
	/** To be used only by OrderedTermVocabulary*/
125
	@Deprecated
126
	protected boolean decreaseIndex(OrderedTermVocabulary<T> vocabulary){
127
		if (vocabulary.indexChangeAllowed(this) == true){
128
			orderIndex--;
129
			return true;
130
		}else{
131
			return false;
132
		}
133
	}
134
	
135
	/** To be used only by OrderedTermVocabulary*/
136
	@Deprecated
137
	protected boolean incrementIndex(OrderedTermVocabulary<T> vocabulary){
138
		if (vocabulary.indexChangeAllowed(this) == true){
139
			orderIndex++;
140
			return true;
141
		}else{
142
			return false;
143
		}
144
	}
145
	
146
	@Override
147
	public boolean equals(Object object){
148
		if(this == object)
149
			return true;
150
		if((object == null) || (!OrderedTermBase.class.isAssignableFrom(object.getClass()))) {
151
			return false;
152
		}else{
153
			OrderedTermBase orderedTermBase = (OrderedTermBase)object;
154
			if (orderedTermBase.getUuid().equals(this.getUuid())){
155
				return true;
156
			}else{
157
				return false;
158
			}
159
		}
160
	}
161
}
(37-37/58)