Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/FastCrossSectionLineFactory.java @ 5838:5aa05a7a34b7
Rename modules to more fitting names.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 15:23:37 +0200 |
parents | flys-artifacts/src/main/java/org/dive4elements/river/artifacts/model/FastCrossSectionLineFactory.java@bd047b71ab37 |
children | 4897a58c8746 |
comparison
equal
deleted
inserted
replaced
5837:d9901a08d0a6 | 5838:5aa05a7a34b7 |
---|---|
1 package org.dive4elements.river.artifacts.model; | |
2 | |
3 import org.dive4elements.river.artifacts.cache.CacheFactory; | |
4 | |
5 import org.dive4elements.river.model.CrossSection; | |
6 | |
7 import org.dive4elements.river.model.FastCrossSectionLine; | |
8 | |
9 import net.sf.ehcache.Cache; | |
10 import net.sf.ehcache.Element; | |
11 | |
12 import java.util.List; | |
13 | |
14 import org.apache.log4j.Logger; | |
15 | |
16 public class FastCrossSectionLineFactory | |
17 { | |
18 private static Logger log = | |
19 Logger.getLogger(FastCrossSectionLineFactory.class); | |
20 | |
21 public static final String CACHE_NAME = "fast-cross-section-lines"; | |
22 | |
23 private FastCrossSectionLineFactory() { | |
24 } | |
25 | |
26 public static FastCrossSectionLine getCrossSectionLine( | |
27 CrossSection cs, | |
28 double km | |
29 ) { | |
30 Cache cache = CacheFactory.getCache(CACHE_NAME); | |
31 | |
32 boolean debug = log.isDebugEnabled(); | |
33 | |
34 if (cache == null) { | |
35 if (debug) { | |
36 log.debug("No cross section chunk cache configured."); | |
37 } | |
38 List<FastCrossSectionLine> lines = cs.getFastLines(km, km); | |
39 return lines.isEmpty() ? null : lines.get(0); | |
40 } | |
41 | |
42 String cacheKey = FastCrossSectionChunk.createHashKey(cs, km); | |
43 | |
44 Element element = cache.get(cacheKey); | |
45 | |
46 FastCrossSectionChunk fcsc; | |
47 | |
48 if (element != null) { | |
49 if (debug) { | |
50 log.debug("Found cross section chunk in cache id: " + | |
51 cs.getId() + " km: " + km); | |
52 } | |
53 | |
54 fcsc = (FastCrossSectionChunk)element.getValue(); | |
55 } | |
56 else { | |
57 if (debug) { | |
58 log.debug("Not found cross section chunk in cache id: " + | |
59 cs.getId() + " km: " + km + " -> loading"); | |
60 } | |
61 fcsc = new FastCrossSectionChunk(cs, km); | |
62 element = new Element(cacheKey, fcsc); | |
63 cache.put(element); | |
64 } | |
65 | |
66 return fcsc.getCrossSectionLine(km); | |
67 } | |
68 } | |
69 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |