Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/WQ.java @ 5838:5aa05a7a34b7
Rename modules to more fitting names.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 15:23:37 +0200 |
parents | flys-artifacts/src/main/java/org/dive4elements/river/artifacts/model/WQ.java@bd047b71ab37 |
children | 4897a58c8746 |
comparison
equal
deleted
inserted
replaced
5837:d9901a08d0a6 | 5838:5aa05a7a34b7 |
---|---|
1 package org.dive4elements.river.artifacts.model; | |
2 | |
3 import org.dive4elements.river.utils.DoubleUtil; | |
4 | |
5 import gnu.trove.TDoubleArrayList; | |
6 | |
7 import java.util.regex.Matcher; | |
8 import java.util.regex.Pattern; | |
9 | |
10 import org.apache.log4j.Logger; | |
11 | |
12 public class WQ | |
13 extends W | |
14 { | |
15 public static final Pattern NUMBERS_PATTERN = | |
16 Pattern.compile("\\D*(\\d++.\\d*)\\D*"); | |
17 | |
18 private static Logger log = Logger.getLogger(WQ.class); | |
19 | |
20 protected TDoubleArrayList qs; | |
21 | |
22 public WQ() { | |
23 this(""); | |
24 } | |
25 | |
26 public WQ(String name) { | |
27 super(name); | |
28 qs = new TDoubleArrayList(); | |
29 } | |
30 | |
31 public WQ(int capacity) { | |
32 this(capacity, ""); | |
33 } | |
34 | |
35 | |
36 public WQ(int capacity, String name) { | |
37 super(capacity, name); | |
38 qs = new TDoubleArrayList(capacity); | |
39 } | |
40 | |
41 public WQ(double [] qs, double [] ws) { | |
42 this(qs, ws, ""); | |
43 } | |
44 | |
45 public WQ(double [] qs, double [] ws, String name) { | |
46 super(name); | |
47 this.ws = new TDoubleArrayList(ws); | |
48 this.qs = new TDoubleArrayList(qs); | |
49 } | |
50 | |
51 | |
52 public Double getRawValue() { | |
53 if (name == null || name.length() == 0) { | |
54 // this should never happen | |
55 return null; | |
56 } | |
57 | |
58 Matcher m = NUMBERS_PATTERN.matcher(name); | |
59 | |
60 if (m.matches()) { | |
61 String raw = m.group(1); | |
62 | |
63 try { | |
64 return Double.valueOf(raw); | |
65 } | |
66 catch (NumberFormatException nfe) { | |
67 // do nothing | |
68 } | |
69 } | |
70 | |
71 return null; | |
72 } | |
73 | |
74 public void add(double w, double q) { | |
75 ws.add(w); | |
76 qs.add(q); | |
77 } | |
78 | |
79 public double getQ(int idx) { | |
80 return qs.getQuick(idx); | |
81 } | |
82 | |
83 @Override | |
84 public double [] get(int idx) { | |
85 return get(idx, new double [2]); | |
86 } | |
87 | |
88 @Override | |
89 public double [] get(int idx, double [] dst) { | |
90 dst[0] = ws.getQuick(idx); | |
91 dst[1] = qs.getQuick(idx); | |
92 return dst; | |
93 } | |
94 | |
95 public double [] getQs() { | |
96 return qs.toNativeArray(); | |
97 } | |
98 | |
99 @Override | |
100 public void removeNaNs() { | |
101 DoubleUtil.removeNaNs(new TDoubleArrayList [] { ws, qs }); | |
102 } | |
103 } | |
104 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |