Revision 42671

View differences:

tags/org.gvsig.desktop-2.0.124/org.gvsig.desktop.library/org.gvsig.timesupport/org.gvsig.timesupport.lib/org.gvsig.timesupport.lib.impl/src/test/resources/README.txt
1
Put into this folder the resources needed by your test classes.
2

  
3
This folder is added to the Tests classpath, so you can load any resources 
4
through the ClassLoader.
5

  
6
By default, in this folder you can find an example of log4j configuration,
7
prepared to log messages through the console, so logging works when you
8
run your tests classes.
tags/org.gvsig.desktop-2.0.124/org.gvsig.desktop.library/org.gvsig.timesupport/org.gvsig.timesupport.lib/org.gvsig.timesupport.lib.impl/src/test/resources/log4j.xml
1
<?xml version="1.0" encoding="ISO-8859-1" ?>
2
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
3

  
4
<!-- 
5
Log4J configuration file for unit tests execution.
6
 -->
7
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
8

  
9
	<!-- Appender configuration to show logging messages through the console -->
10
	<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
11
		<layout class="org.apache.log4j.PatternLayout">
12
			<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n  %m%n" />
13
		</layout>
14
	</appender>
15

  
16
	<!-- 
17
	Activate logging messages of DEBUG level of higher only for the
18
	org.gvsig.tools packages.
19
	You can put full classes names or packages instead, to configure
20
	logging for all the classes and subpackages of the package.
21
	-->
22
	<category name="org.gvsig.tools">
23
		<priority value="DEBUG" />
24
	</category>
25
	<category name="org.gvsig.timesupport">
26
		<priority value="DEBUG" />
27
	</category>
28

  
29
	<!-- 
30
	By default, show only logging messages of INFO level or higher, 
31
	through the previously configured CONSOLE appender. 
32
	-->
33
	<root>
34
		<priority value="INFO" />
35
		<appender-ref ref="CONSOLE" />
36
	</root>
37
</log4j:configuration>
tags/org.gvsig.desktop-2.0.124/org.gvsig.desktop.library/org.gvsig.timesupport/org.gvsig.timesupport.lib/org.gvsig.timesupport.lib.impl/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.timesupport.impl.TimeSupportDefaultImplLibrary
tags/org.gvsig.desktop-2.0.124/org.gvsig.desktop.library/org.gvsig.timesupport/org.gvsig.timesupport.lib/org.gvsig.timesupport.lib.impl/src/main/java/org/gvsig/timesupport/impl/DefaultAbsoluteInstant.java
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.timesupport.impl;
23

  
24
import org.gvsig.timesupport.AbsoluteInstant;
25
import org.gvsig.timesupport.AbsoluteInstantType;
26
import org.gvsig.timesupport.AbsoluteInterval;
27
import org.gvsig.timesupport.AbsoluteIntervalType;
28
import org.gvsig.timesupport.Chronology;
29
import org.gvsig.timesupport.Duration;
30
import org.gvsig.timesupport.Instant;
31
import org.gvsig.timesupport.Time;
32

  
33
/**
34
 * @author gvSIG team
35
 * @version $Id$
36
 */
37
public class DefaultAbsoluteInstant implements AbsoluteInstant {
38
    private org.joda.time.Partial jodaPartial = null;
39
    private AbsoluteInstantType[] dateTimeFieldTypes = null;
40
    private Chronology chronology = null;
41
    private org.joda.time.DateTimeFieldType[] indexes = null;
42

  
43
    DefaultAbsoluteInstant(Chronology chronology) {
44
        super();    
45
        this.jodaPartial = new org.joda.time.Partial(((DefaultChronology)chronology).getJodaType());
46
        this.chronology = chronology;
47
        initializeIndexes();
48
    }
49

  
50
    DefaultAbsoluteInstant(Chronology chronology, org.joda.time.Partial jodaPartial) {
51
        super();    
52
        this.jodaPartial = jodaPartial;
53
        this.chronology = chronology;
54
        initializeIndexes();
55
    }
56

  
57
    DefaultAbsoluteInstant(DefaultAbsoluteInstantType dateTimeFieldType, int value, Chronology chronology) {
58
        super();	
59
        this.jodaPartial = new org.joda.time.Partial(dateTimeFieldType.getJodaType(), value, ((DefaultChronology)chronology).getJodaType());
60
        this.dateTimeFieldTypes = new DefaultAbsoluteInstantType[1];
61
        this.dateTimeFieldTypes[0] = dateTimeFieldType;
62
        this.chronology = chronology;
63
        initializeIndexes();
64
    }
65

  
66
    DefaultAbsoluteInstant(DefaultAbsoluteInstantType[] dateTimeFieldTypes, int[] values, Chronology chronology) {
67
        super();    
68
        org.joda.time.DateTimeFieldType[] jodaDateTimeFieldTypes = new org.joda.time.DateTimeFieldType[dateTimeFieldTypes.length];
69
        this.dateTimeFieldTypes = new DefaultAbsoluteInstantType[dateTimeFieldTypes.length];
70
        for (int i=0 ; i<dateTimeFieldTypes.length ; i++){
71
            this.dateTimeFieldTypes[i] = dateTimeFieldTypes[i];
72
            jodaDateTimeFieldTypes[i] = dateTimeFieldTypes[i].getJodaType();
73
        }
74
        this.jodaPartial = new org.joda.time.Partial(jodaDateTimeFieldTypes, values, ((DefaultChronology)chronology).getJodaType());
75
        this.chronology = chronology;
76
        initializeIndexes();
77
    }
78
    
79
    private void initializeIndexes(){
80
        indexes = new org.joda.time.DateTimeFieldType[8];
81
        org.joda.time.DateTimeFieldType[] dateTimeFieldTypes = jodaPartial.getFieldTypes();    
82
        for (int i=0 ; i<dateTimeFieldTypes.length ; i++){    
83
            if (dateTimeFieldTypes[i].equals(org.joda.time.DateTimeFieldType.year())){
84
                indexes[AbsoluteIntervalType.YEARS] = dateTimeFieldTypes[i];
85
            } else if (dateTimeFieldTypes[i].equals(org.joda.time.DateTimeFieldType.monthOfYear())){
86
                indexes[AbsoluteIntervalType.MONTHS] = dateTimeFieldTypes[i];
87
            } else if (dateTimeFieldTypes[i].equals(org.joda.time.DateTimeFieldType.weekOfWeekyear())){
88
                indexes[AbsoluteIntervalType.WEEKS] = dateTimeFieldTypes[i];
89
            } else if (dateTimeFieldTypes[i].equals(org.joda.time.DateTimeFieldType.dayOfMonth())){
90
                indexes[AbsoluteIntervalType.DAYS] = dateTimeFieldTypes[i];
91
            } else if (dateTimeFieldTypes[i].equals(org.joda.time.DateTimeFieldType.hourOfDay())){
92
                indexes[AbsoluteIntervalType.HOURS] = dateTimeFieldTypes[i];
93
            } else if (dateTimeFieldTypes[i].equals(org.joda.time.DateTimeFieldType.minuteOfHour())){
94
                indexes[AbsoluteIntervalType.MINUTES] = dateTimeFieldTypes[i];
95
            } else if (dateTimeFieldTypes[i].equals(org.joda.time.DateTimeFieldType.secondOfMinute())){
96
                indexes[AbsoluteIntervalType.SECONDS] = dateTimeFieldTypes[i];
97
            } else if (dateTimeFieldTypes[i].equals(org.joda.time.DateTimeFieldType.millisOfSecond())){
98
                indexes[AbsoluteIntervalType.MILLIS] = dateTimeFieldTypes[i];
99
            } 
100
        }         
101
    }
102

  
103
    public int size() {
104
        return jodaPartial.size();
105
    }
106

  
107
    public AbsoluteInstantType getFieldType(int index) {        
108
        return dateTimeFieldTypes[index];
109
    }
110

  
111
    public int getValue(int index) {       
112
        return jodaPartial.getValue(index);
113
    }
114

  
115
    public String toString() {      
116
        return jodaPartial.toString();
117
    } 
118

  
119
    public boolean equals(Object obj) {      
120
        if (((Time)obj).isRelative() || ((Time)obj).isInterval()){
121
            return false;
122
        }    
123
        return ((DefaultAbsoluteInstant)obj).getJodaType().equals(jodaPartial);
124
    }
125

  
126
    org.joda.time.Partial getJodaType() {
127
        return jodaPartial;
128
    }
129

  
130
    public boolean isAfter(Instant partial) {
131
        return jodaPartial.isAfter(((DefaultAbsoluteInstant)partial).getJodaType());
132
    }
133

  
134
    public boolean isBefore(Instant partial) {
135
        return jodaPartial.isBefore(((DefaultAbsoluteInstant)partial).getJodaType());
136
    }
137

  
138
    public boolean isEqual(Instant partial) {
139
        return jodaPartial.isEqual(((DefaultAbsoluteInstant)partial).getJodaType());
140
    }    
141

  
142
    public Chronology getChronology() {      
143
        return chronology;
144
    }
145

  
146
    public Object clone() throws CloneNotSupportedException {
147
        return new DefaultAbsoluteInstant(chronology, new org.joda.time.Partial(jodaPartial));
148
    }  
149
    
150
    public int getYears(){
151
        if (indexes[AbsoluteIntervalType.YEARS] == null){
152
            return 0;
153
        }
154
        return ((Integer)jodaPartial.get(indexes[AbsoluteIntervalType.YEARS])).intValue();
155
    }    
156

  
157
    public int getMonths(){
158
        if (indexes[AbsoluteIntervalType.MONTHS] == null){
159
            return 1;
160
        }
161
        return ((Integer)jodaPartial.get(indexes[AbsoluteIntervalType.MONTHS])).intValue();
162
    }
163
    
164
    public int getWeeks(){
165
        if (indexes[AbsoluteIntervalType.WEEKS] == null){
166
            return 0;
167
        }
168
        return ((Integer)jodaPartial.get(indexes[AbsoluteIntervalType.WEEKS])).intValue();
169
    }
170

  
171
    public int getDays(){
172
        if (indexes[AbsoluteIntervalType.DAYS] == null){
173
            return 1;
174
        }
175
        return ((Integer)jodaPartial.get(indexes[AbsoluteIntervalType.DAYS])).intValue();
176
    }
177

  
178
    public int getHours(){
179
        if (indexes[AbsoluteIntervalType.HOURS] == null){
180
            return 0;
181
        }
182
        return ((Integer)jodaPartial.get(indexes[AbsoluteIntervalType.HOURS])).intValue();
183
    }
184

  
185
    public int getMinutes(){
186
        if (indexes[AbsoluteIntervalType.MINUTES] == null){
187
            return 0;
188
        }
189
        return ((Integer)jodaPartial.get(indexes[AbsoluteIntervalType.MINUTES])).intValue();
190
    }
191

  
192
    public int getSeconds(){
193
        if (indexes[AbsoluteIntervalType.SECONDS] == null){
194
            return 0;
195
        }
196
        return ((Integer)jodaPartial.get(indexes[AbsoluteIntervalType.SECONDS])).intValue();
197
    }
198

  
199
    public int getMillis(){
200
        if (indexes[AbsoluteIntervalType.MILLIS] == null){
201
            return 0;
202
        }
203
        return ((Integer)jodaPartial.get(indexes[AbsoluteIntervalType.MILLIS])).intValue();
204
    }
205

  
206
    public boolean isRelative() {
207
        return false;
208
    }
209

  
210
    public boolean isAbsolute() {
211
        return true;
212
    }
213

  
214
    public boolean isInterval() {
215
        return false;
216
    }
217

  
218
    public boolean isInstant() { 
219
        return true;
220
    }
221

  
222
    public boolean intersects(Time time) {
223
        if (time.isAbsolute()){
224
            if (time.isInterval()){
225
                return (((AbsoluteInterval)time).getMillis() == 0) && ((AbsoluteInterval)time).getStart().equals(this);
226
            }else{
227
                return this.equals(time);
228
            }
229
        }
230
        return true;
231
    }
232

  
233
    public AbsoluteInstant minus(AbsoluteInterval interval) {
234
        return new DefaultAbsoluteInstant(chronology, jodaPartial.minus(((DefaultAbsoluteInterval)interval).getJodaType()));
235
    }
236

  
237
    public AbsoluteInstant plus(AbsoluteInterval interval) {
238
        return new DefaultAbsoluteInstant(chronology, jodaPartial.plus(((DefaultAbsoluteInterval)interval).getJodaType()));
239
    }
240

  
241
    public Duration toStandardDuration() {
242
        long millis = 0;                  
243
        millis += getYears() * DefaultAbsoluteInterval.MILLIS_BY_YEAR;
244
        millis += (getMonths() - 1) * DefaultAbsoluteInterval.MILLIS_BY_MONTH;
245
        millis += (getDays() - 1) * DefaultAbsoluteInterval.MILLIS_BY_YEAR;
246
        millis += getHours() * DefaultAbsoluteInterval.MILLIS_BY_HOUR;
247
        millis += getMinutes() * DefaultAbsoluteInterval.MILLIS_BY_MINUTE;
248
        millis += getSeconds() * DefaultAbsoluteInterval.MILLIS_BY_SECOND;       
249
        millis += getMillis();
250
        return new DefaultDuration(millis);    
251
    }    
252
}
253

  
tags/org.gvsig.desktop-2.0.124/org.gvsig.desktop.library/org.gvsig.timesupport/org.gvsig.timesupport.lib/org.gvsig.timesupport.lib.impl/src/main/java/org/gvsig/timesupport/impl/DefaultRelativeInterval.java
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.timesupport.impl;
23

  
24
import org.gvsig.timesupport.Chronology;
25
import org.gvsig.timesupport.Duration;
26
import org.gvsig.timesupport.Instant;
27
import org.gvsig.timesupport.RelativeInstant;
28
import org.gvsig.timesupport.RelativeInterval;
29
import org.gvsig.timesupport.Time;
30

  
31
/**
32
 * @author gvSIG team
33
 * @version $Id$
34
 */
