Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/LocationProvider.java @ 2156:4e0878695c5f
Made StyledSeriesBuilder more robust.
flys-artifacts/trunk@3741 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Fri, 20 Jan 2012 10:23:27 +0000 |
parents | a4bdf7d8527e |
children | fe3ea0f16098 |
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 |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
13 import de.intevation.flys.artifacts.model.AnnotationsFactory; |
2063
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
15 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
|
16 |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
17 private static final Logger log = |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
18 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
|
19 |
0c7847b8e85e
Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2063
diff
changeset
|
20 |
2063
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 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
|
22 |
2127
0c7847b8e85e
Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2063
diff
changeset
|
23 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
|
24 |
2063
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 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
|
27 } |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 |
2127
0c7847b8e85e
Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2063
diff
changeset
|
29 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
|
30 |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
31 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
|
32 |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
33 FastAnnotations.Annotation an = fas.findByKm(km); |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
34 |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
35 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
|
36 } |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
37 |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
38 public static FastAnnotations getAnnotations(String river) { |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
39 return getAnnotations(river, Double.NaN); |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
40 } |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
41 |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
42 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
|
43 |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
44 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
|
45 |
2127
0c7847b8e85e
Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2063
diff
changeset
|
46 if (cache == null) { |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
47 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
|
48 } |
2127
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 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
|
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 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
|
53 |
0c7847b8e85e
Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2063
diff
changeset
|
54 if (element != null) { |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
55 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
|
56 } |
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 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
|
59 |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
60 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
|
61 |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
62 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
|
63 } |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
64 |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
65 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
|
66 String river, |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
67 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
|
68 ) { |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
69 if (km != Double.MAX_VALUE) { |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
70 // XXX Fake it by using a standard Annotation. |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
71 |
2127
0c7847b8e85e
Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2063
diff
changeset
|
72 Annotation annotation = |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
73 AnnotationsFactory.getAnnotation(river, km); |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
74 |
2127
0c7847b8e85e
Speed up the join of calculation results and the km annotations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2063
diff
changeset
|
75 if (annotation != null) { |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
76 FastAnnotations.Annotation fa = |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
77 new FastAnnotations.Annotation( |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
78 km, Double.NaN, |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
79 annotation.getPosition().getValue(), null, null, |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
80 Double.NaN, Double.NaN); |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
81 return new FastAnnotations( |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
82 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
|
83 } |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
84 |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
85 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
|
86 } |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
87 |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
88 long startTime = System.currentTimeMillis(); |
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 FastAnnotations fas = new FastAnnotations(river); |
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 long stopTime = System.currentTimeMillis(); |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
93 |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
94 if (log.isDebugEnabled()) { |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
95 log.debug("Loading locations took " + |
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
96 (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
|
97 } |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
98 |
2144
a4bdf7d8527e
Use FastAnnotations for LocationProvider.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2127
diff
changeset
|
99 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
|
100 } |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
101 } |
97a25b54eea3
Part 1 of #125: added a description for a location to the WaterlevelExport.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
102 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |