Mercurial > hg > digilib-old
comparison servlet/src/digilib/io/DocuDirCache.java @ 282:87dca7119596
Servlet version 1.22b1
- more fast searching (hopefully all working now)
- some simple synchronisation
- some reshuffling of methods to eliminate cruft
author | robcast |
---|---|
date | Fri, 15 Oct 2004 16:59:47 +0200 |
parents | b21915a3fc24 |
children | dd1e681924bf |
comparison
equal
deleted
inserted
replaced
281:60a064f27d25 | 282:87dca7119596 |
---|---|
38 */ | 38 */ |
39 public class DocuDirCache { | 39 public class DocuDirCache { |
40 | 40 |
41 /** general logger for this class */ | 41 /** general logger for this class */ |
42 Logger logger = Logger.getLogger(this.getClass()); | 42 Logger logger = Logger.getLogger(this.getClass()); |
43 | |
43 /** HashMap of directories */ | 44 /** HashMap of directories */ |
44 Map map = null; | 45 Map map = null; |
46 | |
45 /** names of base directories */ | 47 /** names of base directories */ |
46 String[] baseDirNames = null; | 48 String[] baseDirNames = null; |
49 | |
47 /** array of allowed file classes (image/text) */ | 50 /** array of allowed file classes (image/text) */ |
48 private int[] fileClasses = null; | 51 private int[] fileClasses = null; |
52 | |
49 /** number of files in the whole cache (approximate) */ | 53 /** number of files in the whole cache (approximate) */ |
50 long numFiles = 0; | 54 long numFiles = 0; |
55 | |
51 /** number of cache hits */ | 56 /** number of cache hits */ |
52 long hits = 0; | 57 long hits = 0; |
58 | |
53 /** number of cache misses */ | 59 /** number of cache misses */ |
54 long misses = 0; | 60 long misses = 0; |
61 | |
55 /** use safe (but slow) indexing */ | 62 /** use safe (but slow) indexing */ |
56 boolean safeDirIndex = false; | 63 boolean safeDirIndex = false; |
64 | |
57 /** the root directory element */ | 65 /** the root directory element */ |
58 public static Directory ROOT = null; | 66 public static Directory ROOT = null; |
59 | 67 |
60 /** | 68 /** |
61 * Constructor with array of base directory names and file classes. | 69 * Constructor with array of base directory names and file classes. |
62 * | 70 * |
63 * @param bd | 71 * @param bd |
64 * base directory names | 72 * base directory names |
65 */ | 73 */ |
66 public DocuDirCache(String[] bd, int[] fileClasses, DigilibConfiguration dlConfig) { | 74 public DocuDirCache(String[] bd, int[] fileClasses, |
75 DigilibConfiguration dlConfig) { | |
67 baseDirNames = bd; | 76 baseDirNames = bd; |
68 map = new HashMap(); | 77 map = new HashMap(); |
69 this.fileClasses = fileClasses; | 78 this.fileClasses = fileClasses; |
70 safeDirIndex = dlConfig.getAsBoolean("safe-dir-index"); | 79 safeDirIndex = dlConfig.getAsBoolean("safe-dir-index"); |
71 } | 80 } |
81 | |
72 /** | 82 /** |
73 * Constructor with array of base directory names. | 83 * Constructor with array of base directory names. |
74 * | 84 * |
75 * @param bd | 85 * @param bd |
76 * base directory names | 86 * base directory names |
110 /** | 120 /** |
111 * Add a directory to the cache and check its parents. | 121 * Add a directory to the cache and check its parents. |
112 * | 122 * |
113 * @param newDir | 123 * @param newDir |
114 */ | 124 */ |
115 public void putDir(DocuDirectory newDir) { | 125 public synchronized void putDir(DocuDirectory newDir) { |
116 put(newDir); | 126 put(newDir); |
117 String parent = FileOps.parent(newDir.getDirName()); | 127 String parent = FileOps.parent(newDir.getDirName()); |
118 if (parent != "") { | 128 if (parent != "") { |
119 // check the parent in the cache | 129 // check the parent in the cache |
120 DocuDirectory pd = (DocuDirectory) map.get(parent); | 130 DocuDirectory pd = (DocuDirectory) map.get(parent); |
128 } | 138 } |
129 | 139 |
130 /** | 140 /** |
131 * Get a list with all children of a directory. | 141 * Get a list with all children of a directory. |
132 * | 142 * |
133 * Returns a List of DocuDirectory's. Returns an empty List if the | 143 * Returns a List of DocuDirectory's. Returns an empty List if the directory |
134 * directory has no children. If recurse is false then only direct children | 144 * has no children. If recurse is false then only direct children are |
135 * are returned. | 145 * returned. |
136 * | 146 * |
137 * @param dirname | 147 * @param dirname |
138 * @param recurse | 148 * @param recurse |
139 * find all children and their children. | 149 * find all children and their children. |
140 * @return | 150 * @return |
156 } | 166 } |
157 return l; | 167 return l; |
158 } | 168 } |
159 | 169 |
160 /** | 170 /** |
161 * Returns the DocuDirent with the pathname <code>fn</code> and the | 171 * Returns the DocuDirent with the pathname <code>fn</code> and the index |
162 * index <code>in</code> and the class <code>fc</code>. | 172 * <code>in</code> and the class <code>fc</code>. |
163 * | 173 * |
164 * If <code>fn</code> is a file then the corresponding DocuDirent is | 174 * If <code>fn</code> is a file then the corresponding DocuDirent is |
165 * returned and the index is ignored. | 175 * returned and the index is ignored. |
166 * | 176 * |
167 * @param fn | 177 * @param fn |
168 * digilib pathname | 178 * digilib pathname |
169 * @param in | 179 * @param in |
170 * file index | 180 * file index |
171 * @param fc | 181 * @param fc |
172 * file class | 182 * file class |
173 * @return | 183 * @return |
174 */ | 184 */ |
175 public DocuDirent getFile(String fn, int in, int fc) { | 185 public DocuDirent getFile(String fn, int in, int fc) { |
176 DocuDirectory dd; | 186 DocuDirectory dd; |
177 // file number is 1-based, vector index is 0-based | 187 // file number is 1-based, vector index is 0-based |