|
57 | 57 | import java.io.FilenameFilter; |
58 | 58 |
|
59 | 59 | /** |
60 | | - * Useful utilities for working with file filters. |
| 60 | + * Useful utilities for working with file filters. It provides access to all |
| 61 | + * file filter implementations in this package so you don't have to import |
| 62 | + * every classes you use. |
61 | 63 | * |
62 | 64 | * @since Commons IO 1.0 |
63 | | - * @version $Revision: 1.5 $ $Date: 2003/10/13 07:03:50 $ |
| 65 | + * @version $Revision: 1.6 $ $Date: 2003/11/22 20:03:52 $ |
64 | 66 | * |
65 | 67 | * @author Henri Yandell |
66 | 68 | * @author Stephen Colebourne |
| 69 | + * @author Jeremias Maerki |
67 | 70 | */ |
68 | 71 | public class FileFilterUtils { |
69 | 72 |
|
@@ -94,6 +97,16 @@ public static IOFileFilter suffixFileFilter(String suffix) { |
94 | 97 | return new SuffixFileFilter(suffix); |
95 | 98 | } |
96 | 99 |
|
| 100 | + /** |
| 101 | + * Returns a filter that returns true if the filename matches the specified text. |
| 102 | + * |
| 103 | + * @param name the filename |
| 104 | + * @return a name checking filter |
| 105 | + */ |
| 106 | + public static IOFileFilter nameFileFilter(String name) { |
| 107 | + return new NameFileFilter(name); |
| 108 | + } |
| 109 | + |
97 | 110 | /** |
98 | 111 | * Returns a filter that checks if the file is a directory. |
99 | 112 | * |
@@ -178,4 +191,29 @@ public static IOFileFilter asFileFilter(FilenameFilter filter) { |
178 | 191 | return new DelegateFileFilter(filter); |
179 | 192 | } |
180 | 193 |
|
| 194 | + //----------------------------------------------------------------------- |
| 195 | + |
| 196 | + /* Constructed on demand and then cached */ |
| 197 | + private static IOFileFilter cvsFilter = null; |
| 198 | + |
| 199 | + /** |
| 200 | + * Resturns an IOFileFilter that ignores CVS directories. You may optionally |
| 201 | + * pass in an existing IOFileFilter in which case it is extended to exclude |
| 202 | + * CVS directories. |
| 203 | + * @param filter IOFileFilter to modify, null if a new IOFileFilter |
| 204 | + * should be created |
| 205 | + * @return the requested (combined) filter |
| 206 | + */ |
| 207 | + public static IOFileFilter makeCVSAware(IOFileFilter filter) { |
| 208 | + if (cvsFilter == null) { |
| 209 | + cvsFilter = andFileFilter(directoryFileFilter(), |
| 210 | + notFileFilter(nameFileFilter("CVS"))); |
| 211 | + } |
| 212 | + if (filter == null) { |
| 213 | + return cvsFilter; |
| 214 | + } else { |
| 215 | + return andFileFilter(filter, cvsFilter); |
| 216 | + } |
| 217 | + } |
| 218 | + |
181 | 219 | } |
0 commit comments