svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.timesupport / org.gvsig.timesupport.lib / org.gvsig.timesupport.lib.impl / src / main / java / org / gvsig / timesupport / impl / DefaultRelativeInstant.java @ 44136
History | View | Annotate | Download (9.02 KB)
1 | 42003 | jjdelcerro | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
||
4 | * of the Valencian Government (CIT)
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 2
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | */
|
||
22 | package org.gvsig.timesupport.impl; |
||
23 | |||
24 | import java.util.Date; |
||
25 | |||
26 | import org.gvsig.timesupport.AbsoluteInstant; |
||
27 | import org.gvsig.timesupport.Chronology; |
||
28 | import org.gvsig.timesupport.EditableRelativeInstant; |
||
29 | import org.gvsig.timesupport.Instant; |
||
30 | import org.gvsig.timesupport.RelativeInstant; |
||
31 | import org.gvsig.timesupport.RelativeInterval; |
||
32 | import org.gvsig.timesupport.Time; |
||
33 | |||
34 | /**
|
||
35 | * @author gvSIG team
|
||
36 | * @version $Id$
|
||
37 | */
|
||
38 | public class DefaultRelativeInstant implements RelativeInstant{ |
||
39 | private org.joda.time.DateTime jodaDateTime = null; |
||
40 | private Chronology chronology = null; |
||
41 | |||
42 | DefaultRelativeInstant(long instant, Chronology chronology) {
|
||
43 | super();
|
||
44 | this.jodaDateTime = new org.joda.time.DateTime(instant, ((DefaultChronology)chronology).getJodaType()); |
||
45 | this.chronology = chronology;
|
||
46 | } |
||
47 | |||
48 | DefaultRelativeInstant(Chronology chronology) { |
||
49 | super();
|
||
50 | this.jodaDateTime = new org.joda.time.DateTime(((DefaultChronology)chronology).getJodaType()); |
||
51 | this.chronology = chronology;
|
||
52 | } |
||
53 | |||
54 | DefaultRelativeInstant(Chronology chronology, org.joda.time.DateTime dateTime ) { |
||
55 | super();
|
||
56 | this.jodaDateTime = dateTime;
|
||
57 | this.chronology = chronology;
|
||
58 | } |
||
59 | |||
60 | DefaultRelativeInstant(Chronology chronology, org.joda.time.Period period ) { |
||
61 | super();
|
||
62 | this.jodaDateTime = new org.joda.time.DateTime(period.getYears(), period.getMonths(), period.getDays(), |
||
63 | period.getHours(), period.getMinutes(), period.getSeconds(), period.getMillis(), ((DefaultChronology)chronology).getJodaType()); |
||
64 | this.chronology = chronology;
|
||
65 | } |
||
66 | |||
67 | DefaultRelativeInstant(Chronology chronology, AbsoluteInstant absoluteInstant) { |
||
68 | super();
|
||
69 | this.jodaDateTime = new org.joda.time.DateTime(absoluteInstant.getYears(), absoluteInstant.getMonths(), absoluteInstant.getDays(), |
||
70 | absoluteInstant.getHours(), absoluteInstant.getMinutes(), absoluteInstant.getSeconds(), absoluteInstant.getMillis(), ((DefaultChronology)chronology).getJodaType()); |
||
71 | this.chronology = chronology;
|
||
72 | } |
||
73 | |||
74 | DefaultRelativeInstant(Date date, Chronology chronology) {
|
||
75 | super();
|
||
76 | this.jodaDateTime = new org.joda.time.DateTime(date, ((DefaultChronology)chronology).getJodaType()); |
||
77 | this.chronology = chronology;
|
||
78 | } |
||
79 | |||
80 | DefaultRelativeInstant(org.joda.time.DateTime jodaDateTime, Chronology chronology){ |
||
81 | super();
|
||
82 | this.jodaDateTime = jodaDateTime;
|
||
83 | this.chronology = chronology;
|
||
84 | } |
||
85 | |||
86 | DefaultRelativeInstant(int year, int monthOfYear, int dayOfMonth, int hourOfDay, |
||
87 | int minuteOfHour, int secondOfMinute, int millisOfSecond, Chronology chronology){ |
||
88 | super();
|
||
89 | this.jodaDateTime = new org.joda.time.DateTime(year, monthOfYear, dayOfMonth, hourOfDay, |
||
90 | minuteOfHour, secondOfMinute, millisOfSecond, ((DefaultChronology)chronology).getJodaType()); |
||
91 | this.chronology = chronology;
|
||
92 | } |
||
93 | |||
94 | public int getHourOfDay() { |
||
95 | return jodaDateTime.getHourOfDay();
|
||
96 | } |
||
97 | |||
98 | public int getMinuteOfHour() { |
||
99 | return jodaDateTime.getMinuteOfHour();
|
||
100 | } |
||
101 | |||
102 | public int getSecondOfMinute() { |
||
103 | return jodaDateTime.getSecondOfMinute();
|
||
104 | } |
||
105 | |||
106 | public int getMinuteOfDay() { |
||
107 | return jodaDateTime.getMinuteOfDay();
|
||
108 | } |
||
109 | |||
110 | public int getSecondOfDay() { |
||
111 | return jodaDateTime.getSecondOfDay();
|
||
112 | } |
||
113 | |||
114 | public EditableRelativeInstant getEditableCopy() {
|
||
115 | return new DefaultEditableRelativeInstant(jodaDateTime.toMutableDateTime(), chronology); |
||
116 | } |
||
117 | |||
118 | public long toMillis() { |
||
119 | return jodaDateTime.getMillis();
|
||
120 | } |
||
121 | |||
122 | public String toString(String pattern) { |
||
123 | return jodaDateTime.toString(pattern);
|
||
124 | } |
||
125 | 43623 | jjdelcerro | |
126 | public String toString() { |
||
127 | return jodaDateTime.toString();
|
||
128 | } |
||
129 | |||
130 | 42003 | jjdelcerro | public Date toDate() { |
131 | return jodaDateTime.toDate();
|
||
132 | } |
||
133 | |||
134 | public boolean isEqual(Instant instant) { |
||
135 | return jodaDateTime.isEqual(((DefaultRelativeInstant)instant).getJodaType());
|
||
136 | } |
||
137 | |||
138 | public boolean isAfter(Instant instant) { |
||
139 | return jodaDateTime.isAfter(((DefaultRelativeInstant)instant).getJodaType());
|
||
140 | } |
||
141 | |||
142 | public boolean isBefore(Instant instant) { |
||
143 | return jodaDateTime.isBefore(((DefaultRelativeInstant)instant).getJodaType());
|
||
144 | 43623 | jjdelcerro | } |
145 | 42003 | jjdelcerro | |
146 | public boolean equals(Object obj) { |
||
147 | if ((obj == null) || ((Time)obj).isAbsolute() || ((Time)obj).isInterval()){ |
||
148 | return false; |
||
149 | } |
||
150 | return ((DefaultRelativeInstant)obj).getJodaType().equals(jodaDateTime);
|
||
151 | } |
||
152 | |||
153 | public int getMillisOfSecond() { |
||
154 | return jodaDateTime.getMillisOfSecond();
|
||
155 | } |
||
156 | |||
157 | public Chronology getChronology() {
|
||
158 | return chronology;
|
||
159 | } |
||
160 | public int getYear() { |
||
161 | return jodaDateTime.getYear();
|
||
162 | } |
||
163 | |||
164 | public int getMonthOfYear() { |
||
165 | return jodaDateTime.getMonthOfYear();
|
||
166 | } |
||
167 | |||
168 | public int getWeekOfWeekyear() { |
||
169 | return jodaDateTime.getWeekOfWeekyear();
|
||
170 | } |
||
171 | |||
172 | public int getDayOfWeek() { |
||
173 | return jodaDateTime.getDayOfWeek();
|
||
174 | } |
||
175 | |||
176 | public int getDayOfMonth() { |
||
177 | return jodaDateTime.getDayOfMonth();
|
||
178 | } |
||
179 | |||
180 | public Object clone() throws CloneNotSupportedException { |
||
181 | return new DefaultRelativeInstant(chronology, new org.joda.time.DateTime(jodaDateTime)); |
||
182 | } |
||
183 | |||
184 | public boolean intersects(Time time) { |
||
185 | if (time.isRelative()){
|
||
186 | if (time.isInterval()){
|
||
187 | return (((RelativeInterval)time).toDurationMillis() == 0) && ((RelativeInterval)time).getStart().equals(this); |
||
188 | }else{
|
||
189 | return this.equals(time); |
||
190 | } |
||
191 | } |
||
192 | return true; |
||
193 | } |
||
194 | |||
195 | public boolean isRelative() { |
||
196 | return true; |
||
197 | } |
||
198 | |||
199 | public boolean isAbsolute() { |
||
200 | return false; |
||
201 | } |
||
202 | |||
203 | public boolean isInterval() { |
||
204 | return false; |
||
205 | } |
||
206 | |||
207 | public boolean isInstant() { |
||
208 | return true; |
||
209 | } |
||
210 | |||
211 | public int compareTo(Instant instant) { |
||
212 | return getJodaType().compareTo(((DefaultRelativeInstant)instant).getJodaType());
|
||
213 | } |
||
214 | |||
215 | |||
216 | org.joda.time.DateTime getJodaType() { |
||
217 | return jodaDateTime;
|
||
218 | } |
||
219 | |||
220 | |||
221 | |||
222 | // protected org.joda.time.Instant jodaInstant = null;
|
||
223 | // private static Chronology chronology =
|
||
224 | // TimeSupportLocator.getManager().getChronology(Chronology.ISO).withUTC();
|
||
225 | //
|
||
226 | // DefaultRelativeInstant(long instant) {
|
||
227 | // super();
|
||
228 | // this.jodaInstant = new org.joda.time.Instant(instant);
|
||
229 | // }
|
||
230 | //
|
||
231 | // DefaultRelativeInstant(Date date) {
|
||
232 | // super();
|
||
233 | // this.jodaInstant = new org.joda.time.Instant(date);
|
||
234 | // }
|
||
235 | //
|
||
236 | // DefaultRelativeInstant(DateTime dateTime) {
|
||
237 | // this(dateTime.toDate());
|
||
238 | // }
|
||
239 | //
|
||
240 | // DefaultRelativeInstant(org.joda.time.Instant instant) {
|
||
241 | // super();
|
||
242 | // this.jodaInstant = instant;
|
||
243 | // }
|
||
244 | //
|
||
245 | // public Date toDate() {
|
||
246 | // return jodaInstant.toDate();
|
||
247 | // }
|
||
248 | //
|
||
249 | // public int compareTo(DateTime dateTime) {
|
||
250 | // return jodaInstant.compareTo(((DefaultDateTime)dateTime).getJodaType());
|
||
251 | // }
|
||
252 | //
|
||
253 | // public DateTime toDateTime() {
|
||
254 | // return new DefaultDateTime(jodaInstant.toDateTime().toDate(), chronology);
|
||
255 | // }
|
||
256 | //
|
||
257 | // public long getMillis() {
|
||
258 | // return jodaInstant.getMillis();
|
||
259 | // }
|
||
260 | //
|
||
261 | // org.joda.time.Instant getJodaType() {
|
||
262 | // return jodaInstant;
|
||
263 | // }
|
||
264 | //
|
||
265 | // public boolean isEqual(RelativeInstant instant) {
|
||
266 | // return jodaInstant.isEqual(((DefaultRelativeInstant)instant).getJodaType());
|
||
267 | // }
|
||
268 | //
|
||
269 | // public boolean isAfter(RelativeInstant instant) {
|
||
270 | // return jodaInstant.isAfter(((DefaultRelativeInstant)instant).getJodaType());
|
||
271 | // }
|
||
272 | //
|
||
273 | // public boolean isBefore(RelativeInstant instant) {
|
||
274 | // return jodaInstant.isBefore(((DefaultRelativeInstant)instant).getJodaType());
|
||
275 | // }
|
||
276 | //
|
||
277 | // public String toString() {
|
||
278 | // return jodaInstant.toString();
|
||
279 | // }
|
||
280 | //
|
||
281 | // public boolean equals(Object obj) {
|
||
282 | // return ((DefaultRelativeInstant)obj).getJodaType().equals(jodaInstant);
|
||
283 | // }
|
||
284 | //
|
||
285 | // public Chronology getChronology() {
|
||
286 | // return chronology;
|
||
287 | // }
|
||
288 | |||
289 | |||
290 | } |