root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / rendering / FInterval.java @ 38080
History | View | Annotate | Download (3.59 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 | 38080 | psanxiao | import java.util.regex.Matcher; |
44 | import java.util.regex.Pattern; |
||
45 | |||
46 | 2413 | caballero | 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 | 298 | vcaballero | /**
|
55 | * Clase intervalo.
|
||
56 | *
|
||
57 | * @author Vicente Caballero Navarro
|
||
58 | */
|
||
59 | 2413 | caballero | public class FInterval implements IInterval { |
60 | 529 | vcaballero | private double from; |
61 | private double to; |
||
62 | 2413 | caballero | public FInterval(){
|
63 | } |
||
64 | 529 | vcaballero | /**
|
65 | * Crea un nuevo FInterval.
|
||
66 | *
|
||
67 | 1034 | vcaballero | * @param from Origen.
|
68 | * @param to Destino.
|
||
69 | 529 | vcaballero | */
|
70 | public FInterval(double from, double to) { |
||
71 | this.from = from;
|
||
72 | this.to = to;
|
||
73 | } |
||
74 | 214 | fernando | |
75 | 2413 | caballero | /* (non-Javadoc)
|
76 | * @see com.iver.cit.gvsig.fmap.rendering.IInterval#isInInterval(com.hardcode.gdbms.engine.values.Value)
|
||
77 | 529 | vcaballero | */
|
78 | 2413 | caballero | 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 | 529 | vcaballero | } |
95 | |||
96 | /**
|
||
97 | 1034 | vcaballero | * Devuelve el n?mero de origen.
|
98 | 529 | vcaballero | *
|
99 | 1034 | vcaballero | * @return N?mero de inicio.
|
100 | 529 | vcaballero | */
|
101 | public double getMin() { |
||
102 | return from;
|
||
103 | } |
||
104 | |||
105 | /**
|
||
106 | 1034 | vcaballero | * Devuelve el n?mero final.
|
107 | 529 | vcaballero | *
|
108 | 1034 | vcaballero | * @return N?mero final.
|
109 | 529 | vcaballero | */
|
110 | public double getMax() { |
||
111 | return to;
|
||
112 | } |
||
113 | |||
114 | 2413 | caballero | /* (non-Javadoc)
|
115 | * @see com.iver.cit.gvsig.fmap.rendering.IInterval#toString()
|
||
116 | 529 | vcaballero | */
|
117 | public String toString() { |
||
118 | return from + "-" + to; |
||
119 | } |
||
120 | |||
121 | /**
|
||
122 | 1034 | vcaballero | * Crea un FInterval nuevo a partir de un String con el n?mero inicial un
|
123 | * gui?n y el n?mero final.
|
||
124 | 529 | vcaballero | *
|
125 | 1034 | vcaballero | * @param s String.
|
126 | 529 | vcaballero | *
|
127 | 1034 | vcaballero | * @return FInterval nuevo.
|
128 | 529 | vcaballero | */
|
129 | 2413 | caballero | public static IInterval create(String s) { |
130 | 38080 | psanxiao | 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 | 9870 | caballero | } |
140 | |||
141 | 529 | vcaballero | return inter;
|
142 | } |
||
143 | 214 | fernando | } |