Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FastCrossSectionLineFactory.java @ 2119:dc28ea60b53d
Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines.
flys-artifacts/trunk@3689 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 16 Jan 2012 15:51:46 +0000 |
parents | |
children | d626ae185305 |
comparison
equal
deleted
inserted
replaced
2118:4d57d456e261 | 2119:dc28ea60b53d |
---|---|
1 package de.intevation.flys.artifacts.model; | |
2 | |
3 import de.intevation.flys.artifacts.cache.CacheFactory; | |
4 | |
5 import de.intevation.flys.model.CrossSection; | |
6 import de.intevation.flys.model.CrossSectionLine; | |
7 | |
8 import net.sf.ehcache.Cache; | |
9 import net.sf.ehcache.Element; | |
10 | |
11 import java.util.List; | |
12 | |
13 | |
14 public class FastCrossSectionLineFactory | |
15 { | |
16 public static final String CACHE_NAME = "fast-cross-section-lines"; | |
17 | |
18 private FastCrossSectionLineFactory() { | |
19 } | |
20 | |
21 public static FastCrossSectionLine getCrossSectionLine( | |
22 CrossSection cs, | |
23 double km | |
24 ) { | |
25 Cache cache = CacheFactory.getCache(CACHE_NAME); | |
26 | |
27 if (cache == null) { | |
28 List<CrossSectionLine> lines = cs.getLines(km, km); | |
29 return lines.isEmpty() | |
30 ? null | |
31 : new FastCrossSectionLine(lines.get(0)); | |
32 } | |
33 | |
34 String cacheKey = FastCrossSectionChunk.createHashKey(cs, km); | |
35 | |
36 Element element = cache.get(cacheKey); | |
37 | |
38 FastCrossSectionChunk fcsc; | |
39 | |
40 if (element != null) { | |
41 fcsc = (FastCrossSectionChunk)element.getValue(); | |
42 } | |
43 else { | |
44 fcsc = new FastCrossSectionChunk(cs, km); | |
45 element = new Element(cacheKey, fcsc); | |
46 cache.put(element); | |
47 } | |
48 | |
49 return fcsc.getCrossSectionLine(km); | |
50 } | |
51 } | |
52 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |