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