comparison flys-artifacts/src/main/java/org/dive4elements/river/artifacts/model/W.java @ 5831:bd047b71ab37

Repaired internal references
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 12:06:39 +0200
parents flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/W.java@bcf25d8c183e
children
comparison
equal deleted inserted replaced
5830:160f53ee0870 5831:bd047b71ab37
1 package org.dive4elements.river.artifacts.model;
2
3 import org.dive4elements.river.utils.DataUtil;
4 import org.dive4elements.river.utils.DoubleUtil;
5
6 import gnu.trove.TDoubleArrayList;
7
8 import org.apache.log4j.Logger;
9
10 public class W
11 extends NamedObjectImpl
12 {
13 private static Logger log = Logger.getLogger(W.class);
14
15 protected TDoubleArrayList ws;
16
17 public W() {
18 ws = new TDoubleArrayList();
19 }
20
21 public W(String name) {
22 super(name);
23 ws = new TDoubleArrayList();
24 }
25
26 public W(int capacity) {
27 this(capacity, "");
28 }
29
30 public W(int capacity, String name) {
31 super(name);
32 ws = new TDoubleArrayList(capacity);
33 }
34
35 public void add(double value) {
36 ws.add(value);
37 }
38
39 public int size() {
40 return ws.size();
41 }
42
43 public double getW(int idx) {
44 return ws.getQuick(idx);
45 }
46
47 public double [] getWs() {
48 return ws.toNativeArray();
49 }
50
51 public double [] get(int idx) {
52 return get(idx, new double [1]);
53 }
54
55 public double [] get(int idx, double [] dst) {
56 dst[0] = ws.getQuick(idx);
57 return dst;
58 }
59
60 public double minWs() {
61 return ws.min();
62 }
63
64 public void removeNaNs() {
65 DoubleUtil.removeNaNs(new TDoubleArrayList [] { ws });
66 }
67
68 public boolean guessWaterIncreasing() {
69 return guessWaterIncreasing(0.05f);
70 }
71
72 public boolean guessWaterIncreasing(float factor) {
73 return DataUtil.guessWaterIncreasing(ws, factor);
74 }
75
76 public int [] longestIncreasingWRangeIndices() {
77 return longestIncreasingWRangeIndices(new int[2]);
78 }
79
80 public int [] longestIncreasingWRangeIndices(int [] bounds) {
81
82 int N = size();
83 int start = 0;
84 int stop = 0;
85
86 double lastW = Double.MAX_VALUE;
87
88 for (int i = 0; i < N; ++i) {
89 double v = ws.getQuick(i);
90 if (v <= lastW) {
91 if (stop-start > bounds[1]-bounds[0]) {
92 bounds[0] = start;
93 bounds[1] = stop;
94 if (log.isDebugEnabled()) {
95 log.debug("new range: " +
96 bounds[0] + " - " + bounds[1] + " (" +
97 ws.getQuick(bounds[0]) + ", " +
98 ws.getQuick(bounds[1]) + ")");
99
100 }
101 }
102 start = stop = i;
103 }
104 else {
105 stop = i;
106 }
107 lastW = v;
108 }
109
110 if (stop-start > bounds[1]-bounds[0]) {
111 bounds[0] = start;
112 bounds[1] = stop;
113 if (log.isDebugEnabled()) {
114 log.debug("new range @end: " +
115 bounds[0] + " - " + bounds[1] + " (" +
116 ws.getQuick(bounds[0]) + ", " +
117 ws.getQuick(bounds[1]) + ")");
118 }
119 }
120
121 return bounds;
122 }
123 }
124 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org