1 | /* |
---|
2 | * $Id: TimeRange.java,v 1.5 2003/08/22 23:02:40 dwd Exp $ |
---|
3 | * |
---|
4 | * This software is provided by NOAA for full, free and open release. It is |
---|
5 | * understood by the recipient/user that NOAA assumes no liability for any |
---|
6 | * errors contained in the code. Although this software is released without |
---|
7 | * conditions or restrictions in its use, it is expected that appropriate |
---|
8 | * credit be given to its author and to the National Oceanic and Atmospheric |
---|
9 | * Administration should the software be included by the recipient as an |
---|
10 | * element in other product development. |
---|
11 | */ |
---|
12 | |
---|
13 | package gov.noaa.pmel.util; |
---|
14 | |
---|
15 | /** |
---|
16 | * Contains minimum and maximum Time values. |
---|
17 | * |
---|
18 | * @author Donald Denbo |
---|
19 | * @version $Revision: 1.5 $, $Date: 2003/08/22 23:02:40 $ |
---|
20 | * @since sgt 1.0 |
---|
21 | * |
---|
22 | * @deprecated As of sgt 3.0, use {@link gov.noaa.pmel.util.SoTRange.Time SoTRange.Time} |
---|
23 | */ |
---|
24 | public class TimeRange implements java.io.Serializable { |
---|
25 | /** The range's first time */ |
---|
26 | public GeoDate start; |
---|
27 | /** The range's last time */ |
---|
28 | public GeoDate end; |
---|
29 | /** The range's time increment */ |
---|
30 | public GeoDate delta; |
---|
31 | /** |
---|
32 | * the Default constructor |
---|
33 | */ |
---|
34 | public TimeRange() { |
---|
35 | } |
---|
36 | /** |
---|
37 | * Constructor |
---|
38 | * |
---|
39 | * @param tstart first time |
---|
40 | * @param tend last time |
---|
41 | */ |
---|
42 | public TimeRange(GeoDate tstart,GeoDate tend) { |
---|
43 | this(tstart, tend, null); |
---|
44 | } |
---|
45 | public TimeRange(long start, long end) { |
---|
46 | this(new GeoDate(start), new GeoDate(end)); |
---|
47 | } |
---|
48 | /** |
---|
49 | * Constructor |
---|
50 | * |
---|
51 | * @param tstart first time |
---|
52 | * @param tend last time |
---|
53 | * @param delta time increment |
---|
54 | */ |
---|
55 | public TimeRange(GeoDate tstart,GeoDate tend, GeoDate tdelta) { |
---|
56 | this.start = tstart; |
---|
57 | this.end = tend; |
---|
58 | this.delta = tdelta; |
---|
59 | } |
---|
60 | public TimeRange(long start, long end, long delta) { |
---|
61 | this(new GeoDate(start), new GeoDate(end), new GeoDate(delta)); |
---|
62 | } |
---|
63 | /** |
---|
64 | * Adds the <code>TimeRange</code> object to this |
---|
65 | * <code>TimeRange</code>. The resulting <code>TimeRange</code> is |
---|
66 | * the smallest <code>TimeRange</code> that contains both the |
---|
67 | * origial <code>TimeRange</code> and the specified |
---|
68 | * <code>TimeRange</code>. |
---|
69 | */ |
---|
70 | public void add(TimeRange trange) { |
---|
71 | if(trange.start.before(start)) start = trange.start; |
---|
72 | if(trange.end.after(end)) end = trange.end; |
---|
73 | } |
---|
74 | /** |
---|
75 | * Test for equality. The start, end, and delta must all be equal |
---|
76 | * for equality. |
---|
77 | */ |
---|
78 | public boolean equals(TimeRange tr) { |
---|
79 | if(start != null && tr.start != null) { |
---|
80 | if(!start.equals(tr.start)) return false; |
---|
81 | } else { |
---|
82 | return false; |
---|
83 | } |
---|
84 | if(end != null && tr.end != null) { |
---|
85 | if(!end.equals(tr.end)) return false; |
---|
86 | } else { |
---|
87 | return false; |
---|
88 | } |
---|
89 | if(delta != null && tr.delta != null) { |
---|
90 | if(!delta.equals(tr.delta)) return false; |
---|
91 | } else { |
---|
92 | return false; |
---|
93 | } |
---|
94 | return true; |
---|
95 | } |
---|
96 | public String toString() { |
---|
97 | StringBuffer buf = new StringBuffer(50); |
---|
98 | buf.append("[").append(start).append(";").append(end); |
---|
99 | if(delta == null) { |
---|
100 | buf.append("]"); |
---|
101 | } else { |
---|
102 | buf.append(";").append(delta).append("]"); |
---|
103 | } |
---|
104 | return buf.toString(); |
---|
105 | } |
---|
106 | } |
---|