Author: scolebourne Date: Sun Jul 23 06:58:32 2006 New Revision: 424742 URL: http://svn.apache.org/viewvc?rev=424742&view=rev Log: Add FileFileFilter that accepts files and not directories
Added: jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/FileFileFilter.java (with props) Modified: jakarta/commons/proper/io/trunk/RELEASE-NOTES.txt jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/FileFilterUtils.java jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/filefilter/FileFilterTestCase.java Modified: jakarta/commons/proper/io/trunk/RELEASE-NOTES.txt URL: http://svn.apache.org/viewvc/jakarta/commons/proper/io/trunk/RELEASE-NOTES.txt?rev=424742&r1=424741&r2=424742&view=diff ============================================================================== --- jakarta/commons/proper/io/trunk/RELEASE-NOTES.txt (original) +++ jakarta/commons/proper/io/trunk/RELEASE-NOTES.txt Sun Jul 23 06:58:32 2006 @@ -54,6 +54,11 @@ - NameFileFilter - Ability to control case-sensitivity +- FileFileFilter + - New IOFileFilter implementation + - Accepts files where File.isFile() is true + - In other words it filters out directories + - CanReadFileFilter - New IOFileFilter implementation - Accepts files where File.canRead() is true Added: jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/FileFileFilter.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/FileFileFilter.java?rev=424742&view=auto ============================================================================== --- jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/FileFileFilter.java (added) +++ jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/FileFileFilter.java Sun Jul 23 06:58:32 2006 @@ -0,0 +1,58 @@ +/* + * Copyright 2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.io.filefilter; + +import java.io.File; + +/** + * This filter accepts <code>File</code>s that are files (not directories). + * <p> + * For example, here is how to print out a list of the real files + * within the current directory: + * + * <pre> + * File dir = new File("."); + * String[] files = dir.list( FileFileFilter.FILE ); + * for ( int i = 0; i < files.length; i++ ) { + * System.out.println(files[i]); + * } + * </pre> + * + * @since Commons IO 1.3 + * @version $Revision: 155419 $ $Date: 2005-02-26 13:02:41 +0000 (Sat, 26 Feb 2005) $ + */ +public class FileFileFilter extends AbstractFileFilter { + + /** Singleton instance of file filter */ + public static final IOFileFilter FILE = new FileFileFilter(); + + /** + * Restrictive consructor. + */ + protected FileFileFilter() { + } + + /** + * Checks to see if the file is a file. + * + * @param file the File to check + * @return true if the file is a file + */ + public boolean accept(File file) { + return file.isFile(); + } + +} Propchange: jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/FileFileFilter.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/FileFileFilter.java ------------------------------------------------------------------------------ svn:keywords = author date id revision Modified: jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/FileFilterUtils.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/FileFilterUtils.java?rev=424742&r1=424741&r2=424742&view=diff ============================================================================== --- jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/FileFilterUtils.java (original) +++ jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/FileFilterUtils.java Sun Jul 23 06:58:32 2006 @@ -76,12 +76,21 @@ /** * Returns a filter that checks if the file is a directory. * - * @return directory file filter + * @return file filter that accepts only directories and not files */ public static IOFileFilter directoryFileFilter() { return DirectoryFileFilter.INSTANCE; } - + + /** + * Returns a filter that checks if the file is a file (and not a directory). + * + * @return file filter that accepts only files and not directories + */ + public static IOFileFilter fileFileFilter() { + return FileFileFilter.FILE; + } + //----------------------------------------------------------------------- /** * Returns a filter that ANDs the two specified filters. Modified: jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/filefilter/FileFilterTestCase.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/filefilter/FileFilterTestCase.java?rev=424742&r1=424741&r2=424742&view=diff ============================================================================== --- jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/filefilter/FileFilterTestCase.java (original) +++ jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/filefilter/FileFilterTestCase.java Sun Jul 23 06:58:32 2006 @@ -138,6 +138,21 @@ assertFiltering(filter, new File("STATUS.html"), false); } + public void testFiles() throws Exception { + // XXX: This test presumes the current working dir is the base dir of the source checkout. + IOFileFilter filter = FileFileFilter.FILE; + + assertFiltering(filter, new File("src/"), false); + assertFiltering(filter, new File("src/java/"), false); + + assertFiltering(filter, new File("project.xml"), true); + + assertFiltering(filter, new File("imaginary"), false); + assertFiltering(filter, new File("imaginary/"), false); + + assertFiltering(filter, new File("STATUS.html"), true); + } + public void testPrefix() throws Exception { IOFileFilter filter = new PrefixFileFilter(new String[] { "foo", "bar" }); File testFile = new File( "test" ); --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]