1 |
9479da48
|
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 |
03abbcde
|
Andreas Müller
|
import java.util.ArrayList;
|
13 |
a42e27ce
|
Andreas Müller
|
import java.util.HashSet;
|
14 |
03abbcde
|
Andreas Müller
|
import java.util.List;
|
15 |
9479da48
|
Andreas Müller
|
|
16 |
03abbcde
|
Andreas Müller
|
import javax.persistence.Entity;
|
17 |
f6765014
|
ben.clark
|
import javax.persistence.FetchType;
|
18 |
03abbcde
|
Andreas Müller
|
import javax.persistence.ManyToMany;
|
19 |
01b7ddbf
|
a.babadshanjan
|
import javax.xml.bind.annotation.XmlAccessType;
|
20 |
|
|
import javax.xml.bind.annotation.XmlAccessorType;
|
21 |
|
|
import javax.xml.bind.annotation.XmlElement;
|
22 |
|
|
import javax.xml.bind.annotation.XmlElementWrapper;
|
23 |
|
|
import javax.xml.bind.annotation.XmlRootElement;
|
24 |
|
|
import javax.xml.bind.annotation.XmlType;
|
25 |
9479da48
|
Andreas Müller
|
|
26 |
03abbcde
|
Andreas Müller
|
import org.apache.log4j.Logger;
|
27 |
|
|
import org.hibernate.annotations.Cascade;
|
28 |
|
|
import org.hibernate.annotations.CascadeType;
|
29 |
ee91bcd9
|
ben.clark
|
import org.hibernate.envers.Audited;
|
30 |
17a0cbe8
|
ben.clark
|
import org.hibernate.search.annotations.Indexed;
|
31 |
51db8d4a
|
ben.clark
|
import org.hibernate.search.annotations.IndexedEmbedded;
|
32 |
a1587c24
|
ben.clark
|
import org.hibernate.validator.constraints.NotEmpty;
|
33 |
|
|
|
34 |
a42e27ce
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
|
35 |
a1587c24
|
ben.clark
|
import eu.etaxonomy.cdm.validation.Level2;
|
36 |
03abbcde
|
Andreas Müller
|
|
37 |
9479da48
|
Andreas Müller
|
/**
|
38 |
50c72f11
|
m.geoffroy
|
* This class represents information pieces expressed in categorical type of
|
39 |
f51e2565
|
m.geoffroy
|
* data (in opposition to {@link QuantitativeData quantitative data} on one side and to literal data on
|
40 |
4daf2f37
|
m.geoffroy
|
* the other side). Only {@link TaxonDescription taxon descriptions} and
|
41 |
|
|
* {@link SpecimenDescription specimen descriptions} may contain categorical data.<BR>
|
42 |
f51e2565
|
m.geoffroy
|
* The "color of petals" {@link Feature feature} for instance can be described with
|
43 |
|
|
* {@link State state terms} such as "blue" or "white". If the color of petals of a
|
44 |
|
|
* particular tree is described as "mostly blue" and "exceptionally white" two
|
45 |
|
|
* {@link StateData state data} instances must be assigned to an instance of the
|
46 |
|
|
* present class: the first one with the state "blue" and the {@link Modifier modifier}
|
47 |
3a9870fa
|
m.geoffroy
|
* "mostly" and the second one with the state "white" and the modifier "exceptionally".
|
48 |
|
|
* Whenever more than one state data belongs to a categorical data they should be
|
49 |
|
|
* interpreted as being related by the inclusive disjunction "or".
|
50 |
50c72f11
|
m.geoffroy
|
* <P>
|
51 |
|
|
* This class corresponds partially to CodedDescriptionType according to
|
52 |
|
|
* the SDD schema.
|
53 |
|
|
*
|
54 |
9479da48
|
Andreas Müller
|
* @author m.doering
|
55 |
|
|
* @version 1.0
|
56 |
|
|
* @created 08-Nov-2007 13:06:15
|
57 |
|
|
*/
|
58 |
01b7ddbf
|
a.babadshanjan
|
@XmlAccessorType(XmlAccessType.FIELD)
|
59 |
|
|
@XmlType(name = "CategoricalData", propOrder = {
|
60 |
|
|
"orderRelevant",
|
61 |
|
|
"states"
|
62 |
|
|
})
|
63 |
|
|
@XmlRootElement(name = "CategoricalData")
|
64 |
9479da48
|
Andreas Müller
|
@Entity
|
65 |
ee91bcd9
|
ben.clark
|
@Audited
|
66 |
17a0cbe8
|
ben.clark
|
@Indexed(index = "eu.etaxonomy.cdm.model.description.DescriptionElementBase")
|
67 |
a42e27ce
|
Andreas Müller
|
public class CategoricalData extends DescriptionElementBase implements Cloneable{
|
68 |
03abbcde
|
Andreas Müller
|
private static final long serialVersionUID = -6298361966947668998L;
|
69 |
|
|
private static final Logger logger = Logger.getLogger(CategoricalData.class);
|
70 |
b484eedb
|
Andreas Müller
|
|
71 |
9479da48
|
Andreas Müller
|
//whether the sequence of ordered states is important
|
72 |
01b7ddbf
|
a.babadshanjan
|
@XmlElement(name = "OrderRelevant")
|
73 |
9479da48
|
Andreas Müller
|
private boolean orderRelevant;
|
74 |
01b7ddbf
|
a.babadshanjan
|
|
75 |
|
|
@XmlElementWrapper(name = "States")
|
76 |
|
|
@XmlElement(name = "State")
|
77 |
ee91bcd9
|
ben.clark
|
@ManyToMany(fetch = FetchType.LAZY)
|
78 |
51db8d4a
|
ben.clark
|
@Cascade({ CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.DELETE,CascadeType.DELETE_ORPHAN })
|
79 |
|
|
@IndexedEmbedded(depth = 2)
|
80 |
a1587c24
|
ben.clark
|
@NotEmpty(groups = Level2.class)
|
81 |
03abbcde
|
Andreas Müller
|
private List<StateData> states = new ArrayList<StateData>();
|
82 |
9479da48
|
Andreas Müller
|
|
83 |
b484eedb
|
Andreas Müller
|
|
84 |
50c72f11
|
m.geoffroy
|
/**
|
85 |
|
|
* Class constructor: creates a new empty categorical data instance.
|
86 |
b484eedb
|
Andreas Müller
|
*/
|
87 |
|
|
protected CategoricalData() {
|
88 |
76f719a7
|
Andreas Müller
|
super(null);
|
89 |
9479da48
|
Andreas Müller
|
}
|
90 |
|
|
|
91 |
50c72f11
|
m.geoffroy
|
/**
|
92 |
|
|
* Creates a new empty categorical data instance.
|
93 |
|
|
*/
|
94 |
|
|
public static CategoricalData NewInstance(){
|
95 |
03abbcde
|
Andreas Müller
|
logger.debug("NewInstance");
|
96 |
50c72f11
|
m.geoffroy
|
return new CategoricalData();
|
97 |
|
|
}
|
98 |
|
|
|
99 |
|
|
/**
|
100 |
|
|
* Returns the (ordered) list of {@link State states} describing the {@link Feature feature}
|
101 |
|
|
* corresponding to <i>this</i> categorical data.
|
102 |
|
|
*/
|
103 |
b7c8bf54
|
h.fradin
|
|
104 |
437dbee8
|
h.fradin
|
public List<StateData> getStates(){
|
105 |
9479da48
|
Andreas Müller
|
return this.states;
|
106 |
|
|
}
|
107 |
a1587c24
|
ben.clark
|
|
108 |
|
|
protected void setStates(List<StateData> states){
|
109 |
|
|
this.states = states;
|
110 |
|
|
}
|
111 |
ee91bcd9
|
ben.clark
|
|
112 |
50c72f11
|
m.geoffroy
|
/**
|
113 |
|
|
* Adds a {@link State state} to the list of {@link #getStates() states}
|
114 |
|
|
* describing the {@link Feature feature} corresponding to <i>this</i> categorical data.
|
115 |
|
|
*
|
116 |
|
|
* @param state the state to be added to <i>this</i> categorical data
|
117 |
|
|
* @see #getStates()
|
118 |
|
|
*/
|
119 |
437dbee8
|
h.fradin
|
public void addState(StateData state){
|
120 |
9479da48
|
Andreas Müller
|
this.states.add(state);
|
121 |
|
|
}
|
122 |
50c72f11
|
m.geoffroy
|
/**
|
123 |
|
|
* Removes one element from the set of {@link #getStates() states}
|
124 |
|
|
* describing the {@link Feature feature} corresponding to <i>this</i> categorical data.
|
125 |
|
|
*
|
126 |
|
|
* @param state the state which should be removed
|
127 |
|
|
* @see #getStates()
|
128 |
|
|
* @see #addState(State)
|
129 |
|
|
*/
|
130 |
72cc7722
|
n.hoffmann
|
public void removeState(StateData state){
|
131 |
9479da48
|
Andreas Müller
|
this.states.remove(state);
|
132 |
|
|
}
|
133 |
|
|
|
134 |
3a9870fa
|
m.geoffroy
|
//rename to isStateSequenceIntentional ??
|
135 |
50c72f11
|
m.geoffroy
|
/**
|
136 |
3a9870fa
|
m.geoffroy
|
* Returns the boolean value of the flag indicating whether the sequence of
|
137 |
|
|
* {@link StateData state data} belonging to <i>this</i> categorical data is intentional
|
138 |
|
|
* (true) and therefore relevant for interpretation or analysis or not (false).
|
139 |
|
|
* The use of this flag depends mostly on the {@link Feature feature} of <i>this</i> categorical data.
|
140 |
50c72f11
|
m.geoffroy
|
*
|
141 |
|
|
* @return the boolean value of the orderRelevant flag
|
142 |
|
|
*/
|
143 |
9479da48
|
Andreas Müller
|
public boolean getOrderRelevant(){
|
144 |
|
|
return this.orderRelevant;
|
145 |
|
|
}
|
146 |
50c72f11
|
m.geoffroy
|
/**
|
147 |
|
|
* @see #getOrderRelevant()
|
148 |
|
|
*/
|
149 |
9479da48
|
Andreas Müller
|
public void setOrderRelevant(boolean orderRelevant){
|
150 |
|
|
this.orderRelevant = orderRelevant;
|
151 |
|
|
}
|
152 |
a42e27ce
|
Andreas Müller
|
|
153 |
|
|
|
154 |
|
|
//*********************************** CLONE *****************************************/
|
155 |
|
|
|
156 |
|
|
/**
|
157 |
|
|
* Clones <i>this</i> categorical data. This is a shortcut that enables to create
|
158 |
|
|
* a new instance that differs only slightly from <i>this</i> categorical data by
|
159 |
|
|
* modifying only some of the attributes.
|
160 |
|
|
*
|
161 |
|
|
* @see eu.etaxonomy.cdm.model.description.DescriptionElementBase#clone()
|
162 |
|
|
* @see java.lang.Object#clone()
|
163 |
|
|
*/
|
164 |
|
|
@Override
|
165 |
|
|
public Object clone() {
|
166 |
|
|
|
167 |
|
|
try {
|
168 |
|
|
CategoricalData result = (CategoricalData)super.clone();
|
169 |
|
|
|
170 |
|
|
//states
|
171 |
|
|
result.states = new ArrayList<StateData>();
|
172 |
|
|
for (StateData stateData : getStates()){
|
173 |
9ec690dd
|
Katja Luther
|
//TODO do we need to clone here?
|
174 |
|
|
//StateData newState = (StateData)stateData.clone();
|
175 |
|
|
result.states.add(stateData);
|
176 |
a42e27ce
|
Andreas Müller
|
}
|
177 |
|
|
|
178 |
|
|
return result;
|
179 |
|
|
//no changes to: orderRelevant
|
180 |
|
|
} catch (CloneNotSupportedException e) {
|
181 |
|
|
logger.warn("Object does not implement cloneable");
|
182 |
|
|
e.printStackTrace();
|
183 |
|
|
return null;
|
184 |
|
|
}
|
185 |
|
|
}
|
186 |
9479da48
|
Andreas Müller
|
|
187 |
|
|
}
|