comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQ.java @ 3786:4adc35aa655c

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

http://dive4elements.wald.intevation.org