Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/LocationProvider.java @ 3615:f84854eba0b3
Preparations for logo inclusion in charts.
flys-artifacts/trunk@5278 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Tue, 28 Aug 2012 12:47:11 +0000 |
parents | 0f7abd95c6e2 |
children | efb067ab2ca4 |
rev | line source |
---|---|
2063
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.model; |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
3 import net.sf.ehcache.Cache; |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
4 import net.sf.ehcache.Element; |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
5 |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
6 import org.apache.log4j.Logger; |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
7 |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
8 import de.intevation.flys.model.Annotation; |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
9 import de.intevation.flys.model.FastAnnotations; |
2063
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 import de.intevation.flys.artifacts.cache.CacheFactory; |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
13 public class LocationProvider { |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
15 private static final Logger log = |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
16 Logger.getLogger(LocationProvider.class); |
2127
0c7847b8e85e
Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2063
diff
changeset
|
17 |
0c7847b8e85e
Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2063
diff
changeset
|
18 |
2063
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
19 public static final String CACHE_KEY = "location-provider"; |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 |
2127
0c7847b8e85e
Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2063
diff
changeset
|
21 public static final String PREFIX = "lp-"; |
0c7847b8e85e
Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2063
diff
changeset
|
22 |
2063
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 private LocationProvider() { |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 } |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 |
2127
0c7847b8e85e
Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2063
diff
changeset
|
27 public static String getLocation(String river, double km) { |
2063
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
29 FastAnnotations fas = getAnnotations(river, km); |
2127
0c7847b8e85e
Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2063
diff
changeset
|
30 |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
31 FastAnnotations.Annotation an = fas.findByKm(km); |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
32 |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
33 return an != null ? an.getPosition() : null; |
2063
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
34 } |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
35 |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
36 public static FastAnnotations getAnnotations(String river) { |
2289
fe3ea0f16098
Small bugfix for fetching river annotations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2144
diff
changeset
|
37 return getAnnotations(river, Double.MAX_VALUE); |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
38 } |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
39 |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
40 protected static FastAnnotations getAnnotations(String river, double km) { |
2063
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
41 |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
42 Cache cache = CacheFactory.getCache(CACHE_KEY); |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
43 |
2127
0c7847b8e85e
Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2063
diff
changeset
|
44 if (cache == null) { |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
45 return uncachedAnnotations(river, km); |
2063
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
46 } |
2127
0c7847b8e85e
Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2063
diff
changeset
|
47 |
0c7847b8e85e
Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2063
diff
changeset
|
48 String key = PREFIX + river; |
0c7847b8e85e
Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2063
diff
changeset
|
49 |
0c7847b8e85e
Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2063
diff
changeset
|
50 Element element = cache.get(key); |
0c7847b8e85e
Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2063
diff
changeset
|
51 |
0c7847b8e85e
Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2063
diff
changeset
|
52 if (element != null) { |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
53 return (FastAnnotations)element.getValue(); |
2063
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
54 } |
2127
0c7847b8e85e
Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2063
diff
changeset
|
55 |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
56 FastAnnotations fas = uncachedAnnotations(river, Double.MAX_VALUE); |
2127
0c7847b8e85e
Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2063
diff
changeset
|
57 |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
58 cache.put(new Element(key, fas)); |
2127
0c7847b8e85e
Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2063
diff
changeset
|
59 |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
60 return fas; |
2063
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
61 } |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
62 |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
63 protected static FastAnnotations uncachedAnnotations( |
2063
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
64 String river, |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
65 double km |
2063
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
66 ) { |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
67 if (km != Double.MAX_VALUE) { |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
68 // XXX Fake it by using a standard Annotation. |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
69 |
2127
0c7847b8e85e
Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2063
diff
changeset
|
70 Annotation annotation = |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
71 AnnotationsFactory.getAnnotation(river, km); |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
72 |
2127
0c7847b8e85e
Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2063
diff
changeset
|
73 if (annotation != null) { |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
74 FastAnnotations.Annotation fa = |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
75 new FastAnnotations.Annotation( |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
76 km, Double.NaN, |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
77 annotation.getPosition().getValue(), null, null, |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
78 Double.NaN, Double.NaN); |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
79 return new FastAnnotations( |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
80 new FastAnnotations.Annotation [] { fa }); |
2127
0c7847b8e85e
Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2063
diff
changeset
|
81 } |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
82 |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
83 return new FastAnnotations(new FastAnnotations.Annotation[0]); |
2063
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
84 } |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
85 |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
86 long startTime = System.currentTimeMillis(); |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
87 |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
88 FastAnnotations fas = new FastAnnotations(river); |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
89 |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
90 long stopTime = System.currentTimeMillis(); |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
91 |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
92 if (log.isDebugEnabled()) { |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
93 log.debug("Loading locations took " + |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
94 (stopTime-startTime)/1000f + " secs."); |
2063
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
95 } |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
96 |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
97 return fas; |
2063
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
98 } |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
99 } |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
100 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |