root / tags / v1_0_2_Build_903+3D / libraries / libFMap / src / com / iver / cit / gvsig / fmap / rendering / FInterval.java @ 10722
History | View | Annotate | Download (3.4 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 com.hardcode.gdbms.engine.values.DateValue; |
44 |
import com.hardcode.gdbms.engine.values.DoubleValue; |
45 |
import com.hardcode.gdbms.engine.values.FloatValue; |
46 |
import com.hardcode.gdbms.engine.values.IntValue; |
47 |
import com.hardcode.gdbms.engine.values.LongValue; |
48 |
import com.hardcode.gdbms.engine.values.NullValue; |
49 |
import com.hardcode.gdbms.engine.values.Value; |
50 |
|
51 |
/**
|
52 |
* Clase intervalo.
|
53 |
*
|
54 |
* @author Vicente Caballero Navarro
|
55 |
*/
|
56 |
public class FInterval implements IInterval { |
57 |
private double from; |
58 |
private double to; |
59 |
public FInterval(){
|
60 |
} |
61 |
/**
|
62 |
* Crea un nuevo FInterval.
|
63 |
*
|
64 |
* @param from Origen.
|
65 |
* @param to Destino.
|
66 |
*/
|
67 |
public FInterval(double from, double to) { |
68 |
this.from = from;
|
69 |
this.to = to;
|
70 |
} |
71 |
|
72 |
/* (non-Javadoc)
|
73 |
* @see com.iver.cit.gvsig.fmap.rendering.IInterval#isInInterval(com.hardcode.gdbms.engine.values.Value)
|
74 |
*/
|
75 |
public boolean isInInterval(Value v) { |
76 |
double valor=0; |
77 |
if (v instanceof IntValue) { |
78 |
valor = ((IntValue) v).getValue(); |
79 |
} else if (v instanceof DoubleValue) { |
80 |
valor = ((DoubleValue) v).getValue(); |
81 |
} else if (v instanceof FloatValue) { |
82 |
valor = ((FloatValue) v).getValue(); |
83 |
} else if (v instanceof LongValue) { |
84 |
valor = ((LongValue) v).getValue(); |
85 |
} else if (v instanceof DateValue) { |
86 |
//TODO POR IMPLEMENTAR
|
87 |
} else if (v instanceof NullValue){ |
88 |
return false; |
89 |
} |
90 |
return ((valor >= from) && (valor <= to));
|
91 |
} |
92 |
|
93 |
/**
|
94 |
* Devuelve el n?mero de origen.
|
95 |
*
|
96 |
* @return N?mero de inicio.
|
97 |
*/
|
98 |
public double getMin() { |
99 |
return from;
|
100 |
} |
101 |
|
102 |
/**
|
103 |
* Devuelve el n?mero final.
|
104 |
*
|
105 |
* @return N?mero final.
|
106 |
*/
|
107 |
public double getMax() { |
108 |
return to;
|
109 |
} |
110 |
|
111 |
/* (non-Javadoc)
|
112 |
* @see com.iver.cit.gvsig.fmap.rendering.IInterval#toString()
|
113 |
*/
|
114 |
public String toString() { |
115 |
return from + "-" + to; |
116 |
} |
117 |
|
118 |
/**
|
119 |
* Crea un FInterval nuevo a partir de un String con el n?mero inicial un
|
120 |
* gui?n y el n?mero final.
|
121 |
*
|
122 |
* @param s String.
|
123 |
*
|
124 |
* @return FInterval nuevo.
|
125 |
*/
|
126 |
public static IInterval create(String s) { |
127 |
String[] str = s.split("-"); |
128 |
IInterval inter=null;
|
129 |
try{
|
130 |
inter = new FInterval(Double.parseDouble(str[0]), |
131 |
Double.parseDouble(str[1])); |
132 |
}catch (NumberFormatException e) { |
133 |
return new NullIntervalValue(); |
134 |
} |
135 |
return inter;
|
136 |
} |
137 |
} |