comparison servlet/src/digilib/io/DocuDirectory.java @ 571:6e8488acb499

fixed default file class for DocuDir.size()
author robcast
date Wed, 22 Dec 2010 14:46:00 +0100
parents 686086d6e6d6
children 3e3e1b7d659f 4f5aaa0de456
comparison
equal deleted inserted replaced
570:fd2ef7e46119 571:6e8488acb499
38 public class DocuDirectory extends Directory { 38 public class DocuDirectory extends Directory {
39 39
40 /** list of files (DocuDirent) */ 40 /** list of files (DocuDirent) */
41 private List<List<DocuDirent>> list = null; 41 private List<List<DocuDirent>> list = null;
42 42
43 /** default FileClass for unspecified calls */
44 public static FileClass defaultFileClass = FileClass.IMAGE;
45
43 /** directory object is valid (exists on disk) */ 46 /** directory object is valid (exists on disk) */
44 private boolean isValid = false; 47 private boolean isValid = false;
45 48
46 /** reference of the parent DocuDirCache */ 49 /** reference of the parent DocuDirCache */
47 private DocuDirCache cache = null; 50 private DocuDirCache cache = null;
106 /** 109 /**
107 * number of DocuFiles in this directory. 110 * number of DocuFiles in this directory.
108 * 111 *
109 */ 112 */
110 public int size() { 113 public int size() {
111 return ((list != null) && (list.get(0) != null)) ? list.get(0).size() : 0; 114 return size(defaultFileClass);
112 } 115 }
113 116
114 /** 117 /**
115 * number of files of this class in this directory. 118 * number of files of this class in this directory.
116 * 119 *
117 * @param fc 120 * @param fc
118 * fileClass 121 * fileClass
119 */ 122 */
120 public int size(FileClass fc) { 123 public int size(FileClass fc) {
121 return ((list != null) && (list.get(fc.ordinal()) != null)) ? list.get(fc.ordinal()).size() : 0; 124 if (list != null) {
125 List<DocuDirent> l = list.get(fc.ordinal());
126 if (l != null) {
127 return l.size();
128 }
129 }
130 return 0;
122 } 131 }
123 132
124 /** 133 /**
125 * Returns the ImageFileSet at the index. 134 * Returns the ImageFileSet at the index.
126 * 135 *
127 * @param index 136 * @param index
128 * @return 137 * @return
129 */ 138 */
130 public ImageFileset get(int index) { 139 public ImageFileset get(int index) {
131 if ((list == null) || (list.get(0) == null) || (index >= list.get(0).size())) { 140 return (ImageFileset) get(index, defaultFileClass);
132 return null;
133 }
134 return (ImageFileset) list.get(0).get(index);
135 } 141 }
136 142
137 /** 143 /**
138 * Returns the file of the class at the index. 144 * Returns the file of the class at the index.
139 * 145 *
466 * @param fn 472 * @param fn
467 * filename 473 * filename
468 * @return DocuDirent 474 * @return DocuDirent
469 */ 475 */
470 public DocuDirent find(String fn) { 476 public DocuDirent find(String fn) {
471 FileClass fc = FileOps.classForFilename(fn); 477 return find(fn, defaultFileClass);
472 int i = indexOf(fn, fc);
473 if (i >= 0) {
474 return (DocuDirent) list.get(0).get(i);
475 }
476 return null;
477 } 478 }
478 479
479 /** 480 /**
480 * Finds the DocuDirent with the name <code>fn</code> and class 481 * Finds the DocuDirent with the name <code>fn</code> and class
481 * <code>fc</code>. 482 * <code>fc</code>.