Skip to content

Commit 985c183

Browse files
committed
Add the new name filter.
Add method to decorate a filter to become "CVS-aware", thus filtering out all CVS directories. This is driven by some functionality in FileUtils as I'm refactoring that class. git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/io/trunk@140399 13f79535-47bb-0310-9956-ffa450edef68
1 parent ffe3184 commit 985c183

1 file changed

Lines changed: 40 additions & 2 deletions

File tree

src/java/org/apache/commons/io/filefilter/FileFilterUtils.java

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,16 @@
5757
import java.io.FilenameFilter;
5858

5959
/**
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.
6163
*
6264
* @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 $
6466
*
6567
* @author Henri Yandell
6668
* @author Stephen Colebourne
69+
* @author Jeremias Maerki
6770
*/
6871
public class FileFilterUtils {
6972

@@ -94,6 +97,16 @@ public static IOFileFilter suffixFileFilter(String suffix) {
9497
return new SuffixFileFilter(suffix);
9598
}
9699

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+
97110
/**
98111
* Returns a filter that checks if the file is a directory.
99112
*
@@ -178,4 +191,29 @@ public static IOFileFilter asFileFilter(FilenameFilter filter) {
178191
return new DelegateFileFilter(filter);
179192
}
180193

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+
181219
}

0 commit comments

Comments
 (0)