Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/CrossSectionKMService.java @ 2120:f021080cb409
Use improved caching for cross section lines data.
flys-artifacts/trunk@3690 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 16 Jan 2012 17:38:39 +0000 |
parents | e0b081105a82 |
children |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/CrossSectionKMService.java Mon Jan 16 15:51:46 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/CrossSectionKMService.java Mon Jan 16 17:38:39 2012 +0000 @@ -76,8 +76,6 @@ NodeList crossSectionNodes = data.getElementsByTagName("art:cross-section"); - Cache cache = CacheFactory.getCache(CACHE_NAME); - Document document = XMLUtils.newDocument(); Element all = document.createElement("cross-sections"); @@ -111,25 +109,7 @@ continue; } - NavigableMap<Double, Integer> map; - - if (cache == null) { - map = getUncached(crossSectionId); - } - else { - net.sf.ehcache.Element element = cache.get(crossSectionId); - if (element == null) { - map = getUncached(crossSectionId); - if (map != null) { - element = new net.sf.ehcache.Element( - crossSectionId, map); - cache.put(element); - } - } - else { - map = (NavigableMap<Double, Integer>)element.getValue(); - } - } + NavigableMap<Double, Integer> map = getKms(crossSectionId); if (map == null) { logger.debug("cannot find cross section " + crossSectionId); @@ -159,6 +139,32 @@ return document; } + public static NavigableMap<Double, Integer> getKms(int crossSectionId) { + + Cache cache = CacheFactory.getCache(CACHE_NAME); + + if (cache == null) { + return getUncached(crossSectionId); + } + + NavigableMap<Double, Integer> map; + + net.sf.ehcache.Element element = cache.get(crossSectionId); + if (element == null) { + map = getUncached(crossSectionId); + if (map != null) { + element = new net.sf.ehcache.Element( + crossSectionId, map); + cache.put(element); + } + } + else { + map = (NavigableMap<Double, Integer>)element.getValue(); + } + + return map; + } + /** * @param km the kilometer from which to start searching for other @@ -173,9 +179,10 @@ Deque<Map.Entry<Double, Integer>> result = new ArrayDeque<Map.Entry<Double, Integer>>(2*N); - if(map.get(km) != null) { - result.add(new AbstractMap.SimpleEntry<Double, Integer>(km,map.get(km))); + Integer v = map.get(km); + if (v != null) { + result.add(new AbstractMap.SimpleEntry<Double, Integer>(km, v)); } int i = 0;