Performed project cleanup.
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / common / TimePeriod.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.common;
11
12 import java.util.Calendar;
13
14 import javax.persistence.Embeddable;
15 import javax.persistence.Temporal;
16 import javax.persistence.TemporalType;
17 import javax.persistence.Transient;
18
19 import org.apache.log4j.Logger;
20
21 /**
22 * @author m.doering
23 * @version 1.0
24 * @created 08-Nov-2007 13:07:00
25 */
26 @Embeddable
27 public class TimePeriod implements Cloneable{
28 private static final Logger logger = Logger.getLogger(TimePeriod.class);
29
30
31 private Calendar start;
32 private Calendar end;
33
34
35 /**
36 * Factory method
37 * @return
38 */
39 public static TimePeriod NewInstance(){
40 return new TimePeriod();
41 }
42
43
44 /**
45 * Factory method
46 * @return
47 */
48 public static TimePeriod NewInstance(Calendar startDate){
49 return new TimePeriod(startDate);
50 }
51
52
53 /**
54 * Factory method
55 * @return
56 */
57 public static TimePeriod NewInstance(Calendar startDate, Calendar endDate){
58 return new TimePeriod(startDate, endDate);
59 }
60
61 /**
62 * Constructor
63 */
64 protected TimePeriod() {
65 super();
66 }
67 public TimePeriod(Calendar startDate) {
68 start=startDate;
69 }
70 public TimePeriod(Calendar startDate, Calendar endDate) {
71 start=startDate;
72 end=endDate;
73 }
74
75 @Temporal(TemporalType.TIMESTAMP)
76 public Calendar getStart() {
77 return start;
78 }
79 public void setStart(Calendar start) {
80 this.start = start;
81 }
82
83 @Temporal(TemporalType.TIMESTAMP)
84 public Calendar getEnd() {
85 return end;
86 }
87 public void setEnd(Calendar end) {
88 this.end = end;
89 }
90
91 @Transient
92 public String getYear(){
93 String result = "";
94 if (start != null){
95 result += String.valueOf(this.start.get(Calendar.YEAR));
96 if (end != null){
97 result += "-" + String.valueOf(this.end.get(Calendar.YEAR));
98 }
99 }else{
100 if (end != null){
101 result += String.valueOf(this.end.get(Calendar.YEAR));
102 }
103 }
104 return result;
105 }
106
107
108 //*********** CLONE **********************************/
109
110 /* (non-Javadoc)
111 * @see java.lang.Object#clone()
112 */
113 @Override
114 public TimePeriod clone() {
115 try {
116 TimePeriod result = (TimePeriod)super.clone();
117 result.setStart((Calendar)start.clone());
118 result.setEnd((Calendar)start.clone());
119 return result;
120 } catch (CloneNotSupportedException e) {
121 logger.warn("Clone not supported exception. Should never occurr !!");
122 return null;
123 }
124 }
125
126 }