Project

General

Profile

Download (3.89 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 javax.persistence.Entity;
14
import javax.xml.bind.annotation.XmlAccessType;
15
import javax.xml.bind.annotation.XmlAccessorType;
16
import javax.xml.bind.annotation.XmlElement;
17
import javax.xml.bind.annotation.XmlRootElement;
18
import javax.xml.bind.annotation.XmlType;
19

    
20
import org.apache.log4j.Logger;
21
import org.hibernate.envers.Audited;
22
import org.hibernate.search.annotations.Indexed;
23

    
24
import eu.etaxonomy.cdm.model.common.ExtendedTimePeriod;
25

    
26
/**
27
 * This class represents a temporal fact .
28
 * A temporal fact handles facts which primarily define certain time periods
29
 * like seasons.
30
 *
31
 * @author a.mueller
32
 * @since 29-Apr-2020
33
 */
34
@XmlAccessorType(XmlAccessType.FIELD)
35
@XmlType(name = "TemporalData", propOrder = {
36
    "period",
37
})
38
@XmlRootElement(name = "TemporalData")
39
@Entity
40
@Audited
41
@Indexed(index = "eu.etaxonomy.cdm.model.description.DescriptionElementBase")
42
public class TemporalData extends DescriptionElementBase {
43

    
44
    private static final long serialVersionUID = -1064249780729501786L;
45
    private static final Logger logger = Logger.getLogger(TemporalData.class);
46

    
47
    @XmlElement(name = "Period")
48
    private ExtendedTimePeriod period = ExtendedTimePeriod.NewExtendedInstance();
49

    
50
    public static TemporalData NewInstance(){
51
        TemporalData result = new TemporalData();
52
        return result;
53
    }
54

    
55
    /**
56
     * Creates a temporal fact with the given period.
57
     */
58
    public static TemporalData NewInstance(ExtendedTimePeriod period){
59
        TemporalData result = new TemporalData();
60
        result.setPeriod(period);
61
        return result;
62
    }
63

    
64
    public static TemporalData NewInstance(Feature feature){
65
        TemporalData result = new TemporalData();
66
        result.setFeature(feature);
67
        return result;
68
    }
69

    
70
    public static TemporalData NewInstance(Feature feature, ExtendedTimePeriod period){
71
        TemporalData result = new TemporalData();
72
        result.setFeature(feature);
73
        result.setPeriod(period);
74
        return result;
75
    }
76

    
77
// *************************** CONSTRUCTOR *************************************/
78

    
79
    /**
80
     * Class constructor: creates a new empty common name instance.
81
     * The corresponding {@link Feature feature} is set to {@link Feature#COMMON_NAME() COMMON_NAME}.
82
     */
83
    protected TemporalData(){}
84

    
85
// *************************** METHODS *****************************************/
86

    
87
    public ExtendedTimePeriod getPeriod() {
88
        return period;
89
    }
90
    public void setPeriod(ExtendedTimePeriod period) {
91
        this.period = period;
92
    }
93

    
94
//*********************************** CLONE *****************************************/
95

    
96
    /**
97
     * Clones <i>this</i> common name. This is a shortcut that enables to create
98
     * a new instance that differs only slightly from <i>this</i> common name by
99
     * modifying only some of the attributes.
100
     *
101
     * @see eu.etaxonomy.cdm.model.description.DescriptionElementBase#clone()
102
     * @see java.lang.Object#clone()
103
     */
104
    @Override
105
    public TemporalData clone() {
106

    
107
        try {
108
            TemporalData result = (TemporalData)super.clone();
109
            result.setPeriod(this.period.clone());
110
            return result;
111
            //no changes to ...
112
        } catch (CloneNotSupportedException e) {
113
            logger.warn("Object does not implement cloneable");
114
            e.printStackTrace();
115
            return null;
116
        }
117
    }
118

    
119
//*********************************** toString *****************************************/
120

    
121
    @Override
122
    public String toString(){
123
        if (period != null){
124
            return period.toString();
125
        }else{
126
            return super.toString();
127
        }
128
    }
129
}
(34-34/38)