35
public class DefaultRelativeInterval implements RelativeInterval {
36
    private org.joda.time.Interval jodaInterval = null;
37
    private Chronology chronology = null;
38

  
39
    DefaultRelativeInterval(long startInstant, long endInstant, Chronology chronology) {
40
        super();	
41
        this.jodaInterval = new org.joda.time.Interval(startInstant, endInstant, ((DefaultChronology)chronology).getJodaType());
42
        this.chronology = chronology;
43
    }
44

  
45
    DefaultRelativeInterval(RelativeInstant startInstant, RelativeInstant endInstant, Chronology chronology) {
46
        this(startInstant.toMillis(), endInstant.toMillis(), chronology);    
47
    }
48

  
49
    DefaultRelativeInterval(Chronology chronology, org.joda.time.Interval interval) {
50
        super();    
51
        this.jodaInterval = interval;
52
        this.chronology = chronology; 
53
    }
54

  
55
    public long toDurationMillis() {     
56
        return jodaInterval.toDurationMillis();
57
    }
58

  
59
    public boolean contains(RelativeInstant instant) {       
60
        return jodaInterval.contains(((DefaultRelativeInstant)instant).getJodaType());
61
    }
62

  
63
    public boolean isAfter(RelativeInstant instant) {
64
        return jodaInterval.isAfter(((DefaultRelativeInstant)instant).getJodaType());
65
    }
66

  
67
    public boolean isAfter(RelativeInterval interval) {
68
        return jodaInterval.isAfter(((DefaultRelativeInterval)interval).getJodaType());
69
    }
70

  
71
    public boolean isBefore(RelativeInstant instant) {
72
        return jodaInterval.isBefore(((DefaultRelativeInstant)instant).getJodaType());
73
    }
74

  
75
    public boolean isBefore(RelativeInterval interval) {
76
        return jodaInterval.isBefore(((DefaultRelativeInterval)interval).getJodaType());
77
    }
78

  
79
    public Duration toDuration() {    
80
        return new DefaultDuration(toDurationMillis());
81
    }
82

  
83
    org.joda.time.Interval getJodaType() {
84
        return jodaInterval;
85
    }    
86

  
87
    public String toString() {      
88
        return jodaInterval.toString();
89
    }     
90

  
91
    public boolean equals(Object obj) {      
92
        if ((obj == null) || ((Time)obj).isAbsolute() || ((Time)obj).isInstant()){
93
            return false;
94
        }
95
        return ((DefaultRelativeInterval)obj).getJodaType().equals(jodaInterval);
96
    }
97

  
98
    public boolean contains(RelativeInterval interval) {       
99
        return jodaInterval.contains(((DefaultRelativeInterval)interval).getJodaType());
100
    }
101

  
102
    public boolean overlaps(RelativeInterval interval) {
103
        return jodaInterval.overlaps(((DefaultRelativeInterval)interval).getJodaType());
104
    }     
105

  
106
    public Chronology getChronology() {      
107
        return chronology;
108
    }
109

  
110
    public Object clone() throws CloneNotSupportedException {
111
        return new DefaultRelativeInterval(chronology, new org.joda.time.Interval(jodaInterval));
112
    } 
113
    
114
    public RelativeInstant getStart(){
115
        return new DefaultRelativeInstant(chronology, jodaInterval.getStart());
116
    }
117
    
118
    public RelativeInstant getEnd(){
119
        return new DefaultRelativeInstant(chronology, jodaInterval.getEnd());
120
    }
121
    
122
    public boolean isRelative() {
123
        return true;
124
    }
125

  
126
    public boolean isAbsolute() {
127
        return false;
128
    }    
129

  
130
    public boolean isInterval() {
131
        return true;
132
    }
133

  
134
    public boolean isInstant() { 
135
        return false;
136
    }
137

  
138
    public boolean contains(Instant instant) {
139
        if (instant.isRelative()){
140
            return contains((RelativeInstant)instant);
141
        }
142
        return false;  
143
    }
144

  
145
    public boolean intersects(Time time) {
146
        if (time.isRelative()){
147
            if (time.isInterval()){
148
                return intersects((RelativeInterval)time);
149
            }else{
150
                return contains((RelativeInstant)time);
151
            }
152
        }
153
        return false;
154
    }
155

  
156
    public boolean intersects(RelativeInterval relativeInterval){
157
        return (this.getStart().isAfter((RelativeInstant)relativeInterval.getStart()) && this.getEnd().isBefore((RelativeInstant)relativeInterval.getStart())) ||
158
        (this.getEnd().isBefore((RelativeInstant)relativeInterval.getEnd()) && this.getEnd().isAfter((RelativeInstant)relativeInterval.getEnd()));
159
    }
160

  
161
    public Duration toStandardDuration() {
162
        return new DefaultDuration(jodaInterval.toDuration());
163
    }
164
}
165

  
tags/org.gvsig.desktop-2.0.124/org.gvsig.desktop.library/org.gvsig.timesupport/org.gvsig.timesupport.lib/org.gvsig.timesupport.lib.impl/src/main/java/org/gvsig/timesupport/impl/DefaultAbsoluteInstantType.java
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.timesupport.impl;
23

  
24
import org.gvsig.timesupport.AbsoluteInstantType;
25

  
26
/**
27
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodr&aacute;</a>
28
 */
29
public class DefaultAbsoluteInstantType implements AbsoluteInstantType{
30
	private org.joda.time.DateTimeFieldType jodaDateTimeFieldType = null;
31
	private int type = 0;
32
	
33
	DefaultAbsoluteInstantType(int type, org.joda.time.DateTimeFieldType dateTimeFieldType) {
34
		super();	
35
		this.type = type;
36
		this.jodaDateTimeFieldType = dateTimeFieldType;
37
	}
38
	
39
	org.joda.time.DateTimeFieldType getJodaType() {
40
		return jodaDateTimeFieldType;
41
	}
42

  
43
    public int getType() {      
44
        return type;
45
    }
46

  
47
    public String getName() {      
48
        return jodaDateTimeFieldType.getName();
49
    }    
50
    
51
    public String toString() {      
52
        return jodaDateTimeFieldType.toString();
53
    }    
54
}
55

  
tags/org.gvsig.desktop-2.0.124/org.gvsig.desktop.library/org.gvsig.timesupport/org.gvsig.timesupport.lib/org.gvsig.timesupport.lib.impl/src/main/java/org/gvsig/timesupport/impl/TimeSupportDefaultImplLibrary.java
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.timesupport.impl;
23

  
24
import org.gvsig.timesupport.AbsoluteInstantType;
25
import org.gvsig.timesupport.AbsoluteIntervalType;
26
import org.gvsig.timesupport.Chronology;
27
import org.gvsig.timesupport.DataTypes;
28
import org.gvsig.timesupport.TimeSupportLocator;
29
import org.gvsig.timesupport.TimeSupportManager;
30
import org.gvsig.tools.ToolsLocator;
31
import org.gvsig.tools.dataTypes.DataTypesManager;
32
import org.gvsig.tools.library.AbstractLibrary;
33
import org.gvsig.tools.library.LibraryException;
34

  
35
/**
36
 * Library for default implementation initialization and configuration.
37
 * 
38
 * @author gvSIG team
39
 * @version $Id$
40
 */
41
public class TimeSupportDefaultImplLibrary extends AbstractLibrary {
42
       
43
    @Override
44
    protected void doInitialize() throws LibraryException {
45
        TimeSupportLocator.registerManager(DefaultTimeSupportManager.class);
46
    }
47

  
48
    @Override
49
    protected void doPostInitialize() throws LibraryException {
50
        //Register the types
51
        DataTypesManager dataTypesManager = ToolsLocator.getDataTypesManager();
52
        dataTypesManager.addtype(DataTypes.INSTANT, "Instant", "Instant", DefaultRelativeInstant.class, null);
53
        dataTypesManager.addtype(DataTypes.INTERVAL, "Interval","Interval", DefaultRelativeInterval.class, null);
54
        
55
        // Do nothing
56
        TimeSupportManager timeSupportManager = TimeSupportLocator.getManager();
57
        
58
        //register AbsoluteInstantType 
59
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.ERA, org.joda.time.DateTimeFieldType.era()));
60
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.YEAR_OF_ERA, org.joda.time.DateTimeFieldType.yearOfEra()));
61
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.CENTURY_OF_ERA, org.joda.time.DateTimeFieldType.centuryOfEra()));
62
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.YEAR_OF_CENTURY, org.joda.time.DateTimeFieldType.yearOfCentury()));
63
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.YEAR, org.joda.time.DateTimeFieldType.year()));
64
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.DAY_OF_YEAR, org.joda.time.DateTimeFieldType.dayOfYear()));
65
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.MONTH_OF_YEAR, org.joda.time.DateTimeFieldType.monthOfYear()));
66
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.DAY_OF_MONTH, org.joda.time.DateTimeFieldType.dayOfMonth()));
67
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.WEEKYEAR_OF_CENTURY, org.joda.time.DateTimeFieldType.weekyearOfCentury()));
68
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.WEEKYEAR, org.joda.time.DateTimeFieldType.weekyear()));
69
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.WEEK_OF_WEEKYEAR, org.joda.time.DateTimeFieldType.weekOfWeekyear()));
70
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.DAY_OF_WEEK, org.joda.time.DateTimeFieldType.dayOfWeek()));
71
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.HALFDAY_OF_DAY, org.joda.time.DateTimeFieldType.halfdayOfDay()));
72
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.HOUR_OF_HALFDAY, org.joda.time.DateTimeFieldType.hourOfHalfday()));
73
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.CLOCKHOUR_OF_HALFDAY, org.joda.time.DateTimeFieldType.clockhourOfHalfday()));
74
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.CLOCKHOUR_OF_DAY, org.joda.time.DateTimeFieldType.clockhourOfDay()));
75
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.HOUR_OF_DAY, org.joda.time.DateTimeFieldType.hourOfDay()));
76
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.MINUTE_OF_DAY, org.joda.time.DateTimeFieldType.minuteOfDay()));
77
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.MINUTE_OF_HOUR, org.joda.time.DateTimeFieldType.minuteOfHour()));
78
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.SECOND_OF_DAY, org.joda.time.DateTimeFieldType.secondOfDay()));
79
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.SECOND_OF_MINUTE, org.joda.time.DateTimeFieldType.secondOfMinute()));
80
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.MILLIS_OF_DAY, org.joda.time.DateTimeFieldType.millisOfDay()));
81
        timeSupportManager.registerAbsoluteInstantType(new DefaultAbsoluteInstantType(AbsoluteInstantType.MILLIS_OF_SECOND, org.joda.time.DateTimeFieldType.millisOfSecond()));
82
       
83
        //Register period types
84
        timeSupportManager.registerAbsoluteIntervalType(new DefaultAbsoluteIntervalType(AbsoluteIntervalType.YEARS, org.joda.time.PeriodType.years()));
85
        timeSupportManager.registerAbsoluteIntervalType(new DefaultAbsoluteIntervalType(AbsoluteIntervalType.MONTHS, org.joda.time.PeriodType.months()));
86
        timeSupportManager.registerAbsoluteIntervalType(new DefaultAbsoluteIntervalType(AbsoluteIntervalType.WEEKS, org.joda.time.PeriodType.weeks()));
87
        timeSupportManager.registerAbsoluteIntervalType(new DefaultAbsoluteIntervalType(AbsoluteIntervalType.DAYS, org.joda.time.PeriodType.days()));
88
        timeSupportManager.registerAbsoluteIntervalType(new DefaultAbsoluteIntervalType(AbsoluteIntervalType.HOURS, org.joda.time.PeriodType.hours()));
89
        timeSupportManager.registerAbsoluteIntervalType(new DefaultAbsoluteIntervalType(AbsoluteIntervalType.MINUTES, org.joda.time.PeriodType.minutes()));
90
        timeSupportManager.registerAbsoluteIntervalType(new DefaultAbsoluteIntervalType(AbsoluteIntervalType.SECONDS, org.joda.time.PeriodType.seconds()));
91
        timeSupportManager.registerAbsoluteIntervalType(new DefaultAbsoluteIntervalType(AbsoluteIntervalType.MILLIS, org.joda.time.PeriodType.millis()));
92
                              
93
        //register Chronologies
94
        timeSupportManager.registerChronology(new DefaultChronology(Chronology.BUDDHIST, org.joda.time.chrono.BuddhistChronology.getInstance()));
95
        timeSupportManager.registerChronology(new DefaultChronology(Chronology.COPTIC, org.joda.time.chrono.CopticChronology.getInstance()));
96
        timeSupportManager.registerChronology(new DefaultChronology(Chronology.GJ, org.joda.time.chrono.GJChronology.getInstance()));
97
        timeSupportManager.registerChronology(new DefaultChronology(Chronology.GREGORIAN, org.joda.time.chrono.GregorianChronology.getInstance()));
98
        timeSupportManager.registerChronology(new DefaultChronology(Chronology.ISO, org.joda.time.chrono.ISOChronology.getInstance()));
99
        timeSupportManager.registerChronology(new DefaultChronology(Chronology.JULIAN, org.joda.time.chrono.JulianChronology.getInstance()));
100
        
101
        //Sets the default chronology
102
        timeSupportManager.setDefaultChronology(Chronology.GREGORIAN);     
103
        
104
        //Add some string patterns to parse relative instants
105
        timeSupportManager.addRelativeInstantPattern("yyyy:MM:dd HH:mm:ss");
106
        timeSupportManager.addRelativeInstantPattern("yyyy:MM:dd");
107
        timeSupportManager.addRelativeInstantPattern("yyyy/MM/dd HH:mm:ss");
108
        timeSupportManager.addRelativeInstantPattern("yyyy/MM/dd");
109
        timeSupportManager.addRelativeInstantPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
110
        timeSupportManager.addRelativeInstantPattern("yyyy-MM-dd HH:mm:ss"); 
111
        timeSupportManager.addRelativeInstantPattern("yyyy-MM-dd");   
112
    }
113

  
114
}
tags/org.gvsig.desktop-2.0.124/org.gvsig.desktop.library/org.gvsig.timesupport/org.gvsig.timesupport.lib/org.gvsig.timesupport.lib.impl/src/main/java/org/gvsig/timesupport/impl/DefaultAbsoluteInterval.java
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.timesupport.impl;
23

  
24
import java.util.ArrayList;
25
import java.util.List;
26

  
27
import org.slf4j.Logger;
28
import org.slf4j.LoggerFactory;
29

  
30
import org.gvsig.timesupport.AbsoluteInstant;
31
import org.gvsig.timesupport.AbsoluteInstantType;
32
import org.gvsig.timesupport.AbsoluteInstantTypeNotRegisteredException;
33
import org.gvsig.timesupport.AbsoluteInterval;
34
import org.gvsig.timesupport.AbsoluteIntervalType;
35
import org.gvsig.timesupport.AbsoluteIntervalTypeNotRegisteredException;
36
import org.gvsig.timesupport.Chronology;
37
import org.gvsig.timesupport.Duration;
38
import org.gvsig.timesupport.Instant;
39
import org.gvsig.timesupport.RelativeInstant;
40
import org.gvsig.timesupport.Time;
41
import org.gvsig.timesupport.TimeSupportLocator;
42
import org.gvsig.timesupport.TimeSupportManager;
43

  
44
/**
45
 * @author gvSIG team
46
 * @version $Id$
47
 */
