root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / rendering / FInterval.java @ 13032
History | View | Annotate | Download (3.6 KB)
1 | 1100 | fjp | /* 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 | 214 | fernando | package com.iver.cit.gvsig.fmap.rendering; |
42 | |||
43 | 2413 | caballero | 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 | 298 | vcaballero | /**
|
52 | * Clase intervalo.
|
||
53 | *
|
||
54 | * @author Vicente Caballero Navarro
|
||
55 | */
|
||
56 | 2413 | caballero | public class FInterval implements IInterval { |
57 | 529 | vcaballero | private double from; |
58 | private double to; |
||
59 | 2413 | caballero | public FInterval(){
|
60 | } |
||
61 | 529 | vcaballero | /**
|
62 | * Crea un nuevo FInterval.
|
||
63 | *
|
||
64 | 1034 | vcaballero | * @param from Origen.
|
65 | * @param to Destino.
|
||
66 | 529 | vcaballero | */
|
67 | public FInterval(double from, double to) { |
||
68 | this.from = from;
|
||
69 | this.to = to;
|
||
70 | } |
||
71 | 214 | fernando | |
72 | 2413 | caballero | /* (non-Javadoc)
|
73 | * @see com.iver.cit.gvsig.fmap.rendering.IInterval#isInInterval(com.hardcode.gdbms.engine.values.Value)
|
||
74 | 529 | vcaballero | */
|
75 | 2413 | caballero | 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 | 529 | vcaballero | } |
92 | |||
93 | /**
|
||
94 | 1034 | vcaballero | * Devuelve el n?mero de origen.
|
95 | 529 | vcaballero | *
|
96 | 1034 | vcaballero | * @return N?mero de inicio.
|
97 | 529 | vcaballero | */
|
98 | public double getMin() { |
||
99 | return from;
|
||
100 | } |
||
101 | |||
102 | /**
|
||
103 | 1034 | vcaballero | * Devuelve el n?mero final.
|
104 | 529 | vcaballero | *
|
105 | 1034 | vcaballero | * @return N?mero final.
|
106 | 529 | vcaballero | */
|
107 | public double getMax() { |
||
108 | return to;
|
||
109 | } |
||
110 | |||
111 | 2413 | caballero | /* (non-Javadoc)
|
112 | * @see com.iver.cit.gvsig.fmap.rendering.IInterval#toString()
|
||
113 | 529 | vcaballero | */
|
114 | public String toString() { |
||
115 | return from + "-" + to; |
||
116 | } |
||
117 | |||
118 | /**
|
||
119 | 1034 | vcaballero | * Crea un FInterval nuevo a partir de un String con el n?mero inicial un
|
120 | * gui?n y el n?mero final.
|
||
121 | 529 | vcaballero | *
|
122 | 1034 | vcaballero | * @param s String.
|
123 | 529 | vcaballero | *
|
124 | 1034 | vcaballero | * @return FInterval nuevo.
|
125 | 529 | vcaballero | */
|
126 | 2413 | caballero | public static IInterval create(String s) { |
127 | 529 | vcaballero | String[] str = s.split("-"); |
128 | 9870 | caballero | if (s.startsWith("-")) { |
129 | str[0]="-"+str[1]; |
||
130 | s.replaceFirst("-",""); |
||
131 | str[1]=str[2]; |
||
132 | } |
||
133 | if (s.contentEquals(new StringBuffer("--"))) { |
||
134 | str[1]=s.substring(s.indexOf('-')+1,s.length()-1); |
||
135 | } |
||
136 | |||
137 | 2413 | caballero | IInterval inter=null;
|
138 | try{
|
||
139 | inter = new FInterval(Double.parseDouble(str[0]), |
||
140 | 529 | vcaballero | Double.parseDouble(str[1])); |
141 | 2413 | caballero | }catch (NumberFormatException e) { |
142 | 2794 | caballero | return new NullIntervalValue(); |
143 | 2413 | caballero | } |
144 | 529 | vcaballero | return inter;
|
145 | } |
||
146 | 214 | fernando | } |