root/trunk/cdmlib/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/Distribution.java

Revision 13570, 6.9 kB (checked in by a.kohlbecker, 5 months ago)

harmonising whitespace tab->space

  • Property svn:keywords set to Id
Line 
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
10package eu.etaxonomy.cdm.model.description;
11
12import java.util.ArrayList;
13
14import javax.persistence.Entity;
15import javax.persistence.FetchType;
16import javax.persistence.ManyToOne;
17import javax.validation.constraints.NotNull;
18import javax.xml.bind.annotation.XmlAccessType;
19import javax.xml.bind.annotation.XmlAccessorType;
20import javax.xml.bind.annotation.XmlElement;
21import javax.xml.bind.annotation.XmlIDREF;
22import javax.xml.bind.annotation.XmlRootElement;
23import javax.xml.bind.annotation.XmlSchemaType;
24import javax.xml.bind.annotation.XmlType;
25
26import org.apache.log4j.Logger;
27import org.hibernate.envers.Audited;
28import org.hibernate.search.annotations.Indexed;
29
30import eu.etaxonomy.cdm.model.location.NamedArea;
31import eu.etaxonomy.cdm.validation.Level2;
32
33/**
34 * This class represents elementary distribution data for a {@link Taxon taxon}.
35 * Only {@link TaxonDescription taxon descriptions} may contain distributions.
36 * A distribution instance consist of a {@link NamedArea named area} and of a {@link PresenceAbsenceTermBase status}
37 * describing the absence or the presence of a taxon (like "extinct"
38 * or "introduced") in this named area.
39 * <P>
40 * This class corresponds partially to: <ul>
41 * <li> CodedDescriptionType according to the the SDD schema
42 * <li> Distribution according to the TDWG ontology
43 * </ul>
44 *
45 * @author m.doering
46 * @version 1.0
47 * @created 08-Nov-2007 13:06:21
48 */
49@XmlAccessorType(XmlAccessType.FIELD)
50@XmlType(name = "Distribution", propOrder = {
51    "area",
52    "status"
53})
54@XmlRootElement(name = "Distribution")
55@Entity
56@Audited
57@Indexed(index = "eu.etaxonomy.cdm.model.description.DescriptionElementBase")
58public class Distribution extends DescriptionElementBase implements Cloneable {
59    private static final long serialVersionUID = 8366462435651559730L;
60    @SuppressWarnings("unused")
61    private static final Logger logger = Logger.getLogger(Distribution.class);
62
63    @XmlElement(name = "NamedArea")
64    @XmlIDREF
65    @XmlSchemaType(name = "IDREF")
66    @ManyToOne(fetch = FetchType.LAZY)
67    @NotNull(groups = Level2.class)
68    private NamedArea area;
69
70    @XmlElement(name = "PresenceAbsenceStatus")
71    @XmlIDREF
72    @XmlSchemaType(name = "IDREF")
73    @ManyToOne(fetch = FetchType.LAZY)
74    @NotNull(groups = Level2.class)
75    private PresenceAbsenceTermBase<?> status;
76
77
78    /**
79     * Class constructor: creates a new empty distribution instance.
80     * The corresponding {@link Feature feature} is set to {@link Feature#DISTRIBUTION() DISTRIBUTION}.
81     */
82    protected Distribution(){
83        super();
84    }
85
86
87    /**
88     * Creates an empty distribution instance. The corresponding {@link Feature feature}
89     * is set to {@link Feature#DISTRIBUTION() DISTRIBUTION}.
90     *
91     * @see             #NewInstance(NamedArea, PresenceAbsenceTermBase)
92     */
93    public static Distribution NewInstance(){
94        Distribution result = new Distribution();
95        result.setFeature(Feature.DISTRIBUTION());
96        return result;
97    }
98
99    /**
100     * Creates a distribution instance with the given {@link NamedArea named area} and {@link PresenceAbsenceTermBase status}.
101     * The corresponding {@link Feature feature} is set to {@link Feature#DISTRIBUTION() DISTRIBUTION}.
102     *
103     * @param   area    the named area for the new distribution
104     * @param   status  the presence or absence term for the new distribution
105     * @see                             #NewInstance()
106     */
107    public static Distribution NewInstance(NamedArea area, PresenceAbsenceTermBase<?> status){
108        Distribution result = NewInstance();
109        result.setArea(area);
110        result.setStatus(status);
111        return result;
112    }
113
114    /**
115     * @deprecated Deprecated because {@link Feature feature} should always be {@link Feature#DISTRIBUTION() DISTRIBUTION}
116     * for all distribution instances and therefore it should not be changed.
117     */
118    /* (non-Javadoc)
119     * @see eu.etaxonomy.cdm.model.description.DescriptionElementBase#setFeature(eu.etaxonomy.cdm.model.description.Feature)
120     */
121    @Override
122    @Deprecated
123    public void setFeature(Feature feature) {
124        super.setFeature(feature);
125    }
126
127    /**
128     * Returns the {@link NamedArea named area} <i>this</i> distribution applies to.
129     */
130    public NamedArea getArea(){
131        return this.area;
132    }
133    /**
134     * @see     #getArea()
135     */
136    public void setArea(NamedArea area){
137        this.area = area;
138    }
139
140    /**
141     * Returns the {@link PresenceAbsenceTermBase presence or absence term} for <i>this</i> distribution.
142     */
143    public PresenceAbsenceTermBase<?> getStatus(){
144        return this.status;
145    }
146    /**
147     * @see     #getStatus()
148     */
149    public void setStatus(PresenceAbsenceTermBase<?> status){
150        this.status = status;
151    }
152
153    /**
154     * Special equal method for building an sorted distribution tree
155     * @param dist
156     * @return
157     */
158    public boolean equalsForTree(Distribution dist){
159        boolean result = false;
160        //same area level and area label
161        if (this.getArea().getLabel().compareTo(dist.getArea().getLabel()) == 0 &&
162                this.getArea().getLevel().getLabel().compareTo(dist.getArea().getLevel().getLabel()) == 0){
163            result = true;
164        }
165
166        return result;
167    }
168
169    /**
170     * Special function for building the sorted distribution tree. The function returns true
171     * if the sources of the two different objects are different
172     * @param dist
173     * @return
174     */
175    public boolean isDifferentSources(Distribution dist){
176        boolean result = false;
177        if(this.getSources().equals(dist.getSources())){
178            result = true;
179        }
180        return result;
181    }
182
183
184//*********************************** CLONE *****************************************/
185
186    /**
187     * Clones <i>this</i> distribution. This is a shortcut that enables to create
188     * a new instance that differs only slightly from <i>this</i> distribution by
189     * modifying only some of the attributes.
190     *
191     * @see eu.etaxonomy.cdm.model.description.DescriptionElementBase#clone()
192     * @see java.lang.Object#clone()
193     */
194    @Override
195    public Object clone() {
196
197        try {
198            Distribution result = (Distribution)super.clone();
199
200            return result;
201            //no changes to: area, status
202        } catch (CloneNotSupportedException e) {
203            logger.warn("Object does not implement cloneable");
204            e.printStackTrace();
205            return null;
206        }
207    }
208
209// ************************* to String ***************************************************/
210
211    /**
212     * Implementation of the toString() function
213     */
214    public String toString(){
215        String result = "null";
216        if (this.area != null){
217            result = area.getLabel().toString();
218        }
219        return result;
220    }
221
222}
Note: See TracBrowser for help on using the browser.