comparison flys-artifacts/src/main/java/de/intevation/flys/utils/DoubleUtil.java @ 3776:1ddbf66a2b0a

Implemented the access for 'Auslagerung extremer Wasserspiegellagen' flys-artifacts/trunk@5483 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sun, 16 Sep 2012 17:55:10 +0000
parents 0dd58ab7e118
children a5f65e8983be
comparison
equal deleted inserted replaced
3775:d52c4ca93ffb 3776:1ddbf66a2b0a
1 package de.intevation.flys.utils; 1 package de.intevation.flys.utils;
2
3 import de.intevation.flys.artifacts.math.Linear;
4
5 import gnu.trove.TDoubleArrayList;
2 6
3 import java.util.Arrays; 7 import java.util.Arrays;
4 8
5 import de.intevation.flys.artifacts.math.Linear; 9 import org.apache.log4j.Logger;
6
7 10
8 public class DoubleUtil 11 public class DoubleUtil
9 { 12 {
13 private static Logger log = Logger.getLogger(DoubleUtil.class);
14
10 public static final double DEFAULT_STEP_PRECISION = 1e6; 15 public static final double DEFAULT_STEP_PRECISION = 1e6;
11 16
12 private DoubleUtil() { 17 private DoubleUtil() {
13 } 18 }
14 19
136 public static final double [] fill(int N, double value) { 141 public static final double [] fill(int N, double value) {
137 double [] result = new double[N]; 142 double [] result = new double[N];
138 Arrays.fill(result, value); 143 Arrays.fill(result, value);
139 return result; 144 return result;
140 } 145 }
146
147 public interface SegmentCallback {
148 void newSegment(double from, double to, double [] values);
149 }
150
151 public static final void parseSegments(
152 String input,
153 SegmentCallback callback
154 ) {
155 TDoubleArrayList vs = new TDoubleArrayList();
156
157 for (String segmentStr: input.split(":")) {
158 String [] parts = segmentStr.split(";");
159 if (parts.length < 3) {
160 log.warn("invalid segment: '" + segmentStr + "'");
161 continue;
162 }
163 try {
164 double from = Double.parseDouble(parts[0].trim());
165 double to = Double.parseDouble(parts[1].trim());
166
167 vs.resetQuick();
168
169 for (String valueStr: parts[2].split(",")) {
170 vs.add(round(Double.parseDouble(valueStr.trim())));
171 }
172
173 callback.newSegment(from, to, vs.toNativeArray());
174 }
175 catch (NumberFormatException nfe) {
176 log.warn("invalid segment: '" + segmentStr + "'");
177 }
178 }
179 }
141 } 180 }
142 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 181 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org