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