1 package com.atlassian.seraph.util; 2 3 import java.util.Map ; 4 import java.util.Collections ; 5 import java.util.Collection ; 6 7 16 17 20 public class CachedPathMapper extends PathMapper 21 { 22 private Map cacheMap; 23 private Map cacheAllMap; 24 25 32 public CachedPathMapper(Map cacheMap, Map cacheAllMap) 33 { 34 this.cacheMap = Collections.synchronizedMap(cacheMap); 36 this.cacheAllMap = Collections.synchronizedMap(cacheAllMap); 37 } 38 39 public String get(String path) 40 { 41 if (cacheMap.containsKey(path)) 43 { 44 return (String ) cacheMap.get(path); 46 } 47 final String result = super.get(path); 49 cacheMap.put(path, result); 51 return result; 52 } 53 54 public Collection getAll(String path) 55 { 56 if (cacheAllMap.containsKey(path)) 58 { 59 return (Collection ) cacheAllMap.get(path); 61 } 62 final Collection result = super.getAll(path); 64 cacheAllMap.put(path, result); 66 return result; 67 } 68 69 public void put(String key, String pattern) 70 { 71 if (cacheMap.containsKey(key)) 73 { 74 cacheMap.remove(key); 75 } 76 if (cacheAllMap.containsKey(key)) 77 { 78 cacheAllMap.remove(key); 79 } 80 super.put(key, pattern); 82 } 83 } 84 | Popular Tags |