48
public class DefaultAbsoluteInterval implements AbsoluteInterval{
49
    static final long MILLIS_BY_SECOND = 1000;
50
    static final long MILLIS_BY_MINUTE = MILLIS_BY_SECOND * 60;
51
    static final long MILLIS_BY_HOUR = MILLIS_BY_MINUTE * 60;
52
    static final long MILLIS_BY_DAY = MILLIS_BY_HOUR * 24;
53
    static final long MILLIS_BY_MONTH = MILLIS_BY_DAY * 30;
54
    static final long MILLIS_BY_YEAR = MILLIS_BY_MONTH * 365;
55

  
56
    private static Logger LOG = LoggerFactory.getLogger(DefaultAbsoluteInterval.class);
57

  
58
    private org.joda.time.Period jodaPeriod = null;
59
    private AbsoluteInstant startAbsoluteInstant = null;
60
    private AbsoluteInstant endAbsoluteInstant = null;
61
    private AbsoluteIntervalType[] absoluteIntervalTypes = null; 
62
    private Chronology chronology = null;
63

  
64
    private static final TimeSupportManager timeSupportManager = TimeSupportLocator.getManager(); 
65

  
66
    DefaultAbsoluteInterval(AbsoluteInstant startPartial, int years, int months, int weeks, int days,
67
        int hours, int minutes, int seconds, int millis, Chronology chronology) throws AbsoluteIntervalTypeNotRegisteredException{
68
        this(years, months, weeks, days, hours, minutes, seconds, millis, chronology);
69
        initilizePartials(((DefaultAbsoluteInstant)startPartial).getJodaType());
70
    }
71

  
72
    DefaultAbsoluteInterval(int years, int months, int weeks, int days,
73
        int hours, int minutes, int seconds, int millis, Chronology chronology) throws AbsoluteIntervalTypeNotRegisteredException{
74
        super();	
75
        this.jodaPeriod = new org.joda.time.Period(years, months, weeks, days, hours, minutes, seconds, millis);
76
        this.absoluteIntervalTypes = new AbsoluteIntervalType[8];
77
        this.absoluteIntervalTypes[0] = timeSupportManager.getAbsoluteIntervalType(AbsoluteIntervalType.YEARS);
78
        this.absoluteIntervalTypes[1] = timeSupportManager.getAbsoluteIntervalType(AbsoluteIntervalType.MONTHS);
79
        this.absoluteIntervalTypes[2] = timeSupportManager.getAbsoluteIntervalType(AbsoluteIntervalType.WEEKS);
80
        this.absoluteIntervalTypes[3] = timeSupportManager.getAbsoluteIntervalType(AbsoluteIntervalType.DAYS);
81
        this.absoluteIntervalTypes[4] = timeSupportManager.getAbsoluteIntervalType(AbsoluteIntervalType.HOURS);
82
        this.absoluteIntervalTypes[5] = timeSupportManager.getAbsoluteIntervalType(AbsoluteIntervalType.MINUTES);
83
        this.absoluteIntervalTypes[6] = timeSupportManager.getAbsoluteIntervalType(AbsoluteIntervalType.SECONDS);
84
        this.absoluteIntervalTypes[7] = timeSupportManager.getAbsoluteIntervalType(AbsoluteIntervalType.MILLIS); 
85
        this.chronology = chronology;
86
        initilizePartials();
87
    }    
88

  
89
    DefaultAbsoluteInterval(AbsoluteInstant startAbsoluteInstant, AbsoluteInstant endAbsoluteInstant, Chronology chronology) {
90
        super(); 
91
        this.jodaPeriod = new org.joda.time.Period(startAbsoluteInstant.toStandardDuration().getMillis(),
92
            endAbsoluteInstant.toStandardDuration().getMillis());         
93
            this.chronology = chronology;
94
            this.startAbsoluteInstant = startAbsoluteInstant;
95
            this.endAbsoluteInstant = endAbsoluteInstant;
96
            
97
//        int[] mergedTypes = mergeTypes(startAbsoluteInstant, endAbsoluteInstant);
98
//        try {
99
//            AbsoluteInstant startAbsoluteInstantAux = mergeTypes(mergedTypes, startAbsoluteInstant);
100
//            AbsoluteInstant endAbsoluteInstantAux = mergeTypes(mergedTypes, endAbsoluteInstant);
101
//            this.jodaPeriod = new org.joda.time.Period(((DefaultAbsoluteInstant)startAbsoluteInstantAux).getJodaType(), 
102
//                ((DefaultAbsoluteInstant)endAbsoluteInstantAux).getJodaType());
103
//            this.chronology = chronology;
104
//            this.startAbsoluteInstant = startAbsoluteInstantAux;
105
//            this.endAbsoluteInstant = endAbsoluteInstantAux;
106
//        } catch (AbsoluteInstantTypeNotRegisteredException e) {
107
//           LOG.error("Error creating the interval");
108
//        }        
109
    }
110

  
111
//    private AbsoluteInstant mergeTypes(int[] mergedTypes,
112
//        AbsoluteInstant absoluteInstant) throws AbsoluteInstantTypeNotRegisteredException{
113
//        int[] values = new int[mergedTypes.length];
114
//        for (int i=0 ; i<mergedTypes.length ; i++){
115
//            if (mergedTypes[i] == AbsoluteInstantType.YEAR){
116
//                values[i] = absoluteInstant.getYears();
117
//            }else if (mergedTypes[i] == AbsoluteInstantType.MONTH_OF_YEAR){
118
//                values[i] = absoluteInstant.getMonths();
119
//                if (values[i] == 0){
120
//                    values[i] = 1;
121
//                }
122
//            }else if (mergedTypes[i] == AbsoluteInstantType.DAY_OF_MONTH){
123
//                values[i] = absoluteInstant.getDays();
124
//                if (values[i] == 0){
125
//                    values[i] = 1;
126
//                }
127
//            }else if (mergedTypes[i] == AbsoluteInstantType.HOUR_OF_DAY){
128
//                values[i] = absoluteInstant.getHours();
129
//            }else if (mergedTypes[i] == AbsoluteInstantType.MINUTE_OF_HOUR){
130
//                values[i] = absoluteInstant.getMinutes();
131
//            }else if (mergedTypes[i] == AbsoluteInstantType.SECOND_OF_MINUTE){
132
//                values[i] = absoluteInstant.getSeconds();
133
//            }else if (mergedTypes[i] == AbsoluteInstantType.MILLIS_OF_SECOND){
134
//                values[i] = absoluteInstant.getMillis();
135
//            }else{
136
//                values[i] = 0;
137
//            }                  
138
//        }
139
//        return timeSupportManager.createAbsoluteInstant(mergedTypes, values, absoluteInstant.getChronology());
140
//    }
141
//
142
//    private int[] mergeTypes(AbsoluteInstant startAbsoluteInstant,
143
//        AbsoluteInstant endAbsoluteInstant) {
144
//        ArrayList types = new ArrayList();
145
//        for (int i=0 ; i<startAbsoluteInstant.size() ; i++){
146
//            types.add(startAbsoluteInstant.getFieldType(i).getType());
147
//        }
148
//        
149
//        for (int i=0 ; i<endAbsoluteInstant.size() ; i++){
150
//            int type = endAbsoluteInstant.getFieldType(i).getType();
151
//            int position = -1;
152
//            for (int j=0 ; j<types.size() ; j++){
153
//                int addedType = (Integer)types.get(j);
154
//                if (type < addedType){
155
//                    position = j;
156
//                    break;
157
//                }else if (type == addedType){
158
//                    position = -2;
159
//                }                
160
//            }
161
//            if (position > -1){
162
//                types.add(position, type);
163
//            }else if (position == -1){
164
//                types.add(type);
165
//            }
166
//        }        
167
//        
168
//        int[] mergedTypes = new int[types.size()];     
169
//        for (int i=0 ; i<types.size() ; i++){
170
//            mergedTypes[i] = (Integer)types.get(i);          
171
//        }
172
//        return mergedTypes;
173
//    }
174

  
175
    DefaultAbsoluteInterval(RelativeInstant startPeriod, RelativeInstant endPeriod, Chronology chronology) {
176
        super();    
177
        this.jodaPeriod = new org.joda.time.Period(((DefaultRelativeInstant)startPeriod).getJodaType(), 
178
            ((DefaultRelativeInstant)endPeriod).getJodaType());
179
        this.chronology = chronology;
180
        initilizePartials();
181
    }
182

  
183
    DefaultAbsoluteInterval(Chronology chronology, org.joda.time.Period period) {
184
        super();    
185
        this.jodaPeriod = period;
186
        this.chronology = chronology; 
187
        initilizePartials();
188
    }    
189

  
190
    DefaultAbsoluteInterval(AbsoluteInstant startPartial, AbsoluteInstant endPartial) {
191
        super(); 
192
        this.startAbsoluteInstant = startPartial;
193
        this.endAbsoluteInstant = endPartial;
194
        this.jodaPeriod = new org.joda.time.Period(endPartial.getYears() - startPartial.getYears(),
195
            0,
196
            endPartial.getMonths() - startPartial.getMonths(),
197
            endPartial.getDays() - startPartial.getDays(),
198
            endPartial.getHours() - startPartial.getHours(),
199
            endPartial.getMinutes() - startPartial.getMinutes(),
200
            endPartial.getSeconds() - startPartial.getSeconds(),
201
            endPartial.getMillis() - startPartial.getMillis());            
202
    }
203
   
204
    @SuppressWarnings({"unchecked" })
205
    private void initilizePartials(){
206
        this.startAbsoluteInstant = new DefaultAbsoluteInstant(chronology);        
207
        ArrayList types = new ArrayList();
208
        ArrayList values = new ArrayList();
209
        if (jodaPeriod.getYears() > 0){
210
            types.add(AbsoluteInstantType.YEAR);
211
            values.add(jodaPeriod.getYears());
212
        }
213
        if (jodaPeriod.getMonths() > 0){
214
            types.add(AbsoluteInstantType.MONTH_OF_YEAR);
215
            values.add(jodaPeriod.getMonths());
216
        }
217
        if (jodaPeriod.getWeeks() > 0){
218
            types.add(AbsoluteInstantType.WEEK_OF_WEEKYEAR);
219
            values.add(jodaPeriod.getWeeks());
220
        }
221
        if (jodaPeriod.getDays() > 0){
222
            types.add(AbsoluteInstantType.DAY_OF_MONTH);
223
            values.add(jodaPeriod.getDays());
224
        }
225
        if (jodaPeriod.getHours() > 0){
226
            types.add(AbsoluteInstantType.HOUR_OF_DAY);
227
            values.add(jodaPeriod.getHours());
228
        }
229
        if (jodaPeriod.getMinutes() > 0){
230
            types.add(AbsoluteInstantType.MINUTE_OF_HOUR);
231
            values.add(jodaPeriod.getMinutes());
232
        }
233
        if (jodaPeriod.getSeconds() > 0){
234
            types.add(AbsoluteInstantType.SECOND_OF_MINUTE);
235
            values.add(jodaPeriod.getSeconds());
236
        }
237
        if (jodaPeriod.getMillis() > 0){
238
            types.add(AbsoluteInstantType.MILLIS_OF_SECOND);
239
            values.add(jodaPeriod.getMillis());
240
        }        
241
        int[] nativeTypes = new int[types.size()];
242
        int[] nativeValues = new int[values.size()];
243
        for (int i=0 ; i<types.size() ; i++){
244
            nativeTypes[i] = (Integer)types.get(i);
245
            nativeValues[i] = (Integer)values.get(i);
246
        }
247
        try {
248
            this.endAbsoluteInstant = timeSupportManager.createAbsoluteInstant(nativeTypes, nativeValues, chronology);
249
        } catch (AbsoluteInstantTypeNotRegisteredException e) {
250
            LOG.error("Impossible to create the endPartial for a period", e);
251
        }  
252
    }
253

  
254
    @SuppressWarnings({ "unchecked" })
255
    private void initilizePartials(org.joda.time.Partial jodaPartial){
256
        this.startAbsoluteInstant = new DefaultAbsoluteInstant(chronology, jodaPartial);
257
        org.joda.time.DateTimeFieldType[] dateTimeFieldTypes = jodaPartial.getFieldTypes();
258
        int[] jodaValues = jodaPartial.getValues();
259
        ArrayList types = new ArrayList();
260
        ArrayList values = new ArrayList();
261
        if (jodaPeriod.getYears() > 0){
262
            types.add(AbsoluteInstantType.YEAR);
263
            values.add(jodaPeriod.getYears());
264
        }
265
        if (jodaPeriod.getMonths() > 0){
266
            types.add(AbsoluteInstantType.MONTH_OF_YEAR);
267
            values.add(jodaPeriod.getMonths());
268
        }
269
        if (jodaPeriod.getDays() > 0){
270
            types.add(AbsoluteInstantType.DAY_OF_MONTH);
271
            values.add(jodaPeriod.getDays());
272
        }
273
        if (jodaPeriod.getHours() > 0){
274
            types.add(AbsoluteInstantType.HOUR_OF_DAY);
275
            values.add(jodaPeriod.getHours());
276
        }
277
        if (jodaPeriod.getMinutes() > 0){
278
            types.add(AbsoluteInstantType.MINUTE_OF_HOUR);
279
            values.add(jodaPeriod.getMinutes());
280
        }
281
        if (jodaPeriod.getSeconds() > 0){
282
            types.add(AbsoluteInstantType.SECOND_OF_MINUTE);
283
            values.add(jodaPeriod.getSeconds());
284
        }
285
        if (jodaPeriod.getMillis() > 0){
286
            types.add(AbsoluteInstantType.MILLIS_OF_SECOND);
287
            values.add(jodaPeriod.getMillis());
288
        }    
289
        for (int i=0 ; i<dateTimeFieldTypes.length ; i++){           
290
            if (dateTimeFieldTypes[i].equals(org.joda.time.DateTimeFieldType.year())){
291
                initializePartialsIteration(types, values, jodaValues[i], AbsoluteInstantType.YEAR);
292
            } else if (dateTimeFieldTypes[i].equals(org.joda.time.DateTimeFieldType.monthOfYear())){
293
                initializePartialsIteration(types, values, jodaValues[i], AbsoluteInstantType.MONTH_OF_YEAR);
294
            } else if (dateTimeFieldTypes[i].equals(org.joda.time.DateTimeFieldType.dayOfMonth())){
295
                initializePartialsIteration(types, values, jodaValues[i], AbsoluteInstantType.DAY_OF_MONTH);
296
            } else if (dateTimeFieldTypes[i].equals(org.joda.time.DateTimeFieldType.hourOfDay())){
297
                initializePartialsIteration(types, values, jodaValues[i], AbsoluteInstantType.HOUR_OF_DAY);
298
            } else if (dateTimeFieldTypes[i].equals(org.joda.time.DateTimeFieldType.minuteOfHour())){
299
                initializePartialsIteration(types, values, jodaValues[i], AbsoluteInstantType.MINUTE_OF_HOUR);
300
            } else if (dateTimeFieldTypes[i].equals(org.joda.time.DateTimeFieldType.secondOfMinute())){
301
                initializePartialsIteration(types, values, jodaValues[i], AbsoluteInstantType.SECOND_OF_MINUTE);
302
            } else if (dateTimeFieldTypes[i].equals(org.joda.time.DateTimeFieldType.millisOfSecond())){
303
                initializePartialsIteration(types, values, jodaValues[i], AbsoluteInstantType.MILLIS_OF_SECOND);
304
            } 
305
        } 
306
        int[] nativeTypes = new int[types.size()];
307
        int[] nativeValues = new int[values.size()];
308
        for (int i=0 ; i<types.size() ; i++){
309
            nativeTypes[i] = (Integer)types.get(i);
310
            nativeValues[i] = (Integer)values.get(i);
311
        }
312
        try {
313
            this.endAbsoluteInstant = timeSupportManager.createAbsoluteInstant(nativeTypes, nativeValues, chronology);
314
        } catch (AbsoluteInstantTypeNotRegisteredException e) {
315
            LOG.error("Impossible to create the endPartial for a period", e);
316
        }  
317
    }
318

  
319
    @SuppressWarnings({ "unchecked" })
320
    private void initializePartialsIteration(List types, List values, int jodaValue, int dateTimefieldtype){
321
        boolean found = false;
322
        for (int j=0 ; j<types.size() ; j++){
323
            if (types.get(j).equals(dateTimefieldtype)){
324
                int value = (Integer)values.get(j);
325
                values.remove(j);
326
                values.add(j, value + jodaValue);
327
                found = true;
328
                break;
329
            }
330
        }
331
        if (!found){
332
            types.add(dateTimefieldtype);
333
            values.add(jodaValue);
334
        }
335
    }
336

  
337
    public int size() {       
338
        return jodaPeriod.size();
339
    }
340

  
341
    public AbsoluteIntervalType getFieldType(int index) {       
342
        return absoluteIntervalTypes[index];
343
    }
344

  
345
    public int getValue(int index) {      
346
        return jodaPeriod.getValue(index);
347
    } 
348

  
349
    public String toString() {      
350
        return jodaPeriod.toString();
351
    } 
352

  
353
    public boolean equals(Object obj) {      
354
        if (((Time)obj).isRelative() || ((Time)obj).isInstant()){
355
            return false;
356
        }          
357
        return ((DefaultAbsoluteInterval)obj).getJodaType().equals(jodaPeriod);
358
    }
359

  
360
    org.joda.time.Period getJodaType() {
361
        return jodaPeriod;
362
    }   
363

  
364
    public Chronology getChronology() {      
365
        return chronology;
366
    }
367

  
368
    public int getYears() {
369
        return jodaPeriod.getYears();
370
    }
371

  
372
    public int getMonths() {
373
        return jodaPeriod.getMonths();
374
    }
375

  
376
    public int getWeeks() {
377
        return jodaPeriod.getWeeks();
378
    }
379

  
380
    public int getDays() {
381
        return jodaPeriod.getDays();
382
    }
383

  
384
    public int getHours() {
385
        return jodaPeriod.getHours();
386
    }
387

  
388
    public int getMinutes() {
389
        return jodaPeriod.getMinutes();
390
    }
391

  
392
    public int getSeconds() {
393
        return jodaPeriod.getSeconds();
394
    }
395

  
396
    public int getMillis() {
397
        return jodaPeriod.getMillis();
398
    }
399

  
400
    public boolean isAfter(AbsoluteInterval period) {
401
        return jodaPeriod.getMillis() > period.getMillis();
402
    }
403

  
404
    public boolean isBefore(AbsoluteInterval period) {
405
        return jodaPeriod.getMillis() < period.getMillis();
406
    }    
407

  
408
    public Object clone() throws CloneNotSupportedException {
409
        return new DefaultAbsoluteInterval(chronology, new org.joda.time.Period(jodaPeriod));
410
    }
411

  
412
    public AbsoluteInstant getStart(){
413
        return startAbsoluteInstant;
414
    }
415

  
416
    public AbsoluteInstant getEnd(){
417
        return endAbsoluteInstant;
418
    }
419

  
420
    public boolean isRelative() {
421
        return false;
422
    }
423

  
424
    public boolean isAbsolute() {
425
        return true;
426
    }    
427

  
428
    public boolean isInterval() {
429
        return true;
430
    }
431

  
432
    public boolean isInstant() { 
433
        return false;
434
    }
435

  
436
    public boolean intersects(Time time) {
437
        if (time.isAbsolute()){
438
            if (time.isInterval()){
439
                return intersects((AbsoluteInterval)time);
440
            }else{
441
                return contains((AbsoluteInstant)time);
442
            }
443
        }
444
        return true;
445
    }
446

  
447
    public boolean intersects(AbsoluteInterval absoluteInsterInterval){
448
        return (this.getStart().isAfter(absoluteInsterInterval.getStart()) && this.getEnd().isBefore(absoluteInsterInterval.getStart())) ||
449
        (this.getEnd().isBefore(absoluteInsterInterval.getEnd()) && this.getEnd().isAfter(absoluteInsterInterval.getEnd()));
450
    }
451

  
452
    public boolean contains(Instant instant) {
453
        if (instant.isAbsolute()){
454
            return this.getMillis() >= ((AbsoluteInstant)instant).getMillis();
455
        }
456
        return false;  
457
    }
458

  
459
    public Duration toStandardDuration() {
460
        long millis = 0;                  
461
        millis += getYears() * MILLIS_BY_YEAR;
462
        millis += getMonths() * MILLIS_BY_MONTH;
463
        millis += getDays() * MILLIS_BY_YEAR;
464
        millis += getHours() * MILLIS_BY_HOUR;
465
        millis += getMinutes() * MILLIS_BY_MINUTE;
466
        millis += getSeconds() * MILLIS_BY_SECOND;       
467
        millis += getMillis();
468
        return new DefaultDuration(millis);
469
    }
470
}
471

  
tags/org.gvsig.desktop-2.0.124/org.gvsig.desktop.library/org.gvsig.timesupport/org.gvsig.timesupport.lib/org.gvsig.timesupport.lib.impl/src/main/java/org/gvsig/timesupport/impl/DefaultChronology.java
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.timesupport.impl;
23

  
24
import org.gvsig.timesupport.Chronology;
25

  
26

  
27

  
28
/**
29
 * @author gvSIG Team
30
 * @version $Id$
31
 *
32
 */
