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.description;
|
11
|
|
12
|
|
13
|
import java.util.HashSet;
|
14
|
import java.util.Set;
|
15
|
|
16
|
import javax.persistence.Entity;
|
17
|
import javax.persistence.FetchType;
|
18
|
import javax.persistence.ManyToMany;
|
19
|
import javax.persistence.ManyToOne;
|
20
|
import javax.xml.bind.annotation.XmlAccessType;
|
21
|
import javax.xml.bind.annotation.XmlAccessorType;
|
22
|
import javax.xml.bind.annotation.XmlElement;
|
23
|
import javax.xml.bind.annotation.XmlElementWrapper;
|
24
|
import javax.xml.bind.annotation.XmlIDREF;
|
25
|
import javax.xml.bind.annotation.XmlRootElement;
|
26
|
import javax.xml.bind.annotation.XmlSchemaType;
|
27
|
import javax.xml.bind.annotation.XmlType;
|
28
|
|
29
|
import org.apache.log4j.Logger;
|
30
|
import org.hibernate.envers.Audited;
|
31
|
import org.hibernate.search.annotations.Indexed;
|
32
|
import org.hibernate.search.annotations.IndexedEmbedded;
|
33
|
|
34
|
import eu.etaxonomy.cdm.model.common.VersionableEntity;
|
35
|
import eu.etaxonomy.cdm.model.term.DefinedTerm;
|
36
|
import eu.etaxonomy.cdm.model.term.TermType;
|
37
|
|
38
|
/**
|
39
|
* This class represents the assignment of numerical values to {@link Feature features}
|
40
|
* corresponding to {@link QuantitativeData quantitative data}. A statistical measurement
|
41
|
* value instance constitutes an atomized part of an information piece
|
42
|
* (quantitative data) so that several statistical measurement value instances
|
43
|
* may belong to one quantitative data instance.
|
44
|
* <P>
|
45
|
* This class corresponds to CharacterMeasureDataType according
|
46
|
* to the SDD schema.
|
47
|
*
|
48
|
* @author m.doering
|
49
|
* @since 08-Nov-2007 13:06:54
|
50
|
*/
|
51
|
@XmlAccessorType(XmlAccessType.FIELD)
|
52
|
@XmlType(name = "StatisticalMeasureValue")
|
53
|
@XmlRootElement(name = "StatisticalMeasureValue")
|
54
|
@Entity
|
55
|
@Indexed(index = "eu.etaxonomy.cdm.model.description.DescriptionElementBase")
|
56
|
@Audited
|
57
|
public class StatisticalMeasurementValue
|
58
|
extends VersionableEntity
|
59
|
implements IModifiable{
|
60
|
|
61
|
private static final long serialVersionUID = -3576311887760351982L;
|
62
|
private static final Logger logger = Logger.getLogger(StatisticalMeasurementValue.class);
|
63
|
|
64
|
@XmlElement(name = "Value")
|
65
|
private float value;
|
66
|
|
67
|
@XmlElementWrapper(name = "Modifiers")
|
68
|
@XmlElement(name = "Modifier")
|
69
|
@XmlIDREF
|
70
|
@XmlSchemaType(name = "IDREF")
|
71
|
@ManyToMany(fetch = FetchType.LAZY)
|
72
|
// @NotNull // avoids creating a UNIQUE key for this field -> not needed for ManyToMany
|
73
|
private Set<DefinedTerm> modifiers = new HashSet<>();
|
74
|
|
75
|
@XmlElement(name = "StatisticalMeasureType")
|
76
|
@XmlIDREF
|
77
|
@XmlSchemaType(name = "IDREF")
|
78
|
@ManyToOne(fetch = FetchType.LAZY)
|
79
|
private StatisticalMeasure type;
|
80
|
|
81
|
@XmlElement(name = "QuantitativeData")
|
82
|
@XmlIDREF
|
83
|
@XmlSchemaType(name = "IDREF")
|
84
|
@ManyToOne(fetch = FetchType.LAZY )
|
85
|
@IndexedEmbedded(depth=1)
|
86
|
private QuantitativeData quantitativeData;
|
87
|
|
88
|
|
89
|
|
90
|
/**
|
91
|
* Class constructor: creates a new empty statistical measurement value
|
92
|
* instance.
|
93
|
*/
|
94
|
protected StatisticalMeasurementValue(){
|
95
|
super();
|
96
|
}
|
97
|
|
98
|
/**
|
99
|
* Creates a new empty statistical measurement value instance.
|
100
|
*/
|
101
|
public static StatisticalMeasurementValue NewInstance(){
|
102
|
return new StatisticalMeasurementValue();
|
103
|
}
|
104
|
|
105
|
|
106
|
/**
|
107
|
* Creates a new empty statistical measurement value instance.
|
108
|
*/
|
109
|
public static StatisticalMeasurementValue NewInstance(StatisticalMeasure type, float value){
|
110
|
StatisticalMeasurementValue result = new StatisticalMeasurementValue();
|
111
|
result.setValue(value);
|
112
|
result.setType(type);
|
113
|
return result;
|
114
|
}
|
115
|
|
116
|
|
117
|
/**
|
118
|
* Returns the type of {@link StatisticalMeasure statistical measure} used in
|
119
|
* <i>this</i> statistical measurement value.
|
120
|
*/
|
121
|
public StatisticalMeasure getType(){
|
122
|
return this.type;
|
123
|
}
|
124
|
/**
|
125
|
* @see #getType()
|
126
|
*/
|
127
|
public void setType(StatisticalMeasure type){
|
128
|
this.type = type;
|
129
|
}
|
130
|
|
131
|
|
132
|
/**
|
133
|
* Returns the numerical value used to describe the {@link Feature feature}
|
134
|
* corresponding to the {@link QuantitativeData quantitative data} <i>this</i>
|
135
|
* statistical measurement value belongs to.
|
136
|
*/
|
137
|
public float getValue(){
|
138
|
return this.value;
|
139
|
}
|
140
|
/**
|
141
|
* @see #getValue()
|
142
|
*/
|
143
|
public void setValue(float value){
|
144
|
this.value = value;
|
145
|
}
|
146
|
|
147
|
|
148
|
/**
|
149
|
* Returns the {@link QuantitativeData quantitative data} <i>this</i>
|
150
|
* statistical measurement value belongs too.
|
151
|
*/
|
152
|
public QuantitativeData getQuantitativeData() {
|
153
|
return quantitativeData;
|
154
|
}
|
155
|
|
156
|
//for bidirectional use only
|
157
|
@Deprecated
|
158
|
protected void setQuantitativeData(QuantitativeData quantitativeData) {
|
159
|
this.quantitativeData = quantitativeData;
|
160
|
}
|
161
|
|
162
|
|
163
|
/**
|
164
|
* Returns the set of terms of {@link TermType type} Modifier used to qualify the validity
|
165
|
* or probability of <i>this</i> statistical measurement value.
|
166
|
* This is only metainformation.
|
167
|
*/
|
168
|
@Override
|
169
|
public Set<DefinedTerm> getModifiers() {
|
170
|
return modifiers;
|
171
|
}
|
172
|
|
173
|
/**
|
174
|
* Adds a {@link Modifier modifier} to the set of {@link #getModifiers() modifiers}
|
175
|
* used to qualify the validity of <i>this</i> statistical measurement value.
|
176
|
*
|
177
|
* @param modifier the modifier to be added to <i>this</i> statistical measurement value
|
178
|
* @see #getModifiers()
|
179
|
*/
|
180
|
@Override
|
181
|
public void addModifier(DefinedTerm modifier) {
|
182
|
this.modifiers.add(modifier);
|
183
|
}
|
184
|
/**
|
185
|
* Removes one element from the set of {@link #getModifiers() modifiers}
|
186
|
* used to qualify the validity of <i>this</i> statistical measurement value.
|
187
|
*
|
188
|
* @param modifier the modifier which should be removed
|
189
|
* @see #getModifiers()
|
190
|
* @see #addModifier(Modifier)
|
191
|
*/
|
192
|
@Override
|
193
|
public void removeModifier(DefinedTerm modifier) {
|
194
|
this.modifiers.remove(modifier);
|
195
|
}
|
196
|
|
197
|
|
198
|
//*********************************** CLONE *****************************************/
|
199
|
|
200
|
/**
|
201
|
* Clones <i>this</i> statistical measurement value. This is a shortcut that enables to create
|
202
|
* a new instance that differs only slightly from <i>this</i> statistical measurement value by
|
203
|
* modifying only some of the attributes.
|
204
|
*
|
205
|
* @see eu.etaxonomy.cdm.model.common.VersionableEntity#clone()
|
206
|
* @see java.lang.Object#clone()
|
207
|
*/
|
208
|
@Override
|
209
|
public Object clone() {
|
210
|
|
211
|
try {
|
212
|
StatisticalMeasurementValue result = (StatisticalMeasurementValue)super.clone();
|
213
|
|
214
|
//modifiers
|
215
|
result.modifiers = new HashSet<>();
|
216
|
for (DefinedTerm modifier : getModifiers()){
|
217
|
result.addModifier(modifier);
|
218
|
}
|
219
|
|
220
|
return result;
|
221
|
//no changes to: value, type
|
222
|
} catch (CloneNotSupportedException e) {
|
223
|
logger.warn("Object does not implement cloneable");
|
224
|
e.printStackTrace();
|
225
|
return null;
|
226
|
}
|
227
|
}
|
228
|
|
229
|
@Override
|
230
|
public String toString() {
|
231
|
return ((modifiers!=null&&!modifiers.isEmpty())?modifiers.toString():"")+
|
232
|
(type!=null?type:"[no type]")
|
233
|
+"="+value;
|
234
|
}
|
235
|
|
236
|
}
|