View Javadoc
1 package net.sf.plb4jedit.plb; 2 3 import java.io.FileNotFoundException; 4 import java.io.IOException; 5 import java.util.Map; 6 import java.util.Set; 7 import java.util.WeakHashMap; 8 9 import org.gjt.sp.util.Log; 10 /*** 11 * implements a caching mechanism for Include objects. 12 * 13 * TODO: handle MAX_ENTRY, at the moment only a WeakHashMap is used. 14 * 15 * * @author Peter Schaefer 16 */ 17 public class IncludeCache { 18 private static int MAX_ENTRY = 100; 19 Map cache; 20 /*** singleton instance of this instance */ 21 private static IncludeCache instance; 22 23 /*** singleton: use getInstance */ 24 private IncludeCache(){ 25 // TODO handle MAX_ENTRY 26 cache = new WeakHashMap(MAX_ENTRY); 27 } 28 29 /*** 30 * gives access to the singletion instance of this cache. 31 * @return IncludeCache 32 */ 33 public static IncludeCache getInstance() { 34 if (instance == null) { 35 instance = new IncludeCache(); 36 } 37 return instance; 38 } 39 40 /*** 41 * gets the Include specified by its absolute path. If an instance of this include is in 42 * the cache, this is returned, otherwise a new instance is created.. 43 * @param absolutePath 44 * @return 45 * @throws FileNotFoundException 46 * @throws IOException 47 */ 48 public Include get(String absolutePath) throws FileNotFoundException, IOException { 49 if (cache.containsKey(absolutePath)) { 50 return (Include)cache.get(absolutePath); 51 } else { 52 Include inc = new Include(absolutePath); 53 Log.log(Log.DEBUG,this,"add entry no " + cache.size() + " " + absolutePath); 54 cache.put(absolutePath,inc); 55 return inc; 56 } 57 } 58 59 /*** 60 * actual content (keys, Strings of absolutePath) of the cache 61 * @return 62 */ 63 public Set content() { 64 return cache.keySet(); 65 } 66 67 /*** 68 * actual size of this cache 69 * @return 70 */ 71 public int getSize() { 72 return cache.size(); 73 } 74 75 }

This page was automatically generated by Maven