33
public class DefaultChronology implements Chronology {
34
    private org.joda.time.Chronology jodaChronology = null;
35
    private Chronology withUTC= null;
36
    private int type = 0;
37
    
38
    DefaultChronology(int type, org.joda.time.Chronology dateTimeFieldType) {
39
        super();    
40
        this.type = type;
41
        this.jodaChronology = dateTimeFieldType;        
42
    }
43
    
44
    org.joda.time.Chronology getJodaType() {      
45
        return jodaChronology;
46
    } 
47

  
48
    public int getType() {
49
        return type;
50
    }
51

  
52
    public Chronology withUTC() {       
53
        if (withUTC == null){
54
            withUTC = new DefaultChronology(type, jodaChronology.withUTC());
55
        }
56
        return withUTC;
57
    }    
58
}
tags/org.gvsig.desktop-2.0.124/org.gvsig.desktop.library/org.gvsig.timesupport/org.gvsig.timesupport.lib/org.gvsig.timesupport.lib.impl/src/main/java/org/gvsig/timesupport/impl/DefaultAbsoluteIntervalType.java
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.timesupport.impl;
23

  
24
import org.gvsig.timesupport.AbsoluteIntervalType;
25

  
26
/**
27
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodr&aacute;</a>
28
 */
29
public class DefaultAbsoluteIntervalType implements AbsoluteIntervalType{
30
	private org.joda.time.PeriodType jodaPeriodType = null;
31
	private int type = 0;
32
	
33
	DefaultAbsoluteIntervalType(int type, org.joda.time.PeriodType jodaPeriodType) {
34
		super();	
35
		this.type = type;
36
		this.jodaPeriodType = jodaPeriodType;
37
	}
38
	
39
	org.joda.time.PeriodType getJodaType() {
40
		return jodaPeriodType;
41
	}
42

  
43
    public int getType() {      
44
        return type;
45
    }
46

  
47
    public String getName() {      
48
        return jodaPeriodType.getName();
49
    }    
50
    
51
    public String toString() {      
52
        return jodaPeriodType.toString();
53
    }    
54
}
55

  
tags/org.gvsig.desktop-2.0.124/org.gvsig.desktop.library/org.gvsig.timesupport/org.gvsig.timesupport.lib/org.gvsig.timesupport.lib.impl/src/main/java/org/gvsig/timesupport/impl/DefaultDuration.java
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.timesupport.impl;
23

  
24
import org.gvsig.timesupport.Duration;
25

  
26
/**
27
 * @author gvSIG team
28
 * @version $Id$
29
 */
