Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 93624 invoked from network); 28 Sep 2010 22:53:20 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 28 Sep 2010 22:53:20 -0000 Received: (qmail 50191 invoked by uid 500); 28 Sep 2010 22:53:19 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 50018 invoked by uid 500); 28 Sep 2010 22:53:19 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 50010 invoked by uid 99); 28 Sep 2010 22:53:19 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Sep 2010 22:53:19 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Sep 2010 22:53:16 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id A118C23889EB; Tue, 28 Sep 2010 22:52:54 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1002394 - in /commons/proper/io/trunk/src: java/org/apache/commons/io/filefilter/FileFilterUtils.java test/org/apache/commons/io/filefilter/FileFilterTestCase.java Date: Tue, 28 Sep 2010 22:52:54 -0000 To: commits@commons.apache.org From: niallp@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100928225254.A118C23889EB@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: niallp Date: Tue Sep 28 22:52:54 2010 New Revision: 1002394 URL: http://svn.apache.org/viewvc?rev=1002394&view=rev Log: IO-229 FileFilterUtils - add varargs methods for AndFileFilter and OrFileFilter - thanks to Michael Wooten Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/FileFilterUtils.java commons/proper/io/trunk/src/test/org/apache/commons/io/filefilter/FileFilterTestCase.java Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/FileFilterUtils.java URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/FileFilterUtils.java?rev=1002394&r1=1002393&r2=1002394&view=diff ============================================================================== --- commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/FileFilterUtils.java (original) +++ commons/proper/io/trunk/src/java/org/apache/commons/io/filefilter/FileFilterUtils.java Tue Sep 28 22:52:54 2010 @@ -19,7 +19,9 @@ package org.apache.commons.io.filefilter import java.io.File; import java.io.FileFilter; import java.io.FilenameFilter; +import java.util.ArrayList; import java.util.Date; +import java.util.List; import org.apache.commons.io.IOCase; @@ -136,6 +138,7 @@ public class FileFilterUtils { * @param filter1 the first filter * @param filter2 the second filter * @return a filter that ANDs the two specified filters + * @deprecated use {@link #and(IOFileFilter...)} */ public static IOFileFilter andFileFilter(IOFileFilter filter1, IOFileFilter filter2) { return new AndFileFilter(filter1, filter2); @@ -147,12 +150,64 @@ public class FileFilterUtils { * @param filter1 the first filter * @param filter2 the second filter * @return a filter that ORs the two specified filters + * @deprecated use {@link #or(IOFileFilter...)} */ public static IOFileFilter orFileFilter(IOFileFilter filter1, IOFileFilter filter2) { return new OrFileFilter(filter1, filter2); } /** + * Returns a filter that ANDs the specified filters. + * + * @param filters the IOFileFilters that will be ANDed together. + * @return a filter that ANDs the specified filters + * + * @throws IllegalArgumentException if the filters are null or contain a + * null value. + * @since Commons IO 2.0 + */ + public static IOFileFilter and(IOFileFilter... filters) { + return new AndFileFilter(toList(filters)); + } + + /** + * Returns a filter that ORs the specified filters. + * + * @param filters the IOFileFilters that will be ORed together. + * @return a filter that ORs the specified filters + * + * @throws IllegalArgumentException if the filters are null or contain a + * null value. + * @since Commons IO 2.0 + */ + public static IOFileFilter or(IOFileFilter... filters) { + return new OrFileFilter(toList(filters)); + } + + /** + * Create a List of file filters. + * + * @param filters The file filters + * @return The list of file filters + * @throws IllegalArgumentException if the filters are null or contain a + * null value. + * @since Commons IO 2.0 + */ + public static List toList(IOFileFilter... filters) { + if (filters == null) { + throw new IllegalArgumentException("The filters must not be null"); + } + List list = new ArrayList(filters.length); + for (int i = 0; i < filters.length; i++) { + if (filters[i] == null) { + throw new IllegalArgumentException("The filter[" + i + "] is null"); + } + list.add(filters[i]); + } + return list; + } + + /** * Returns a filter that NOTs the specified filter. * * @param filter the filter to invert Modified: commons/proper/io/trunk/src/test/org/apache/commons/io/filefilter/FileFilterTestCase.java URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/org/apache/commons/io/filefilter/FileFilterTestCase.java?rev=1002394&r1=1002393&r2=1002394&view=diff ============================================================================== --- commons/proper/io/trunk/src/test/org/apache/commons/io/filefilter/FileFilterTestCase.java (original) +++ commons/proper/io/trunk/src/test/org/apache/commons/io/filefilter/FileFilterTestCase.java Tue Sep 28 22:52:54 2010 @@ -482,6 +482,24 @@ public class FileFilterTestCase extends OrFileFilter f = new OrFileFilter((List) null); assertEquals(true, f.getFileFilters().isEmpty()); } + public void testFileFilterUtils_and() throws Exception { + IOFileFilter trueFilter = TrueFileFilter.INSTANCE; + IOFileFilter falseFilter = FalseFileFilter.INSTANCE; + assertFiltering(FileFilterUtils.and(trueFilter, trueFilter, trueFilter), new File("foo.test"), true); + assertFiltering(FileFilterUtils.and(trueFilter, falseFilter, trueFilter), new File("foo.test"), false); + assertFiltering(FileFilterUtils.and(falseFilter, trueFilter), new File("foo.test"), false); + assertFiltering(FileFilterUtils.and(falseFilter, falseFilter), new File("foo.test"), false); + } + + public void testFileFilterUtils_or() throws Exception { + IOFileFilter trueFilter = TrueFileFilter.INSTANCE; + IOFileFilter falseFilter = FalseFileFilter.INSTANCE; + File testFile = new File( "foo.test" ); + assertFiltering(FileFilterUtils.or(trueFilter, trueFilter), testFile, true); + assertFiltering(FileFilterUtils.or(trueFilter, trueFilter, falseFilter), testFile, true); + assertFiltering(FileFilterUtils.or(falseFilter, trueFilter), testFile, true); + assertFiltering(FileFilterUtils.or(falseFilter, falseFilter, falseFilter), testFile, false); + } @SuppressWarnings("deprecation") public void testDeprecatedWildcard() throws Exception {