Mercurial > hg > digilib-old
comparison servlet/src/digilib/io/DocuDirCache.java @ 270:b21915a3fc24
Servlet version 1.21b3
- searching in directories got faster (real binarySearch now!)
- cached file lists get disposed
- some code cleaning (Map types instead of HashMap)
| author | robcast |
|---|---|
| date | Tue, 12 Oct 2004 16:06:43 +0200 |
| parents | beed92ee6022 |
| children | 87dca7119596 |
comparison
equal
deleted
inserted
replaced
| 269:6e6bf5aa7ad2 | 270:b21915a3fc24 |
|---|---|
| 25 import java.io.File; | 25 import java.io.File; |
| 26 import java.util.HashMap; | 26 import java.util.HashMap; |
| 27 import java.util.Iterator; | 27 import java.util.Iterator; |
| 28 import java.util.LinkedList; | 28 import java.util.LinkedList; |
| 29 import java.util.List; | 29 import java.util.List; |
| 30 import java.util.Map; | |
| 30 | 31 |
| 31 import org.apache.log4j.Logger; | 32 import org.apache.log4j.Logger; |
| 32 | 33 |
| 33 import digilib.servlet.DigilibConfiguration; | 34 import digilib.servlet.DigilibConfiguration; |
| 34 | 35 |
| 36 * @author casties | 37 * @author casties |
| 37 */ | 38 */ |
| 38 public class DocuDirCache { | 39 public class DocuDirCache { |
| 39 | 40 |
| 40 /** general logger for this class */ | 41 /** general logger for this class */ |
| 41 protected Logger logger = Logger.getLogger(this.getClass()); | 42 Logger logger = Logger.getLogger(this.getClass()); |
| 42 /** HashMap of directories */ | 43 /** HashMap of directories */ |
| 43 protected HashMap map = null; | 44 Map map = null; |
| 44 /** names of base directories */ | 45 /** names of base directories */ |
| 45 private String[] baseDirNames = null; | 46 String[] baseDirNames = null; |
| 46 /** array of allowed file classes (image/text) */ | 47 /** array of allowed file classes (image/text) */ |
| 47 private int[] fileClasses = null; | 48 private int[] fileClasses = null; |
| 48 /** number of files in the whole cache (approximate) */ | 49 /** number of files in the whole cache (approximate) */ |
| 49 private long numFiles = 0; | 50 long numFiles = 0; |
| 50 /** number of cache hits */ | 51 /** number of cache hits */ |
| 51 private long hits = 0; | 52 long hits = 0; |
| 52 /** number of cache misses */ | 53 /** number of cache misses */ |
| 53 private long misses = 0; | 54 long misses = 0; |
| 54 /** use safe (but slow) indexing */ | 55 /** use safe (but slow) indexing */ |
| 55 boolean safeDirIndex = false; | 56 boolean safeDirIndex = false; |
| 57 /** the root directory element */ | |
| 58 public static Directory ROOT = null; | |
| 56 | 59 |
| 57 /** | 60 /** |
| 58 * Constructor with array of base directory names and file classes. | 61 * Constructor with array of base directory names and file classes. |
| 59 * | 62 * |
| 60 * @param bd | 63 * @param bd |
| 109 * | 112 * |
| 110 * @param newDir | 113 * @param newDir |
| 111 */ | 114 */ |
| 112 public void putDir(DocuDirectory newDir) { | 115 public void putDir(DocuDirectory newDir) { |
| 113 put(newDir); | 116 put(newDir); |
| 114 String parent = newDir.getParentDirName(); | 117 String parent = FileOps.parent(newDir.getDirName()); |
| 115 if (parent != null) { | 118 if (parent != "") { |
| 116 // check the parent in the cache | 119 // check the parent in the cache |
| 117 DocuDirectory pd = (DocuDirectory) map.get(parent); | 120 DocuDirectory pd = (DocuDirectory) map.get(parent); |
| 118 if (pd == null) { | 121 if (pd == null) { |
| 119 // the parent is unknown | 122 // the parent is unknown |
| 120 pd = new DocuDirectory(parent, this); | 123 pd = new DocuDirectory(parent, this); |
| 144 if (recurse) { | 147 if (recurse) { |
| 145 if (dd.getDirName().startsWith(dirname)) { | 148 if (dd.getDirName().startsWith(dirname)) { |
| 146 l.add(dd); | 149 l.add(dd); |
| 147 } | 150 } |
| 148 } else { | 151 } else { |
| 149 if (dd.getParentDirName().equals(dirname)) { | 152 if (FileOps.parent(dd.getDirName()).equals(dirname)) { |
| 150 l.add(dd); | 153 l.add(dd); |
| 151 } | 154 } |
| 152 } | 155 } |
| 153 } | 156 } |
| 154 return l; | 157 return l; |
