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