Mercurial > dive4elements > river
annotate backend/src/main/java/org/dive4elements/river/model/FastAnnotations.java @ 9565:4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
author | gernotbelger |
---|---|
date | Mon, 05 Nov 2018 10:18:07 +0100 |
parents | 6ae0c5116d58 |
children |
rev | line source |
---|---|
5844
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
2 * Software engineering by Intevation GmbH |
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
3 * |
5992
4c3ccf2b0304
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5844
diff
changeset
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
5844
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
5992
4c3ccf2b0304
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5844
diff
changeset
|
6 * documentation coming with Dive4Elements River for details. |
5844
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
7 */ |
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
8 |
5829
18619c1e7c2a
Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5828
diff
changeset
|
9 package org.dive4elements.river.model; |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
11 import java.io.Serializable; |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
12 import java.util.ArrayList; |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
13 import java.util.Arrays; |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 import java.util.Comparator; |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
15 import java.util.Iterator; |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import java.util.List; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 import java.util.NoSuchElementException; |
8406
6ae0c5116d58
Distinguish between types of measurement stations and filter appropriately (plus minor cleanup in related classes).
Tom Gottfried <tom@intevation.de>
parents:
5992
diff
changeset
|
18 import java.util.regex.Pattern; |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
20 import org.dive4elements.river.backend.SessionHolder; |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
21 import org.dive4elements.river.backend.utils.StringUtil; |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
22 import org.hibernate.SQLQuery; |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 import org.hibernate.Session; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 import org.hibernate.type.StandardBasicTypes; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
26 public class FastAnnotations implements Serializable { |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
27 private static final long serialVersionUID = 1L; |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
29 public static final String SQL_BY_RIVER_NAME = // |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
30 "SELECT r.a AS a, r.b AS b, p.value AS position, " + // |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
31 "at.value AS attribute, ant.name AS name, " + // |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
32 "e.top AS top, e.bottom AS bottom " + // |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
33 "FROM annotations an " + // |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
34 "JOIN ranges r " + "ON an.range_id = r.id " + // |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
35 "JOIN attributes at " + "ON an.attribute_id = at.id "// |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
36 + "JOIN positions p " + "ON an.position_id = p.id " + // |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
37 "JOIN rivers riv " + "ON r.river_id = riv.id " + // |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
38 "LEFT JOIN annotation_types ant " + "ON an.type_id = ant.id " + // |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
39 "LEFT JOIN edges e " + "ON an.edge_id = e.id " + // |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
40 "WHERE riv.name = :river_name " + "ORDER BY r.a, position"; |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
42 public static final String SQL_BY_RIVER_ID = "SELECT r.a AS a, r.b AS b, p.value AS position, "// |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
43 + "at.value AS attribute, ant.name AS name, "// |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
44 + "e.top AS top, e.bottom AS bottom " + "FROM annotations an " + // |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
45 "JOIN ranges r " + "ON an.range_id = r.id " + // |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
46 "JOIN attributes at " + "ON an.attribute_id = at.id "// |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
47 + "JOIN positions p " + "ON an.position_id = p.id " + // |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
48 "LEFT JOIN annotation_types ant " + "ON an.type_id = ant.id "// |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
49 + "LEFT JOIN edges e " + "ON an.edge_id = e.id " + // |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
50 "WHERE r.id = :river_id " + "ORDER BY r.a, position"; |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 public static final double EPSILON = 1e-5; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
54 public static final Comparator<Annotation> KM_CMP = new Comparator<Annotation>() { |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
55 @Override |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
56 public int compare(final Annotation a, final Annotation b) { |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
57 final double diff = a.a - b.a; |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
59 if (diff < -EPSILON) |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
60 return -1; |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
61 if (diff > +EPSILON) |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
62 return +1; |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
63 |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
64 return 0; |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
65 } |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
66 }; |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
67 |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
68 public static final class Annotation implements Serializable, Comparable<Annotation> { |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
69 private static final long serialVersionUID = 1L; |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 private double a; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 private double b; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 private String position; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 private String attribute; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 private String name; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 private double top; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 private double bottom; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 public Annotation() { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
79 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
81 public Annotation(final double a) { |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 this.a = a; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
85 public Annotation(final double a, final double b, final String position, final String attribute, final String name, final double top, |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
86 final double bottom) { |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
87 this.a = a; |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
88 this.b = b; |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
89 this.position = position; |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 this.attribute = attribute; |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
91 this.name = name; |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
92 this.top = top; |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
93 this.bottom = bottom; |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 public double getA() { |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
97 return this.a; |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
98 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
99 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
100 public double getB() { |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
101 return this.b; |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
102 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
103 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
104 public String getPosition() { |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
105 return this.position; |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
106 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
107 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
108 public String getAttribute() { |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
109 return this.attribute; |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
110 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
111 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
112 public String getName() { |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
113 return this.name; |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
114 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
115 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
116 public double getTop() { |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
117 return this.top; |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
118 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
119 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
120 public double getBottom() { |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
121 return this.bottom; |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
122 } |
3653
20d249e1589f
Added FastAnnotation.Annotation.toString()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3334
diff
changeset
|
123 |
20d249e1589f
Added FastAnnotation.Annotation.toString()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3334
diff
changeset
|
124 @Override |
20d249e1589f
Added FastAnnotation.Annotation.toString()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3334
diff
changeset
|
125 public String toString() { |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
126 return "[a=" + this.a + ";b=" + this.b + ";pos=" + this.position + ";attr=" + this.attribute + ";name=" + this.name + ";top=" + this.top + ";bot=" |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
127 + this.bottom + "]"; |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
128 } |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
129 |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
130 @Override |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
131 public int compareTo(final Annotation o) { |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
132 |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
133 // Comparable interface introduced to make annotations deterministic (for testing etc) |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
134 final int compareKmStart = Double.valueOf(this.a).compareTo(Double.valueOf(o.a)); |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
135 if (compareKmStart != 0) |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
136 return compareKmStart; |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
137 |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
138 // Although position must not be null by database definition, Null-Checks are provided for safety reasons |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
139 if (StringUtil.isEmpty(this.position)) |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
140 return +1; // leere Strings ans Ende |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
141 |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
142 return String.valueOf(this.position).compareTo(String.valueOf(o.position)); |
3653
20d249e1589f
Added FastAnnotation.Annotation.toString()
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3334
diff
changeset
|
143 } |
3323
07c96cd39360
Fix comment.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2382
diff
changeset
|
144 } // class Annotation |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
145 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
146 public interface Filter { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
147 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
148 boolean accept(Annotation annotation); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
149 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
150 } // interface Filter |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
151 |
3325
96bd63281af7
Added Override annotation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3324
diff
changeset
|
152 public static class NameFilter implements Filter { |
3324
290189f07809
Added filter for annotation names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3323
diff
changeset
|
153 |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
154 private final Pattern namePattern; |
3324
290189f07809
Added filter for annotation names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3323
diff
changeset
|
155 |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
156 public NameFilter(final String name) { |
8406
6ae0c5116d58
Distinguish between types of measurement stations and filter appropriately (plus minor cleanup in related classes).
Tom Gottfried <tom@intevation.de>
parents:
5992
diff
changeset
|
157 this.namePattern = Pattern.compile(name); |
3324
290189f07809
Added filter for annotation names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3323
diff
changeset
|
158 } |
290189f07809
Added filter for annotation names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3323
diff
changeset
|
159 |
3325
96bd63281af7
Added Override annotation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3324
diff
changeset
|
160 @Override |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
161 public boolean accept(final Annotation annotation) { |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
162 return this.namePattern.matcher(annotation.getName()).matches(); |
3324
290189f07809
Added filter for annotation names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3323
diff
changeset
|
163 } |
3325
96bd63281af7
Added Override annotation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3324
diff
changeset
|
164 } // class NameFilter |
3324
290189f07809
Added filter for annotation names.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
3323
diff
changeset
|
165 |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
166 public static final Filter ALL = new Filter() { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
167 @Override |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
168 public boolean accept(final Annotation annotation) { |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
169 return true; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
170 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
171 }; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
172 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
173 public static final Filter IS_POINT = new Filter() { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
174 @Override |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
175 public boolean accept(final Annotation annotation) { |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
176 return Double.isNaN(annotation.getB()); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
177 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
178 }; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
179 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
180 public static final Filter IS_RANGE = new Filter() { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
181 @Override |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
182 public boolean accept(final Annotation annotation) { |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
183 return !Double.isNaN(annotation.getB()); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
184 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
185 }; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
186 |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
187 private Annotation[] annotations; |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
188 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
189 public FastAnnotations() { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
190 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
191 |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
192 public FastAnnotations(final Annotation[] annotations) { |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
193 this.annotations = annotations; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
194 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
195 |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
196 public FastAnnotations(final String riverName) { |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
197 this(loadByRiverName(riverName)); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
198 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
199 |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
200 public FastAnnotations(final int riverId) { |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
201 this(loadByRiverId(riverId)); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
202 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
203 |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
204 public FastAnnotations(final Iterator<Annotation> iter) { |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
205 this(toArray(iter)); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
206 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
207 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
208 public int size() { |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
209 return this.annotations.length; |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
210 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
211 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
212 public Iterator<Annotation> filter(final Filter filter) { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
213 return new Iterator<Annotation>() { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
214 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
215 private int idx; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
216 private Annotation current = findNext(); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
217 |
3334
2ae732e2c65c
FLYS backend: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3325
diff
changeset
|
218 @Override |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
219 public boolean hasNext() { |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
220 return this.current != null; |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
221 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
222 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
223 @Override |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
224 public Annotation next() { |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
225 if (this.current == null) { |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
226 throw new NoSuchElementException(); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
227 } |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
228 final Annotation result = this.current; |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
229 this.current = findNext(); |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
230 return result; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
231 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
232 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
233 private Annotation findNext() { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
234 |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
235 while (this.idx < FastAnnotations.this.annotations.length) { |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
236 final Annotation annotation = FastAnnotations.this.annotations[this.idx++]; |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
237 if (filter.accept(annotation)) { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
238 return annotation; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
239 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
240 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
241 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
242 return null; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
243 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
244 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
245 @Override |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
246 public void remove() { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
247 throw new UnsupportedOperationException(); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
248 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
249 }; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
250 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
251 |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
252 public static Annotation[] toArray(final Iterator<Annotation> iter) { |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
253 |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
254 final ArrayList<Annotation> list = new ArrayList<>(); |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
255 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
256 while (iter.hasNext()) { |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
257 list.add(iter.next()); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
258 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
259 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
260 return list.toArray(new Annotation[list.size()]); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
261 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
262 |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
263 public Annotation findByKm(final double km) { |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
264 final Annotation key = new Annotation(km); |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
265 final int idx = Arrays.binarySearch(this.annotations, key, KM_CMP); |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
266 |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
267 if ((idx < 0)) |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
268 return null; |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
269 |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
270 if (idx == 0) |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
271 return this.annotations[idx]; // lowest possible index |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
272 |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
273 // REMARK: binary search my find any annotation at kmTest, but we want the first entry (because the list of annotations |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
274 // is ordered by name) |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
275 for (int lowestIndex = idx; lowestIndex > 0; lowestIndex--) { |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
276 final double kmTest = this.annotations[lowestIndex].a; |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
277 if (Math.abs(kmTest - this.annotations[idx].a) > EPSILON) |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
278 return this.annotations[lowestIndex + 1]; |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
279 } |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
280 |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
281 return this.annotations[0]; |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
282 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
283 |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
284 private static SQLQuery createQuery(final String query) { |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
285 final Session session = SessionHolder.HOLDER.get(); |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
286 |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
287 return session.createSQLQuery(query).addScalar("a", StandardBasicTypes.DOUBLE).addScalar("b", StandardBasicTypes.DOUBLE) |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
288 .addScalar("position", StandardBasicTypes.STRING).addScalar("attribute", StandardBasicTypes.STRING).addScalar("name", StandardBasicTypes.STRING) |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
289 .addScalar("top", StandardBasicTypes.DOUBLE).addScalar("bottom", StandardBasicTypes.DOUBLE); |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
290 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
291 |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
292 private static Annotation[] buildAnnotations(final List<Object[]> list) { |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
293 final Annotation[] anns = new Annotation[list.size()]; |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
294 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
295 // Names are likely the same because they are a type |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
296 // like 'Pegel' or 'Hafen'. |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
297 // final HashMap<String, String> names = new HashMap<>(); |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
298 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
299 for (int i = 0; i < anns.length; ++i) { |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
300 final Object[] data = list.get(i); |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
301 final double a = ((Double) data[0]); |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
302 final double b = data[1] != null ? (Double) data[1] : Double.NaN; |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
303 final String position = (String) data[2]; |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
304 final String attribute = (String) data[3]; |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
305 final String name = (String) data[4]; |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
306 final double top = data[5] != null ? (Double) data[5] : Double.NaN; |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
307 final double bottom = data[6] != null ? (Double) data[6] : Double.NaN; |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
308 |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
309 // if (name != null) { |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
310 // final String old = names.get(name); |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
311 // if (old != null) { |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
312 // name = old; |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
313 // } else { |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
314 // names.put(name, name); |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
315 // } |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
316 // } |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
317 |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
318 anns[i] = new Annotation(a, b, position, attribute, name, top, bottom); |
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
319 |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
320 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
321 |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
322 Arrays.sort(anns); // Comparable interface introduced to make annotations deterministic (for testing etc) |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
323 return anns; |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
324 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
325 |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
326 public static Annotation[] loadByRiverName(final String riverName) { |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
327 |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
328 final SQLQuery query = createQuery(SQL_BY_RIVER_NAME); |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
329 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
330 query.setString("river_name", riverName); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
331 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
332 return buildAnnotations(query.list()); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
333 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
334 |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
335 public static Annotation[] loadByRiverId(final int riverId) { |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
336 |
9565
4809e23ffd27
FastAnnotations (Locations, POIs, Streckenfavoriten) deterministisch
gernotbelger
parents:
8406
diff
changeset
|
337 final SQLQuery query = createQuery(SQL_BY_RIVER_ID); |
2382
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
338 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
339 query.setInteger("river_id", riverId); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
340 |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
341 return buildAnnotations(query.list()); |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
342 } |
c5791de0c495
Added meachnism to backend to fetch all annotation related data in one go.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
343 } |