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