Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/FunctionResolver.java @ 4926:1e379598c47a
Fixed dc:fromValue/toValue (now handles values in locations as numbers).
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 31 Jan 2013 10:18:16 +0100 |
parents | 5ab87837622f |
children | 53be73133104 |
comparison
equal
deleted
inserted
replaced
4925:57609ffb3843 | 4926:1e379598c47a |
---|---|
99 | 99 |
100 if (mode.equals("locations")) { | 100 if (mode.equals("locations")) { |
101 if (!(locations instanceof String)) { | 101 if (!(locations instanceof String)) { |
102 return -Double.MAX_VALUE; | 102 return -Double.MAX_VALUE; |
103 } | 103 } |
104 else { | 104 String loc = ((String)locations).replace(" ", ""); |
105 String loc = ((String)locations).replace(" ", ""); | 105 String[] split = loc.split(","); |
106 String[] split = loc.split(","); | 106 if (split.length < 1) { |
107 Arrays.sort(split); | 107 return -Double.MAX_VALUE; |
108 return split[0]; | 108 } |
109 try { | |
110 double min = Double.parseDouble(split[0]); | |
111 for (int i = 1; i < split.length; ++i) { | |
112 double v = Double.parseDouble(split[i]); | |
113 if (v < min) { | |
114 min = v; | |
115 } | |
116 } | |
117 return min; | |
118 } | |
119 catch (NumberFormatException nfe) { | |
120 return -Double.MAX_VALUE; | |
109 } | 121 } |
110 } | 122 } |
111 else if (mode.equals("distance")) { | 123 else if (mode.equals("distance")) { |
112 if (!(from instanceof String)) { | 124 if (!(from instanceof String)) { |
113 return -Double.MAX_VALUE; | 125 return -Double.MAX_VALUE; |
143 | 155 |
144 if (mode.equals("locations")) { | 156 if (mode.equals("locations")) { |
145 if (!(locations instanceof String)) { | 157 if (!(locations instanceof String)) { |
146 return Double.MAX_VALUE; | 158 return Double.MAX_VALUE; |
147 } | 159 } |
148 else { | 160 try { |
149 String loc = ((String)locations).replace(" ", ""); | 161 String loc = ((String)locations).replace(" ", ""); |
150 String[] split = loc.split(","); | 162 String[] split = loc.split(","); |
151 Arrays.sort(split); | 163 if (split.length < 1) { |
152 return split[split.length - 1]; | 164 return Double.MAX_VALUE; |
165 } | |
166 double max = Double.parseDouble(split[0]); | |
167 for (int i = 1; i < split.length; ++i) { | |
168 double v = Double.parseDouble(split[i]); | |
169 if (v > max) { | |
170 max = v; | |
171 } | |
172 } | |
173 return max; | |
174 } | |
175 catch (NumberFormatException nfe) { | |
176 return Double.MAX_VALUE; | |
153 } | 177 } |
154 } | 178 } |
155 else if (mode.equals("distance")) { | 179 else if (mode.equals("distance")) { |
156 if (!(to instanceof String)) { | 180 if (!(to instanceof String)) { |
157 return Double.MAX_VALUE; | 181 return Double.MAX_VALUE; |