annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQ.java @ 5745:ed9d7e360658

Merged.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 17 Apr 2013 15:00:38 +0200
parents bcf25d8c183e
children
rev   line source
726
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts.model;
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
4821
bcf25d8c183e Moved NaN removal code from W to DoubleUtil. Create QKms when calculating the 'Umhuellende'.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 2182
diff changeset
3 import de.intevation.flys.utils.DoubleUtil;
bcf25d8c183e Moved NaN removal code from W to DoubleUtil. Create QKms when calculating the 'Umhuellende'.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 2182
diff changeset
4
bcf25d8c183e Moved NaN removal code from W to DoubleUtil. Create QKms when calculating the 'Umhuellende'.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 2182
diff changeset
5 import gnu.trove.TDoubleArrayList;
bcf25d8c183e Moved NaN removal code from W to DoubleUtil. Create QKms when calculating the 'Umhuellende'.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 2182
diff changeset
6
2087
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
7 import java.util.regex.Matcher;
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
8 import java.util.regex.Pattern;
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
9
1033
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
10 import org.apache.log4j.Logger;
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
11
726
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12 public class WQ
2182
5ff481ab24a1 Refactored class hierachy to integrate model for W~W.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2087
diff changeset
13 extends W
726
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14 {
2087
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
15 public static final Pattern NUMBERS_PATTERN =
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
16 Pattern.compile("\\D*(\\d++.\\d*)\\D*");
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
17
2182
5ff481ab24a1 Refactored class hierachy to integrate model for W~W.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2087
diff changeset
18 private static Logger log = Logger.getLogger(WQ.class);
1033
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
19
2182
5ff481ab24a1 Refactored class hierachy to integrate model for W~W.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2087
diff changeset
20 protected TDoubleArrayList qs;
726
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 public WQ() {
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 this("");
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 public WQ(String name) {
2182
5ff481ab24a1 Refactored class hierachy to integrate model for W~W.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2087
diff changeset
27 super(name);
5ff481ab24a1 Refactored class hierachy to integrate model for W~W.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2087
diff changeset
28 qs = new TDoubleArrayList();
726
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 public WQ(int capacity) {
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 this(capacity, "");
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 public WQ(int capacity, String name) {
2182
5ff481ab24a1 Refactored class hierachy to integrate model for W~W.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2087
diff changeset
37 super(capacity, name);
5ff481ab24a1 Refactored class hierachy to integrate model for W~W.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2087
diff changeset
38 qs = new TDoubleArrayList(capacity);
726
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 public WQ(double [] qs, double [] ws) {
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 this(qs, ws, "");
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 public WQ(double [] qs, double [] ws, String name) {
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 super(name);
2182
5ff481ab24a1 Refactored class hierachy to integrate model for W~W.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2087
diff changeset
47 this.ws = new TDoubleArrayList(ws);
5ff481ab24a1 Refactored class hierachy to integrate model for W~W.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2087
diff changeset
48 this.qs = new TDoubleArrayList(qs);
726
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50
2087
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
51
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
52 public Double getRawValue() {
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
53 if (name == null || name.length() == 0) {
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
54 // this should never happen
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
55 return null;
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
56 }
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
57
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
58 Matcher m = NUMBERS_PATTERN.matcher(name);
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
59
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
60 if (m.matches()) {
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
61 String raw = m.group(1);
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
62
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
63 try {
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
64 return Double.valueOf(raw);
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
65 }
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
66 catch (NumberFormatException nfe) {
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
67 // do nothing
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
68 }
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
69 }
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
70
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
71 return null;
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
72 }
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
73
726
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74 public void add(double w, double q) {
2182
5ff481ab24a1 Refactored class hierachy to integrate model for W~W.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2087
diff changeset
75 ws.add(w);
5ff481ab24a1 Refactored class hierachy to integrate model for W~W.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2087
diff changeset
76 qs.add(q);
726
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
77 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
78
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
79 public double getQ(int idx) {
2182
5ff481ab24a1 Refactored class hierachy to integrate model for W~W.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2087
diff changeset
80 return qs.getQuick(idx);
726
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
81 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
82
2182
5ff481ab24a1 Refactored class hierachy to integrate model for W~W.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2087
diff changeset
83 @Override
726
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
84 public double [] get(int idx) {
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
85 return get(idx, new double [2]);
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
86 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
87
2182
5ff481ab24a1 Refactored class hierachy to integrate model for W~W.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2087
diff changeset
88 @Override
726
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
89 public double [] get(int idx, double [] dst) {
2182
5ff481ab24a1 Refactored class hierachy to integrate model for W~W.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2087
diff changeset
90 dst[0] = ws.getQuick(idx);
5ff481ab24a1 Refactored class hierachy to integrate model for W~W.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2087
diff changeset
91 dst[1] = qs.getQuick(idx);
726
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
92 return dst;
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
93 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
94
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
95 public double [] getQs() {
2182
5ff481ab24a1 Refactored class hierachy to integrate model for W~W.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2087
diff changeset
96 return qs.toNativeArray();
744
b385577bcaca WQ: Added a method to guess is increasing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 726
diff changeset
97 }
b385577bcaca WQ: Added a method to guess is increasing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 726
diff changeset
98
2182
5ff481ab24a1 Refactored class hierachy to integrate model for W~W.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2087
diff changeset
99 @Override
5ff481ab24a1 Refactored class hierachy to integrate model for W~W.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2087
diff changeset
100 public void removeNaNs() {
4821
bcf25d8c183e Moved NaN removal code from W to DoubleUtil. Create QKms when calculating the 'Umhuellende'.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 2182
diff changeset
101 DoubleUtil.removeNaNs(new TDoubleArrayList [] { ws, qs });
1033
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
102 }
726
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
103 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
104 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org