annotate artifacts/src/main/java/org/dive4elements/river/utils/KMIndex.java @ 9415:9744ce3c3853

Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets. The facets also put the valid station range into their xml-metadata
author gernotbelger
date Thu, 16 Aug 2018 16:27:53 +0200
parents ddcd52d239cd
children
rev   line source
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
6 * documentation coming with Dive4Elements River for details.
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4318
diff changeset
9 package org.dive4elements.river.utils;
3013
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
11 import java.io.Serializable;
3013
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12 import java.util.ArrayList;
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13 import java.util.Collections;
3026
65b6e27c6f25 FixA: Use new data structures in Delta W(t) exporter. Removed obsolete code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3013
diff changeset
14 import java.util.Iterator;
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
15 import java.util.List;
3013
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16
4318
46511b4d8357 KMIndex: Minor doc.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 3158
diff changeset
17 /** km to value, searchable. Tolerance is at 10cm. */
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
18 public class KMIndex<A> implements Serializable, Iterable<KMIndex.Entry<A>> {
3013
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
20 private static final long serialVersionUID = 1L;
3013
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
22 private static final double EPSILON = 1e-4;
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
23
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
24 public static class Entry<A> implements Serializable, Comparable<Entry<A>> {
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
25 private static final long serialVersionUID = 1L;
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
26
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
27 private final double km;
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
28
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
29 private A value;
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
30
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
31 public Entry(final double km) {
3013
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 this.km = km;
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 }
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
35 public Entry(final double km, final A value) {
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
36 this.km = km;
3013
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 this.value = value;
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 }
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 public double getKm() {
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
41 return this.km;
3013
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 }
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 public A getValue() {
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
45 return this.value;
3013
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 }
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48 @Override
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
49 public int compareTo(final Entry<A> other) {
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
50 final double diff = this.km - other.km;
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
51 if (diff < -EPSILON)
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
52 return -1;
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
53 if (diff > +EPSILON)
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
54 return +1;
3013
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 return 0;
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56 }
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
58 public boolean epsilonEquals(final double otherKm) {
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
59 return Math.abs(this.km - otherKm) < EPSILON;
3013
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
60 }
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
61 }
3013
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
63 private List<Entry<A>> entries;
3013
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65 public KMIndex() {
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
66 this(10);
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67 }
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
68
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
69 public KMIndex(final int capacity) {
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
70 this.entries = new ArrayList<>(capacity);
3013
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
71 }
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
72
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
73 public void add(final double km, final A value) {
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
74 this.entries.add(new Entry<>(km, value));
3013
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
75 }
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
76
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
77 public void sort() {
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
78 Collections.sort(this.entries);
3013
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
79 }
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
80
8613
39ce099a6551 (issue1755) Add good defaults for bedquality distance selection
Andre Heinecke <andre.heinecke@intevation.de>
parents: 7215
diff changeset
81 public int size() {
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
82 return this.entries.size();
8613
39ce099a6551 (issue1755) Add good defaults for bedquality distance selection
Andre Heinecke <andre.heinecke@intevation.de>
parents: 7215
diff changeset
83 }
39ce099a6551 (issue1755) Add good defaults for bedquality distance selection
Andre Heinecke <andre.heinecke@intevation.de>
parents: 7215
diff changeset
84
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
85 public Entry<A> get(final int idx) {
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
86 return this.entries.get(idx);
8613
39ce099a6551 (issue1755) Add good defaults for bedquality distance selection
Andre Heinecke <andre.heinecke@intevation.de>
parents: 7215
diff changeset
87 }
39ce099a6551 (issue1755) Add good defaults for bedquality distance selection
Andre Heinecke <andre.heinecke@intevation.de>
parents: 7215
diff changeset
88
7215
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5994
diff changeset
89 /** Return the first entry at km. */
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
90 public Entry<A> search(final double km) {
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
91 for (final Entry<A> entry : this.entries) {
3013
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
92 if (entry.epsilonEquals(km)) {
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
93 return entry;
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
94 }
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
95 }
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
96 return null;
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
97 }
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
98
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
99 public Entry<A> binarySearch(final double km) {
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
100 final int index = Collections.binarySearch(this.entries, new Entry<A>(km));
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
101 return index >= 0 ? this.entries.get(index) : null;
3013
ba62c1751f07 FixA: Added new serializable km inedx structure.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
102 }
3026
65b6e27c6f25 FixA: Use new data structures in Delta W(t) exporter. Removed obsolete code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3013
diff changeset
103
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
104 @Override
3026
65b6e27c6f25 FixA: Use new data structures in Delta W(t) exporter. Removed obsolete code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3013
diff changeset
105 public Iterator<Entry<A>> iterator() {
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
106 return this.entries.iterator();
3026
65b6e27c6f25 FixA: Use new data structures in Delta W(t) exporter. Removed obsolete code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3013
diff changeset
107 }
9415
9744ce3c3853 Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets.
gernotbelger
parents: 9360
diff changeset
108 }

http://dive4elements.wald.intevation.org