Statistics
| Revision:

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 / datastruct / TimeInfo.java @ 162

History | View | Annotate | Download (4.19 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.datastruct;
23

    
24
import java.text.ParseException;
25
import java.text.SimpleDateFormat;
26
import java.util.ArrayList;
27
import java.util.Calendar;
28
import java.util.Date;
29

    
30
import org.gvsig.fmap.dal.coverage.store.RasterQuery;
31

    
32
/**
33
 * Time information
34
 * @author Nacho Brodin (nachobrodin@gmail.com)
35
 */
36
public class TimeInfo {
37
        public static final int    SINGLE_VALUE               = RasterQuery.SINGLE_VALUE;
38
        public static final int    MULTIPLE_VALUE             = RasterQuery.MULTIPLE_VALUE;
39
        public static final int    SINGLE_RANGE               = RasterQuery.SINGLE_RANGE;
40
        public static final int    MULTIPLE_RANGE             = RasterQuery.MULTIPLE_RANGE;
41
        
42
        private ArrayList<Date>    time                       = new ArrayList<Date>();
43
        private int                timeType                   = SINGLE_VALUE;
44
        private String             timeFormat                 = null;
45
        private String             serialName                 = null;
46
        private String             description                = null;
47
        
48
        public TimeInfo() {
49
                timeFormat = "dd/MM/yyyy-hh:mm:ss";
50
        }
51
        
52
        public TimeInfo(String timeFormat) {
53
                this.timeFormat = timeFormat;
54
        }
55
        
56
        public void load(String[] t, int type) throws ParseException {
57
                this.timeType = type;
58
                for (int i = 0; i < t.length; i++) 
59
                        addDate(t[i]);
60
        }
61
        
62
        /**
63
         * Gets the serial name
64
         * @return
65
         */
66
        public String getSerialName() {
67
                return serialName;
68
        }
69

    
70
        /**
71
         * Sets the serial name
72
         * @param serialName
73
         */
74
        public void setSerialName(String serialName) {
75
                this.serialName = serialName;
76
        }
77

    
78
        /**
79
         * Gets the list of dates
80
         * @return
81
         */
82
        public ArrayList<Date> getTime() {
83
                return time;
84
        }
85

    
86
        /**
87
         * Sets the list of dates
88
         * @return
89
         */
90
        public void setTime(ArrayList<Date> time) {
91
                this.time = time;
92
        }
93

    
94
        /**
95
         * Gets the time type
96
         * @return
97
         */
98
        public int getTimeType() {
99
                return timeType;
100
        }
101

    
102
        /**
103
         * Sets the time type
104
         * @param timeType
105
         */
106
        public void setTimeType(int timeType) {
107
                this.timeType = timeType;
108
        }
109
        
110
        /**
111
         * Sets the time type
112
         * @param timeType
113
         */
114
        public void setTimeType(String timeType) {
115
                if(timeType.compareTo("Single value") == 0)
116
                        this.timeType = 0;
117
                if(timeType.compareTo("Multiple value") == 0)
118
                        this.timeType = 1;
119
                if(timeType.compareTo("Single range") == 0)
120
                        this.timeType = 2;
121
                if(timeType.compareTo("Multiple range") == 0)
122
                        this.timeType = 3;
123
        }
124
        
125
        /**
126
         * Adds a new date in the array
127
         * @param dateStr
128
         * @throws ParseException
129
         */
130
        public void addDate(String dateStr) throws ParseException {
131
                SimpleDateFormat formatter = new SimpleDateFormat(timeFormat);
132
                Date date = null;
133
                try {
134
                        date = formatter.parse(dateStr);
135
                } catch (ParseException e) {
136
                        date = formatter.parse(dateStr + "-00:00:00");
137
                }
138
                
139
                System.out.println();
140
                this.time.add(date);
141
        }
142
        
143
        /**
144
         * Gets a string which represents a time information for that position.
145
         * Each position is or a single value or a part of a interval.
146
         * @param pos
147
         * @return
148
         */
149
        public String getTimeInfo(int pos) {
150
                SimpleDateFormat formatter = new SimpleDateFormat(timeFormat);
151
                return formatter.format(time.get(pos));
152
        }
153

    
154
        /**
155
         * Gets the description
156
         * @param description
157
         */
158
        public String getDescription() {
159
                return description;
160
        }
161

    
162
        /**
163
         * Sets the description
164
         * @return
165
         */
166
        public void setDescription(String description) {
167
                this.description = description;
168
        }
169
}