Project

General

Profile

Download (6.74 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.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.DefinedTerm;
35
import eu.etaxonomy.cdm.model.common.TermType;
36
import eu.etaxonomy.cdm.model.common.VersionableEntity;
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
 * @created 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 extends VersionableEntity implements IModifiable, Cloneable{
58
	private static final long serialVersionUID = -3576311887760351982L;
59
	private static final Logger logger = Logger.getLogger(StatisticalMeasurementValue.class);
60

    
61
	@XmlElement(name = "Value")
62
	private float value;
63

    
64
	@XmlElementWrapper(name = "Modifiers")
65
	@XmlElement(name = "Modifier")
66
	@XmlIDREF
67
	@XmlSchemaType(name = "IDREF")
68
	@ManyToMany(fetch = FetchType.LAZY)
69
//	@NotNull // avoids creating a UNIQUE key for this field -> not needed for ManyToMany
70
	private Set<DefinedTerm> modifiers = new HashSet<DefinedTerm>();
71

    
72
	@XmlElement(name = "StatisticalMeasureType")
73
	@XmlIDREF
74
	@XmlSchemaType(name = "IDREF")
75
	@ManyToOne(fetch = FetchType.LAZY)
76
	private StatisticalMeasure type;
77

    
78
	@XmlElement(name = "QuantitativeData")
79
    @XmlIDREF
80
    @XmlSchemaType(name = "IDREF")
81
    @ManyToOne(fetch = FetchType.LAZY )
82
    @IndexedEmbedded(depth=1)
83
	private QuantitativeData quantitativeData;
84

    
85

    
86

    
87
    /**
88
	 * Class constructor: creates a new empty statistical measurement value
89
	 * instance.
90
	 */
91
	protected StatisticalMeasurementValue(){
92
		super();
93
	}
94

    
95
	/**
96
	 * Creates a new empty statistical measurement value instance.
97
	 */
98
	public static StatisticalMeasurementValue NewInstance(){
99
		return new StatisticalMeasurementValue();
100
	}
101

    
102

    
103
	/**
104
	 * Creates a new empty statistical measurement value instance.
105
	 */
106
	public static StatisticalMeasurementValue NewInstance(StatisticalMeasure type, float value){
107
		StatisticalMeasurementValue result = new StatisticalMeasurementValue();
108
		result.setValue(value);
109
		result.setType(type);
110
		return result;
111
	}
112

    
113
	/**
114
	 * Returns the type of {@link StatisticalMeasure statistical measure} used in
115
	 * <i>this</i> statistical measurement value.
116
	 */
117
	public StatisticalMeasure getType(){
118
		return this.type;
119
	}
120
	/**
121
	 * @see	#getType()
122
	 */
123
	public void setType(StatisticalMeasure type){
124
		this.type = type;
125
	}
126

    
127

    
128
	/**
129
	 * Returns the numerical value used to describe the {@link Feature feature}
130
	 * corresponding to the {@link QuantitativeData quantitative data} <i>this</i>
131
	 * statistical measurement value belongs to.
132
	 */
133
	public float getValue(){
134
		return this.value;
135
	}
136
	/**
137
	 * @see	#getValue()
138
	 */
139
	public void setValue(float value){
140
		this.value = value;
141
	}
142

    
143

    
144
    /**
145
     * Returns the {@link QuantitativeData quantitative data} <i>this</i>
146
     * statistical measurement value belongs too.
147
     */
148
    public QuantitativeData getQuantitativeData() {
149
        return quantitativeData;
150
    }
151

    
152
    //for bidirectional use only
153
    @Deprecated
154
    protected void setQuantitativeData(QuantitativeData quantitativeData) {
155
        this.quantitativeData = quantitativeData;
156
    }
157

    
158

    
159
	/**
160
	 * Returns the set of terms of {@link TermType type} Modifier used to qualify the validity
161
	 * or probability of <i>this</i> statistical measurement value.
162
	 * This is only metainformation.
163
	 */
164
	@Override
165
    public Set<DefinedTerm> getModifiers() {
166
		return modifiers;
167
	}
168

    
169
	/**
170
	 * Adds a {@link Modifier modifier} to the set of {@link #getModifiers() modifiers}
171
	 * used to qualify the validity of <i>this</i> statistical measurement value.
172
	 *
173
	 * @param modifier	the modifier to be added to <i>this</i> statistical measurement value
174
	 * @see    	   		#getModifiers()
175
	 */
176
	@Override
177
    public void addModifier(DefinedTerm modifier) {
178
		this.modifiers.add(modifier);
179
	}
180
	/**
181
	 * Removes one element from the set of {@link #getModifiers() modifiers}
182
	 * used to qualify the validity of <i>this</i> statistical measurement value.
183
	 *
184
	 * @param  modifier	the modifier which should be removed
185
	 * @see     		#getModifiers()
186
	 * @see     		#addModifier(Modifier)
187
	 */
188
	@Override
189
    public void removeModifier(DefinedTerm modifier) {
190
		this.modifiers.remove(modifier);
191
	}
192

    
193

    
194
//*********************************** CLONE *****************************************/
195

    
196
	/**
197
	 * Clones <i>this</i> statistical measurement value. This is a shortcut that enables to create
198
	 * a new instance that differs only slightly from <i>this</i> statistical measurement value by
199
	 * modifying only some of the attributes.
200
	 *
201
	 * @see eu.etaxonomy.cdm.model.common.VersionableEntity#clone()
202
	 * @see java.lang.Object#clone()
203
	 */
204
	@Override
205
	public Object clone() {
206

    
207
		try {
208
			StatisticalMeasurementValue result = (StatisticalMeasurementValue)super.clone();
209

    
210
			//modifiers
211
			result.modifiers = new HashSet<DefinedTerm>();
212
			for (DefinedTerm modifier : getModifiers()){
213
				result.modifiers.add(modifier);
214
			}
215

    
216
			return result;
217
			//no changes to: value, type
218
		} catch (CloneNotSupportedException e) {
219
			logger.warn("Object does not implement cloneable");
220
			e.printStackTrace();
221
			return null;
222
		}
223
	}
224

    
225
}
(29-29/37)