annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/ZoomScale.java @ 5211:9e11599266c8

Allow dots and numbers in oracle backend name
author Andre Heinecke <aheinecke@intevation.de>
date Mon, 11 Mar 2013 09:53:16 +0100
parents e8c6fbed889b
children
rev   line source
4618
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts.model;
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
2
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
3 import java.util.HashMap;
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
4 import java.util.Map;
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
5 import java.util.Set;
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
6 import java.util.TreeMap;
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
7
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
8 import org.apache.log4j.Logger;
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
9
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
10 import de.intevation.flys.artifacts.math.Linear;
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
11
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
12
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
13 public class ZoomScale
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
14 {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
15 private static Logger logger = Logger.getLogger(ZoomScale.class);
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
16
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
17 private HashMap<String, TreeMap<Double, Double>> rivers;
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
18
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
19 public ZoomScale() {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
20 this.rivers = new HashMap<String, TreeMap<Double, Double>>();
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
21 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
22
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
23 public ZoomScale(String river) {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
24 this();
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
25 rivers.put(river, new TreeMap<Double, Double>());
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
26 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
27
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
28 public double getRadius(String river, double lower, double upper) {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
29 double range = Math.abs(upper) - Math.abs(lower);
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
30 TreeMap<Double, Double> ranges = rivers.get(river);
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
31 if (ranges == null) {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
32 return 0.001;
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
33 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
34 Map.Entry<Double, Double> next = ranges.higherEntry(range);
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
35 Map.Entry<Double, Double> prev = ranges.lowerEntry(range);
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
36 double x0 = 0d;
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
37 double x1 = 0d;
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
38 double y0 = 0d;
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
39 double y1 = 0d;
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
40 if (prev == null && next != null) {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
41 x1 = next.getKey();
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
42 y1 = next.getValue();
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
43 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
44 else if (prev != null && next == null) {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
45 return prev.getValue();
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
46 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
47 else {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
48 x0 = prev.getKey();
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
49 x1 = next.getKey();
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
50 y0 = prev.getValue();
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
51 y1 = next.getValue();
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
52 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
53 return Linear.linear(range, x0, x1, y0, y1);
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
54 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
55
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
56 public void addRiver(String river) {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
57 if (!this.rivers.containsKey(river)) {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
58 this.rivers.put(river, new TreeMap<Double, Double>());
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
59 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
60 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
61
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
62 public Set<String> getRivers() {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
63 return this.rivers.keySet();
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
64 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
65
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
66 public void addRange(String river, double range, double radius) {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
67 if (this.rivers.containsKey(river)) {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
68 this.rivers.get(river).put(range, radius);
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
69 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
70 else {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
71 this.rivers.put(river, new TreeMap<Double, Double>());
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
72 this.rivers.get(river).put(range, radius);
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
73 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
74 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
75 }

http://dive4elements.wald.intevation.org