Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / rendering / FInterval.java @ 38563

History | View | Annotate | Download (3.59 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.cit.gvsig.fmap.rendering;
42

    
43
import java.util.regex.Matcher;
44
import java.util.regex.Pattern;
45

    
46
import com.hardcode.gdbms.engine.values.DateValue;
47
import com.hardcode.gdbms.engine.values.DoubleValue;
48
import com.hardcode.gdbms.engine.values.FloatValue;
49
import com.hardcode.gdbms.engine.values.IntValue;
50
import com.hardcode.gdbms.engine.values.LongValue;
51
import com.hardcode.gdbms.engine.values.NullValue;
52
import com.hardcode.gdbms.engine.values.Value;
53

    
54
/**
55
 * Clase intervalo.
56
 *
57
 * @author Vicente Caballero Navarro
58
 */
59
public class FInterval implements IInterval {
60
        private double from;
61
        private double to;
62
        public FInterval(){
63
        }
64
        /**
65
         * Crea un nuevo FInterval.
66
         *
67
         * @param from Origen.
68
         * @param to Destino.
69
         */
70
        public FInterval(double from, double to) {
71
                this.from = from;
72
                this.to = to;
73
        }
74

    
75
        /* (non-Javadoc)
76
         * @see com.iver.cit.gvsig.fmap.rendering.IInterval#isInInterval(com.hardcode.gdbms.engine.values.Value)
77
         */
78
        public boolean isInInterval(Value v) {
79
                double valor=0;
80
                if (v instanceof IntValue) {
81
                        valor = ((IntValue) v).getValue();
82
                } else if (v instanceof DoubleValue) {
83
                        valor = ((DoubleValue) v).getValue();
84
                } else if (v instanceof FloatValue) {
85
                        valor = ((FloatValue) v).getValue();
86
                } else if (v instanceof LongValue) {
87
                        valor = ((LongValue) v).getValue();
88
                } else if (v instanceof DateValue) {
89
                        //TODO POR IMPLEMENTAR
90
                } else if (v instanceof NullValue){
91
                        return false;
92
                }
93
                return ((valor >= from) && (valor <= to));
94
        }
95

    
96
        /**
97
         * Devuelve el n?mero de origen.
98
         *
99
         * @return N?mero de inicio.
100
         */
101
        public double getMin() {
102
                return from;
103
        }
104

    
105
        /**
106
         * Devuelve el n?mero final.
107
         *
108
         * @return N?mero final.
109
         */
110
        public double getMax() {
111
                return to;
112
        }
113

    
114
        /* (non-Javadoc)
115
         * @see com.iver.cit.gvsig.fmap.rendering.IInterval#toString()
116
         */
117
        public String toString() {
118
                return from + "-" + to;
119
        }
120

    
121
        /**
122
         * Crea un FInterval nuevo a partir de un String con el n?mero inicial un
123
         * gui?n y el n?mero final.
124
         *
125
         * @param s String.
126
         *
127
         * @return FInterval nuevo.
128
         */
129
        public static IInterval create(String s) {
130
                Pattern pattern = Pattern.compile("(-?[^-]*)-(-?.*)");
131
                Matcher matcher = pattern.matcher(s);
132
                IInterval inter=new NullIntervalValue(); // temporal pessimism
133
                if (matcher.find()) {
134
                        try{
135
                                inter = new FInterval(Double.parseDouble(matcher.group(1)),
136
                                                Double.parseDouble(matcher.group(2)));
137
                        }catch (NumberFormatException e) {
138
                        }
139
                }
140

    
141
                return inter;
142
        }
143
}