30
public class DefaultDuration implements Duration {
31
	private org.joda.time.Duration jodaDuration = null;
32

  
33
	DefaultDuration(long duration) {
34
		super();	
35
		this.jodaDuration = new org.joda.time.Duration(duration);
36
	}	
37
	
38
	DefaultDuration(org.joda.time.Duration jodaDuration) {
39
        super();    
40
        this.jodaDuration = jodaDuration;
41
    }   
42
    
43
	DefaultDuration(long startInstant, long endInstant) {
44
		super();	
45
		this.jodaDuration = new org.joda.time.Duration(startInstant, endInstant);
46
	}
47

  
48
    public long getMillis() {
49
        return jodaDuration.getMillis();
50
    }
51
    
52
    public String toString() {      
53
        return jodaDuration.toString();
54
    }  
55
    
56
    public boolean equals(Object obj) {      
57
        return ((DefaultDuration)obj).getJodaType().equals(jodaDuration);
58
    }
59

  
60
    org.joda.time.Duration getJodaType() {      
61
        return jodaDuration;
62
    } 
63
}
64

  
tags/org.gvsig.desktop-2.0.124/org.gvsig.desktop.library/org.gvsig.timesupport/org.gvsig.timesupport.lib/org.gvsig.timesupport.lib.impl/src/main/java/org/gvsig/timesupport/impl/DefaultEditableRelativeInstant.java
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.timesupport.impl;
23

  
24
import org.joda.time.MutableDateTime;
25

  
26
import org.gvsig.timesupport.Chronology;
27
import org.gvsig.timesupport.EditableRelativeInstant;
28

  
29

  
30
/**
31
 * @author gvSIG Team
32
 * @version $Id$
33
 *
34
 */
