gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / provider / DefaultTimeSerials.java @ 2443
History | View | Annotate | Download (8.38 KB)
1 |
/* 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.raster.impl.provider; |
23 |
|
24 |
import java.text.ParseException; |
25 |
import java.util.ArrayList; |
26 |
import java.util.Date; |
27 |
|
28 |
import org.gvsig.fmap.dal.coverage.datastruct.SerialInfo; |
29 |
import org.gvsig.fmap.dal.coverage.store.props.TimeSeries; |
30 |
import org.gvsig.raster.impl.datastruct.DefaultSerialInfo; |
31 |
import org.gvsig.timesupport.AbsoluteInstant; |
32 |
import org.gvsig.timesupport.AbsoluteInterval; |
33 |
import org.gvsig.timesupport.RelativeInstant; |
34 |
import org.gvsig.timesupport.RelativeInterval; |
35 |
import org.gvsig.timesupport.Time; |
36 |
/**
|
37 |
* DataStore serial information
|
38 |
*
|
39 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
40 |
*/
|
41 |
public class DefaultTimeSerials implements TimeSeries { |
42 |
private ArrayList<DefaultSerialInfo> serial = new ArrayList<DefaultSerialInfo>(); |
43 |
private String description = null; |
44 |
private String name = null; |
45 |
|
46 |
/**
|
47 |
* Constructor vacio.
|
48 |
*/
|
49 |
public DefaultTimeSerials() {
|
50 |
} |
51 |
|
52 |
/**
|
53 |
* Adds a SerialInfo to the list
|
54 |
* @param ser
|
55 |
*/
|
56 |
public void addSerialInfo(SerialInfo ser) { |
57 |
serial.add((DefaultSerialInfo)ser); |
58 |
} |
59 |
|
60 |
/**
|
61 |
* Clears the list of SerialInfo
|
62 |
*/
|
63 |
public void clearSerialInfoList() { |
64 |
serial.clear(); |
65 |
} |
66 |
|
67 |
/*
|
68 |
* (non-Javadoc)
|
69 |
* @see org.gvsig.fmap.dal.coverage.store.props.SerialInfo#selectSerial(java.lang.String)
|
70 |
*/
|
71 |
public void selectSerial(String name) { |
72 |
for (int i = 0; i < serial.size(); i++) { |
73 |
if(serial.get(i).getSerialName().compareTo(name) == 0) { |
74 |
this.name = serial.get(i).getSerialName();
|
75 |
this.description = serial.get(i).getDescription();
|
76 |
} |
77 |
} |
78 |
} |
79 |
|
80 |
/*
|
81 |
* (non-Javadoc)
|
82 |
* @see org.gvsig.fmap.dal.coverage.store.props.SerialInfo#selectSerial(int)
|
83 |
*/
|
84 |
public void selectSerial(int pos) { |
85 |
if (pos >= 0 && pos < serial.size()) { |
86 |
this.name = serial.get(pos).getSerialName();
|
87 |
this.description = serial.get(pos).getDescription();
|
88 |
} |
89 |
} |
90 |
|
91 |
/*
|
92 |
* (non-Javadoc)
|
93 |
* @see org.gvsig.fmap.dal.coverage.store.props.SerialInfo#getNumberOfSerials()
|
94 |
*/
|
95 |
public int getNumberOfSerials() { |
96 |
return serial.size();
|
97 |
} |
98 |
|
99 |
/**
|
100 |
* Gets the serial with then name selected
|
101 |
* @param name
|
102 |
* @return
|
103 |
*/
|
104 |
public DefaultSerialInfo getSerial(String name) { |
105 |
for (int i = 0; i < serial.size(); i++) { |
106 |
if(serial.get(i).getSerialName().compareTo(name) == 0) |
107 |
return serial.get(i);
|
108 |
} |
109 |
return null; |
110 |
} |
111 |
|
112 |
/**
|
113 |
* Gets the serial with then name selected
|
114 |
* @param uri
|
115 |
* @return
|
116 |
*/
|
117 |
public DefaultSerialInfo getSerial(int pos) { |
118 |
return serial.get(pos);
|
119 |
} |
120 |
|
121 |
/**
|
122 |
* Sets the serial information
|
123 |
* @param serial
|
124 |
*/
|
125 |
public void setSerial(ArrayList<DefaultSerialInfo> serial) { |
126 |
this.serial = serial;
|
127 |
} |
128 |
|
129 |
/*
|
130 |
* (non-Javadoc)
|
131 |
* @see org.gvsig.fmap.dal.coverage.store.props.SerialInfo#setDescription(java.lang.String)
|
132 |
*/
|
133 |
public void setDescription(String description) { |
134 |
this.description = description;
|
135 |
} |
136 |
|
137 |
/*
|
138 |
* (non-Javadoc)
|
139 |
* @see org.gvsig.fmap.dal.coverage.store.props.SerialInfo#getDescription()
|
140 |
*/
|
141 |
public String getDescription() { |
142 |
return description;
|
143 |
} |
144 |
|
145 |
/*
|
146 |
* (non-Javadoc)
|
147 |
* @see org.gvsig.fmap.dal.coverage.store.props.SerialInfo#getName()
|
148 |
*/
|
149 |
public String getName() { |
150 |
return name;
|
151 |
} |
152 |
|
153 |
/*
|
154 |
* (non-Javadoc)
|
155 |
* @see org.gvsig.fmap.dal.coverage.store.props.SerialInfo#setName(java.lang.String)
|
156 |
*/
|
157 |
public void setName(String name) { |
158 |
this.name = name;
|
159 |
} |
160 |
|
161 |
/*
|
162 |
* (non-Javadoc)
|
163 |
* @see org.gvsig.fmap.dal.coverage.store.props.SerialInfo#removeIntervals()
|
164 |
*/
|
165 |
public void removeIntervals() { |
166 |
serial.clear(); |
167 |
} |
168 |
|
169 |
/*
|
170 |
* (non-Javadoc)
|
171 |
* @see org.gvsig.fmap.dal.coverage.store.props.SerialInfo#createNewTimeInterval(java.lang.String, java.lang.String)
|
172 |
*/
|
173 |
public void createNewTimeInterval(String dateA, String dateB) throws ParseException { |
174 |
DefaultSerialInfo tInfo = new DefaultSerialInfo();
|
175 |
tInfo.setTimeType(DefaultSerialInfo.RANGES); |
176 |
tInfo.setDataType(SerialInfo.DATE); |
177 |
tInfo.addValue(dateA); |
178 |
tInfo.addValue(dateB); |
179 |
tInfo.setDescription(description); |
180 |
tInfo.setSerialName(name); |
181 |
serial.add(tInfo); |
182 |
} |
183 |
|
184 |
/*
|
185 |
* (non-Javadoc)
|
186 |
* @see org.gvsig.fmap.dal.coverage.store.props.SerialInfo#createNewTimeValue(java.lang.String)
|
187 |
*/
|
188 |
public void createNewTimeValue(String value) throws ParseException { |
189 |
DefaultSerialInfo tInfo = new DefaultSerialInfo();
|
190 |
tInfo.setTimeType(DefaultSerialInfo.SINGLE_VALUES); |
191 |
tInfo.setDataType(SerialInfo.DATE); |
192 |
tInfo.addValue(value); |
193 |
tInfo.setDescription(description); |
194 |
tInfo.setSerialName(name); |
195 |
serial.add(tInfo); |
196 |
} |
197 |
|
198 |
/*
|
199 |
* (non-Javadoc)
|
200 |
* @see org.gvsig.fmap.dal.coverage.store.props.SerialInfo#createNewTimeInterval(double, double)
|
201 |
*/
|
202 |
public void createNewTimeInterval(double a, double b) throws ParseException { |
203 |
DefaultSerialInfo tInfo = new DefaultSerialInfo();
|
204 |
tInfo.setTimeType(DefaultSerialInfo.RANGES); |
205 |
tInfo.setDataType(SerialInfo.NUMERIC); |
206 |
tInfo.addValue(a); |
207 |
tInfo.addValue(b); |
208 |
tInfo.setDescription(description); |
209 |
tInfo.setSerialName(name); |
210 |
serial.add(tInfo); |
211 |
} |
212 |
|
213 |
/*
|
214 |
* (non-Javadoc)
|
215 |
* @see org.gvsig.fmap.dal.coverage.store.props.SerialInfo#createNewTimeValue(double)
|
216 |
*/
|
217 |
public void createNewTimeValue(double value) throws ParseException { |
218 |
DefaultSerialInfo tInfo = new DefaultSerialInfo();
|
219 |
tInfo.setTimeType(DefaultSerialInfo.SINGLE_VALUES); |
220 |
tInfo.setDataType(SerialInfo.NUMERIC); |
221 |
tInfo.addValue(value); |
222 |
tInfo.setDescription(description); |
223 |
tInfo.setSerialName(name); |
224 |
serial.add(tInfo); |
225 |
} |
226 |
|
227 |
/*
|
228 |
* (non-Javadoc)
|
229 |
* @see org.gvsig.fmap.dal.coverage.store.props.TimeSerials#createNewTime(org.gvsig.timesupport.Time)
|
230 |
*/
|
231 |
public void createNewTime(Time time) throws ParseException { |
232 |
if(time instanceof RelativeInstant) { |
233 |
createNewTimeValue((double)((RelativeInstant)time).toMillis());
|
234 |
} |
235 |
if(time instanceof AbsoluteInstant) { |
236 |
AbsoluteInstant t = ((AbsoluteInstant)time); |
237 |
String dateA = t.getDays() + "/" + t.getMonths() + "/" + t.getYears() + "-" + t.getHours() + "/" + t.getMinutes() + "/" + t.getSeconds(); |
238 |
createNewTimeValue(dateA); |
239 |
} |
240 |
if(time instanceof AbsoluteInterval) { |
241 |
AbsoluteInstant t = ((AbsoluteInterval)time).getStart(); |
242 |
String dateA = t.getDays() + "/" + t.getMonths() + "/" + t.getYears() + "-" + t.getHours() + "/" + t.getMinutes() + "/" + t.getSeconds(); |
243 |
t = ((AbsoluteInterval)time).getEnd(); |
244 |
String dateB = t.getDays() + "/" + t.getMonths() + "/" + t.getYears() + "-" + t.getHours() + "/" + t.getMinutes() + "/" + t.getSeconds(); |
245 |
createNewTimeInterval(dateA, dateB); |
246 |
} |
247 |
if(time instanceof RelativeInterval) { |
248 |
RelativeInstant t = ((RelativeInterval)time).getStart(); |
249 |
double dateA = t.toMillis();
|
250 |
t = ((RelativeInterval)time).getEnd(); |
251 |
double dateB = t.toMillis();
|
252 |
createNewTimeInterval(dateA, dateB); |
253 |
} |
254 |
} |
255 |
|
256 |
@SuppressWarnings("unchecked") |
257 |
public ArrayList<?> getTimeList() { |
258 |
ArrayList result = new ArrayList(); |
259 |
|
260 |
for (int i = 0; i < serial.size(); i++) { |
261 |
DefaultSerialInfo dsi = serial.get(i); |
262 |
ArrayList<?> timeList = dsi.getTime();
|
263 |
|
264 |
if(timeList.get(0).getClass() == Date.class) { |
265 |
if(timeList.size() > 1) { |
266 |
long date1 = ((Date)timeList.get(0)).getTime(); |
267 |
long date2 = ((Date)timeList.get(timeList.size() - 1)).getTime(); |
268 |
long r = date1 + ((date2 - date1) / 2); |
269 |
Date newDate = new Date(r); |
270 |
result.add(newDate); |
271 |
} else {
|
272 |
result.add(timeList.get(0));
|
273 |
} |
274 |
} |
275 |
|
276 |
if(timeList.get(0).getClass() == Double.class) { |
277 |
if(timeList.size() > 1) { |
278 |
long date1 = ((Double)timeList.get(0)).longValue(); |
279 |
long date2 = ((Double)timeList.get(serial.size() - 1)).longValue(); |
280 |
long r = date1 + ((date2 - date1) / 2); |
281 |
result.add(new Double(r)); |
282 |
} else {
|
283 |
result.add(timeList.get(0));
|
284 |
} |
285 |
} |
286 |
} |
287 |
return result;
|
288 |
} |
289 |
} |