View Javadoc

1   /*
2    * $Id: Period.java,v 1.2 2007/05/24 12:26:17 oeuillot Exp $
3    */
4   package org.rcfaces.core.lang;
5   
6   import java.io.Serializable;
7   import java.util.Date;
8   
9   /**
10   * 
11   * @author Olivier Oeuillot (latest modification by $Author: oeuillot $)
12   * @version $Revision: 1.2 $ $Date: 2007/05/24 12:26:17 $
13   */
14  public class Period extends DefaultAdaptable implements Serializable,
15          Comparable {
16      private static final String REVISION = "$Revision: 1.2 $";
17  
18      private static final long serialVersionUID = -3717158186943282329L;
19  
20      private final Date start;
21  
22      private final Date end;
23  
24      public Period(Date start, Date end) {
25          this.start = start;
26          this.end = end;
27      }
28  
29      public final Date getEnd() {
30          return end;
31      }
32  
33      public final Date getStart() {
34          return start;
35      }
36  
37      public int hashCode() {
38          final int PRIME = 31;
39          int result = 1;
40          result = PRIME * result + ((end == null) ? 0 : end.hashCode());
41          result = PRIME * result + ((start == null) ? 0 : start.hashCode());
42          return result;
43      }
44  
45      public boolean equals(Object obj) {
46          if (this == obj)
47              return true;
48          if (obj == null)
49              return false;
50          if (getClass() != obj.getClass())
51              return false;
52          final Period other = (Period) obj;
53          if (end == null) {
54              if (other.end != null)
55                  return false;
56          } else if (!end.equals(other.end))
57              return false;
58          if (start == null) {
59              if (other.start != null)
60                  return false;
61          } else if (!start.equals(other.start))
62              return false;
63          return true;
64      }
65  
66      public int compareTo(Object o) {
67          return start.compareTo(((Period) o).getStart());
68      }
69  
70  }