35
public class DefaultEditableRelativeInstant extends DefaultRelativeInstant implements EditableRelativeInstant{
36
    private org.joda.time.MutableDateTime jodaMutableDateTime;
37

  
38
    DefaultEditableRelativeInstant(MutableDateTime jodaMutableDateTime, Chronology chronology) {
39
        super(jodaMutableDateTime.getMillis(), chronology);
40
        this.jodaMutableDateTime = jodaMutableDateTime;       
41
    }
42

  
43
    public void setTime(int hour, int minuteOfHour, int secondOfMinute,
44
        int millisOfSecond) {
45
        jodaMutableDateTime.setTime(hour, minuteOfHour, secondOfMinute, millisOfSecond); 
46
    }
47

  
48
    public void setDate(int year, int monthOfYear, int dayOfMonth) {
49
        jodaMutableDateTime.setDate(year, monthOfYear, dayOfMonth);        
50
    }
51

  
52
    public void addYears(int years) {
53
        jodaMutableDateTime.addYears(years);
54
    }
55

  
56
    public void addDays(int days) {
57
        jodaMutableDateTime.addDays(days);        
58
    }
59

  
60
    public void addHours(int hours) {
61
        jodaMutableDateTime.addHours(hours);        
62
    }
63

  
64
    public void addMinutes(int minutes) {
65
        jodaMutableDateTime.addMinutes(minutes);        
66
    }
67

  
68
    public void addSeconds(int seconds) {
69
        jodaMutableDateTime.addSeconds(seconds);        
70
    }
71

  
72
    public void addMillis(int millis) {
73
        jodaMutableDateTime.addMillis(millis);        
74
    }  
75
        
76
    public String toString() {      
77
        return jodaMutableDateTime.toString();
78
    }  
79
}
tags/org.gvsig.desktop-2.0.124/org.gvsig.desktop.library/org.gvsig.timesupport/org.gvsig.timesupport.lib/org.gvsig.timesupport.lib.impl/src/main/java/org/gvsig/timesupport/impl/DefaultTimeSupportManager.java
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.timesupport.impl;
23

  
24
import java.text.ParseException;
25
import java.text.SimpleDateFormat;
26
import java.util.ArrayList;
27
import java.util.Date;
28
import java.util.HashMap;
29
import java.util.List;
30
import java.util.Map;
31

  
32
import org.slf4j.Logger;
33
import org.slf4j.LoggerFactory;
34

  
35
import org.gvsig.timesupport.AbsoluteInstant;
36
import org.gvsig.timesupport.AbsoluteInstantType;
37
import org.gvsig.timesupport.AbsoluteInstantTypeNotRegisteredException;
38
import org.gvsig.timesupport.AbsoluteInterval;
39
import org.gvsig.timesupport.AbsoluteIntervalType;
40
import org.gvsig.timesupport.AbsoluteIntervalTypeNotRegisteredException;
41
import org.gvsig.timesupport.Chronology;
42
import org.gvsig.timesupport.RelativeInstant;
43
import org.gvsig.timesupport.RelativeInterval;
44
import org.gvsig.timesupport.TimeSupportManager;
45
import org.gvsig.timesupport.animation.TimeAnimation;
46
import org.gvsig.timesupport.impl.animation.TimeAnimationImpl;
47

  
48
/**
49
 * Default {@link TimeSupportManager} implementation.
50
 * 
51
 * @author gvSIG Team
52
 * @version $Id$
53
 */
54
@SuppressWarnings("unchecked")
55
public class DefaultTimeSupportManager implements TimeSupportManager {
56
    private Logger LOG = LoggerFactory.getLogger(DefaultTimeSupportManager.class);
57
	private Map absoluteInstantTypes = new HashMap();
58
    private Map chronologyes = new HashMap();
59
    private Map absoluteIntervalTypes = new HashMap();
60

  
61
    private Chronology defaultChronology = null;
62

  
63
    private List relativeInstantPatterns = null;
64

  
65
    public DefaultTimeSupportManager(){
66
        relativeInstantPatterns = new ArrayList();
67
    }
68

  
69
    public void registerAbsoluteInstantType(AbsoluteInstantType absoluteInstantType) {
70
        absoluteInstantTypes.put(absoluteInstantType.getType(), absoluteInstantType);   
71
    }
72

  
73
    public AbsoluteInstantType getAbsoluteInstantType(int type) throws AbsoluteInstantTypeNotRegisteredException {
74
        if (absoluteInstantTypes.containsKey(type)){
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff