You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ni...@apache.org on 2006/07/22 01:47:00 UTC
svn commit: r424496 - in
/jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder:
./ filters/
Author: niallp
Date: Fri Jul 21 16:46:59 2006
New Revision: 424496
URL: http://svn.apache.org/viewvc?rev=424496&view=rev
Log:
SANDBOX-159 Switch to using Commons IO's IOFileFilter (from java.util.FileFilter) and replace implementations with those from Commons IO where available.
* See JIRA Issue IO-85 wrt to (hopefully) replacing CanReadFilter, CanWriteFilter, HiddenFilter and EmptyFilter at a later date.
* See JIRA Issues IO-66 and IO-74 wrt to (hopefully) replacing RegexFilter
* WildcardFileFilter can probably replace NameFilter when its released in Commons IO 1.3
* Commons IO has a SizeFileFilter but it works slightly differently to SizeFilter
Removed:
jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/AbstractFileFilter.java
jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/CompositeFilter.java
jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/MinFilter.java
jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/NewerFilter.java
jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/TimeFilter.java
jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/TypeFilter.java
Modified:
jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/Finder.java
jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/FindingFilter.java
jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/CanReadFilter.java
jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/CanWriteFilter.java
jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/EmptyFilter.java
jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/HiddenFilter.java
jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/NameFilter.java
jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/PathFilter.java
jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/RegexFilter.java
jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/SizeFilter.java
Modified: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/Finder.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/Finder.java?rev=424496&r1=424495&r2=424496&view=diff
==============================================================================
--- jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/Finder.java (original)
+++ jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/Finder.java Fri Jul 21 16:46:59 2006
@@ -16,13 +16,15 @@
package org.apache.commons.finder;
import java.io.File;
-import java.io.FileFilter;
import java.util.Map;
import org.apache.commons.finder.filters.CanReadFilter;
import org.apache.commons.finder.filters.CanWriteFilter;
import org.apache.commons.finder.filters.EmptyFilter;
import org.apache.commons.finder.filters.HiddenFilter;
-import org.apache.commons.finder.filters.TypeFilter;
+
+import org.apache.commons.io.filefilter.DirectoryFileFilter;
+import org.apache.commons.io.filefilter.IOFileFilter;
+import org.apache.commons.io.filefilter.NotFileFilter;
/**
* A Finder of Files. Though the structure the files are in is
@@ -46,8 +48,8 @@
public static final String TIME = "TIME";
// size based tests
- public static final FileFilter EMPTY = new EmptyFilter(false);
- public static final FileFilter NOT_EMPTY = new EmptyFilter(true);
+ public static final IOFileFilter EMPTY = EmptyFilter.EMPTY;
+ public static final IOFileFilter NOT_EMPTY = EmptyFilter.NOT_EMPTY;
public static final String SIZE = "SIZE";
// name based tests
@@ -59,16 +61,16 @@
public static final String IREGEX = "IREGEX";
// type of file
- public static final FileFilter DIRECTORY = new TypeFilter(true);
- public static final FileFilter FILE = new TypeFilter(false);
- public static final FileFilter HIDDEN = new HiddenFilter(false);
- public static final FileFilter NOT_HIDDEN = new HiddenFilter(true);
+ public static final IOFileFilter DIRECTORY = DirectoryFileFilter.INSTANCE;
+ public static final IOFileFilter FILE = new NotFileFilter(DirectoryFileFilter.INSTANCE);
+ public static final IOFileFilter HIDDEN = HiddenFilter.HIDDEN;
+ public static final IOFileFilter VISIBLE = HiddenFilter.VISIBLE;
// permission replacements
- public static final FileFilter CAN_READ = new CanReadFilter(false);
- public static final FileFilter CANNOT_READ = new CanReadFilter(true);
- public static final FileFilter CAN_WRITE = new CanWriteFilter(false);
- public static final FileFilter CANNOT_WRITE = new CanWriteFilter(true);
+ public static final IOFileFilter CAN_READ = CanReadFilter.CAN_READ;
+ public static final IOFileFilter CANNOT_READ = CanReadFilter.CANNOT_READ;
+ public static final IOFileFilter CAN_WRITE = CanWriteFilter.CAN_WRITE;
+ public static final IOFileFilter CANNOT_WRITE = CanWriteFilter.CANNOT_WRITE;
public void addFindListener(FindListener fl);
public void removeFindListener(FindListener fl);
Modified: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/FindingFilter.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/FindingFilter.java?rev=424496&r1=424495&r2=424496&view=diff
==============================================================================
--- jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/FindingFilter.java (original)
+++ jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/FindingFilter.java Fri Jul 21 16:46:59 2006
@@ -17,17 +17,18 @@
import java.util.Collection;
import java.io.File;
-import java.io.FileFilter;
import java.util.Map;
import java.util.Iterator;
-import org.apache.commons.finder.filters.CompositeFilter;
-import org.apache.commons.finder.filters.MinFilter;
import org.apache.commons.finder.filters.NameFilter;
-import org.apache.commons.finder.filters.NewerFilter;
import org.apache.commons.finder.filters.PathFilter;
import org.apache.commons.finder.filters.RegexFilter;
import org.apache.commons.finder.filters.SizeFilter;
-import org.apache.commons.finder.filters.TimeFilter;
+
+// import org.apache.commons.io.filefilter.WildcardFileFilter; // todo switch to WildcardFileFilter
+import org.apache.commons.io.filefilter.IOFileFilter;
+import org.apache.commons.io.filefilter.AgeFileFilter;
+import org.apache.commons.io.filefilter.NotFileFilter;
+import org.apache.commons.io.filefilter.AndFileFilter;
/**
* Filters that can check whether to include a file in the response or not.
@@ -41,7 +42,10 @@
* @version $Id$
* @since 1.1
*/
-public class FindingFilter extends CompositeFilter {
+public class FindingFilter extends AndFileFilter {
+
+ private static final long MINUTE = 60000L;
+ private static final long DAY = MINUTE * 60L * 24L;
/** The daystart flag. */
private boolean daystart;
@@ -52,7 +56,7 @@
* @param options the options to use
*/
public FindingFilter(Map options) {
- super(false, true);
+ super();
this.daystart = options.containsKey(Finder.DAYSTART);
Collection entries = options.entrySet();
Iterator itr = entries.iterator();
@@ -62,18 +66,21 @@
continue;
}
Object key = entry.getKey();
- if (key instanceof FileFilter) {
- addFilter((FileFilter)key);
+ if (key instanceof IOFileFilter) {
+ addFileFilter((IOFileFilter)key);
} else {
- addFilter(createFilter(key.toString(), entry.getValue()));
+ IOFileFilter filter = createFilter(key.toString(), entry.getValue());
+ if (filter != null) {
+ addFileFilter(filter);
+ }
}
}
}
- private FileFilter createFilter(String option, Object argument) {
+ private IOFileFilter createFilter(String option, Object argument) {
- if (argument instanceof FileFilter) {
- return (FileFilter)argument;
+ if (argument instanceof IOFileFilter) {
+ return (IOFileFilter)argument;
}
boolean invert = false;
@@ -83,52 +90,64 @@
option = option.substring(Finder.NOT.length());
}
if( option.equals(Finder.MIN) ) {
- if (argument instanceof Number) {
- return new MinFilter(invert, ((Number)argument).intValue(), daystart);
- } else {
- return new MinFilter(invert, argument.toString(), daystart);
- }
+ int minutes = toInt(argument);
+ return new AgeFileFilter((long)minutes * MINUTE, invert);
}
if( option.equals(Finder.NEWER) ) {
- if (argument instanceof File) {
- return new NewerFilter(invert, (File)argument);
- } else {
- return new NewerFilter(invert, argument.toString());
- }
+ File refFile = argument instanceof File ? (File)argument : new File(argument.toString());
+ return new AgeFileFilter(refFile, invert);
}
if( option.equals(Finder.TIME) ) {
- if (argument instanceof Number) {
- return new TimeFilter(invert, ((Number)argument).intValue(), daystart);
- } else {
- return new TimeFilter(invert, argument.toString(), daystart);
- }
+ int days = toInt(argument);
+ return new AgeFileFilter((long)days * DAY, invert);
}
if( option.equals(Finder.SIZE) ) {
- return new SizeFilter(invert, argument.toString());
+ IOFileFilter filter = new SizeFilter(argument.toString());
+ return (invert ? new NotFileFilter(filter) : filter);
}
if( option.equals(Finder.NAME) ) {
- return new NameFilter(invert, argument.toString(), false);
+// IOFileFilter filter = new WildcardFileFilter(argument.toString(), false);
+ IOFileFilter filter = new NameFilter(argument.toString(), false);
+ return (invert ? new NotFileFilter(filter) : filter);
}
if( option.equals(Finder.INAME) ) {
- return new NameFilter(invert, argument.toString(), true);
+// WildcardFileFilter filter = new WildcardFileFilter(argument.toString(), true);
+ IOFileFilter filter = new NameFilter(argument.toString(), true);
+ return (invert ? new NotFileFilter(filter) : filter);
}
if( option.equals(Finder.PATH) ) {
- return new PathFilter(invert, argument.toString(), false);
+ IOFileFilter filter = new PathFilter(argument.toString(), false);
+ return (invert ? new NotFileFilter(filter) : filter);
}
if( option.equals(Finder.IPATH) ) {
- return new PathFilter(invert, argument.toString(), true);
+ IOFileFilter filter = new PathFilter(argument.toString(), true);
+ return (invert ? new NotFileFilter(filter) : filter);
}
if( option.equals(Finder.REGEX) ) {
- return new RegexFilter(invert, argument.toString(), false);
+ IOFileFilter filter = new RegexFilter(argument.toString(), false);
+ return (invert ? new NotFileFilter(filter) : filter);
}
if( option.equals(Finder.IREGEX) ) {
- return new RegexFilter(invert, argument.toString(), true);
+ IOFileFilter filter = new RegexFilter(argument.toString(), true);
+ return (invert ? new NotFileFilter(filter) : filter);
}
return null;
}
public boolean isDaystartConfigured() {
return this.daystart;
+ }
+
+ private int toInt(Object argument) {
+ if (argument instanceof Number) {
+ return((Number)argument).intValue();
+ } else {
+ try {
+ return Integer.parseInt(argument.toString());
+ } catch(NumberFormatException nfe) {
+ throw new IllegalArgumentException("Argument " + argument + " must be an integer.");
+ }
+ }
}
}
Modified: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/CanReadFilter.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/CanReadFilter.java?rev=424496&r1=424495&r2=424496&view=diff
==============================================================================
--- jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/CanReadFilter.java (original)
+++ jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/CanReadFilter.java Fri Jul 21 16:46:59 2006
@@ -16,42 +16,78 @@
package org.apache.commons.finder.filters;
import java.io.File;
+import org.apache.commons.io.filefilter.IOFileFilter;
+import org.apache.commons.io.filefilter.NotFileFilter;
+import org.apache.commons.io.filefilter.AbstractFileFilter;
+import org.apache.commons.io.filefilter.AndFileFilter;
/**
- * {@link java.io.FileFilter} that tests whether a File can be read.
- *
- * @version $Id$
- * @since 0.1
+ * This filter accepts <code>File</code>s that can be read.
+ * <p>
+ * Example, showing how to print out a list of the
+ * current directory's readable files:
+ *
+ * <pre>
+ * File dir = new File(".");
+ * String[] files = dir.list( CanReadFileFilter.CAN_READ );
+ * for ( int i = 0; i < files.length; i++ ) {
+ * System.out.println(files[i]);
+ * }
+ * </pre>
+ *
+ * <p>
+ * Example, showing how to print out a list of the
+ * current directory's un-readable files:
+ *
+ * <pre>
+ * File dir = new File(".");
+ * String[] files = dir.list( CanReadFileFilter.CANNOT_READ );
+ * for ( int i = 0; i < files.length; i++ ) {
+ * System.out.println(files[i]);
+ * }
+ * </pre>
+ *
+ * <p>
+ * Example, showing how to print out a list of the
+ * current directory's read-only files:
+ *
+ * <pre>
+ * File dir = new File(".");
+ * String[] files = dir.list( CanReadFileFilter.READ_ONLY );
+ * for ( int i = 0; i < files.length; i++ ) {
+ * System.out.println(files[i]);
+ * }
+ * </pre>
+ *
+ * @since Commons IO 1.3
+ * @version $Revision$
*/
public class CanReadFilter extends AbstractFileFilter {
+
+ /** Singleton instance of readable filter */
+ public static final IOFileFilter CAN_READ = new CanReadFilter ();
+ /** Singleton instance of not readable filter */
+ public static final IOFileFilter CANNOT_READ = new NotFileFilter(CAN_READ);
+
+ /** Singleton instance of read only filter */
+ public static final IOFileFilter READ_ONLY = new AndFileFilter(CAN_READ,
+ CanWriteFilter.CANNOT_WRITE);
+
/**
- * Construct a new {@link java.io.FileFilter} specifying whether the
- * criteria should be <i>inverted</i> or not.
- *
- * @param invert Whether the test criteria should be inverted.
+ * Restrictive consructor.
*/
- public CanReadFilter(boolean invert) {
- super(invert);
+ protected CanReadFilter() {
}
-
+
/**
- * Tests whether the {@link File} can
- * be read.
+ * Checks to see if the file can be read.
*
- * @param file The {@link File} to test.
- * @return <code>true</code> if the {@link File}
- * can be read, otherwise <code>false</code> .
+ * @param file the File to check
+ * @return true if the file is a directory
*/
- protected boolean test(File file) {
+ public boolean accept(File file) {
return file.canRead();
}
-
- /**
- * Return a String representation of this class.
- * @return a String representation of the class.
- */
- public String toString() {
- return super.toString() + "}";
- }
+
}
Modified: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/CanWriteFilter.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/CanWriteFilter.java?rev=424496&r1=424495&r2=424496&view=diff
==============================================================================
--- jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/CanWriteFilter.java (original)
+++ jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/CanWriteFilter.java Fri Jul 21 16:46:59 2006
@@ -16,43 +16,65 @@
package org.apache.commons.finder.filters;
import java.io.File;
+import org.apache.commons.io.filefilter.IOFileFilter;
+import org.apache.commons.io.filefilter.NotFileFilter;
+import org.apache.commons.io.filefilter.AbstractFileFilter;
/**
- * {@link java.io.FileFilter} that tests whether a File can be written.
- *
- * @version $Id$
- * @since 0.1
+ * This filter accepts <code>File</code>s that can be written to.
+ * <p>
+ * Example, showing how to print out a list of the
+ * current directory's writable files:
+ *
+ * <pre>
+ * File dir = new File(".");
+ * String[] files = dir.list( CanWriteFileFilter.CAN_WRITE );
+ * for ( int i = 0; i < files.length; i++ ) {
+ * System.out.println(files[i]);
+ * }
+ * </pre>
+ *
+ * <p>
+ * Example, showing how to print out a list of the
+ * current directory's un-writable files:
+ *
+ * <pre>
+ * File dir = new File(".");
+ * String[] files = dir.list( CanWriteFileFilter.CANNOT_WRITE );
+ * for ( int i = 0; i < files.length; i++ ) {
+ * System.out.println(files[i]);
+ * }
+ * </pre>
+ *
+ * <p>
+ * <b>N.B.</b> For read-only files, use <code>CanReadFileFilter.READ_ONLY</code>.
+ *
+ * @since Commons IO 1.3
+ * @version $Revision$
*/
public class CanWriteFilter extends AbstractFileFilter {
+
+ /** Singleton instance of writable filter */
+ public static final IOFileFilter CAN_WRITE = new CanWriteFilter();
+
+ /** Singleton instance of not writable filter */
+ public static final IOFileFilter CANNOT_WRITE = new NotFileFilter(CAN_WRITE);
/**
- * Construct a new {@link java.io.FileFilter} specifying whether the
- * criteria should be <i>inverted</i> or not.
- *
- * @param invert Whether the test criteria
- * should be inverted.
+ * Restrictive consructor.
*/
- public CanWriteFilter(boolean invert) {
- super(invert);
+ protected CanWriteFilter() {
}
-
+
/**
- * Tests whether the specified {@link File} can
- * be written.
+ * Checks to see if the file can be written to.
*
- * @param file The {@link File} to test.
- * @return <code>true</code> if the {@link File}
- * can be written, otherwise <code>false</code> .
+ * @param file the File to check
+ * @return true if the file is a directory
*/
- protected boolean test(File file) {
+ public boolean accept(File file) {
return file.canWrite();
}
-
- /**
- * Return a String representation of this class.
- * @return a String representation of the class.
- */
- public String toString() {
- return super.toString() + "}";
- }
+
}
+
Modified: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/EmptyFilter.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/EmptyFilter.java?rev=424496&r1=424495&r2=424496&view=diff
==============================================================================
--- jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/EmptyFilter.java (original)
+++ jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/EmptyFilter.java Fri Jul 21 16:46:59 2006
@@ -16,35 +16,63 @@
package org.apache.commons.finder.filters;
import java.io.File;
+import org.apache.commons.io.filefilter.IOFileFilter;
+import org.apache.commons.io.filefilter.NotFileFilter;
+import org.apache.commons.io.filefilter.AbstractFileFilter;
/**
- * {@link java.io.FileFilter} that tests whether a file/directory is empty or not.
- *
- * @version $Id$
- * @since 0.1
+ * This filter accepts <code>File</code>s that are empty.
+ * <p>
+ * If the <code>File</code> is a directory it checks that
+ * it contains no files.
+ * <p>
+ * Example, showing how to print out a list of the
+ * current directory's empty files:
+ *
+ * <pre>
+ * File dir = new File(".");
+ * String[] files = dir.list( EmptyFileFilter.EMPTY );
+ * for ( int i = 0; i < files.length; i++ ) {
+ * System.out.println(files[i]);
+ * }
+ * </pre>
+ *
+ * <p>
+ * Example, showing how to print out a list of the
+ * current directory's non-empty files:
+ *
+ * <pre>
+ * File dir = new File(".");
+ * String[] files = dir.list( EmptyFileFilter.NOT_EMPTY );
+ * for ( int i = 0; i < files.length; i++ ) {
+ * System.out.println(files[i]);
+ * }
+ * </pre>
+ *
+ * @since Commons IO 1.3
+ * @version $Revision$
*/
public class EmptyFilter extends AbstractFileFilter {
-
+
+ /** Singleton instance of empty filter */
+ public static final IOFileFilter EMPTY = new EmptyFilter();
+
+ /** Singleton instance of not-empty filter */
+ public static final IOFileFilter NOT_EMPTY = new NotFileFilter(EMPTY);
+
/**
- * Construct a new {@link java.io.FileFilter} specifying whether the
- * criteria should be <i>inverted</i> or not.
- *
- * @param invert Whether the test criteria
- * should be inverted.
+ * Restrictive consructor.
*/
- public EmptyFilter(boolean invert) {
- super(invert);
+ protected EmptyFilter() {
}
-
+
/**
- * Tests whether the {@link File} or directory
- * is empty.
+ * Checks to see if the file is empty.
*
- * @param file The {@link File} to test.
- * @return <code>true</code> if the {@link File}
- * is empty, otherwise <code>false</code> .
+ * @param file the File to check
+ * @return true if the file is a directory
*/
- protected boolean test(File file) {
+ public boolean accept(File file) {
if (file.isDirectory()) {
File[] files = file.listFiles();
return (files == null || files.length == 0);
@@ -52,12 +80,6 @@
return (file.length() == 0);
}
}
-
- /**
- * Return a String representation of this class.
- * @return a String representation of the class.
- */
- public String toString() {
- return super.toString() + "}";
- }
+
}
+
Modified: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/HiddenFilter.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/HiddenFilter.java?rev=424496&r1=424495&r2=424496&view=diff
==============================================================================
--- jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/HiddenFilter.java (original)
+++ jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/HiddenFilter.java Fri Jul 21 16:46:59 2006
@@ -16,43 +16,61 @@
package org.apache.commons.finder.filters;
import java.io.File;
+import org.apache.commons.io.filefilter.IOFileFilter;
+import org.apache.commons.io.filefilter.NotFileFilter;
+import org.apache.commons.io.filefilter.AbstractFileFilter;
/**
- * {@link java.io.FileFilter} that tests whether a File is <i>hidden</i>.
- *
- * @version $Id$
- * @since 0.1
+ * This filter accepts <code>File</code>s that are hidden.
+ * <p>
+ * Example, showing how to print out a list of the
+ * current directory's hidden files:
+ *
+ * <pre>
+ * File dir = new File(".");
+ * String[] files = dir.list( HiddenFilter.HIDDEN );
+ * for ( int i = 0; i < files.length; i++ ) {
+ * System.out.println(files[i]);
+ * }
+ * </pre>
+ *
+ * <p>
+ * Example, showing how to print out a list of the
+ * current directory's visible (i.e. not hidden) files:
+ *
+ * <pre>
+ * File dir = new File(".");
+ * String[] files = dir.list( HiddenFilter.VISIBLE );
+ * for ( int i = 0; i < files.length; i++ ) {
+ * System.out.println(files[i]);
+ * }
+ * </pre>
+ *
+ * @since Commons IO 1.3
+ * @version $Revision$
*/
public class HiddenFilter extends AbstractFileFilter {
-
+
+ /** Singleton instance of hidden filter */
+ public static final IOFileFilter HIDDEN = new HiddenFilter();
+
+ /** Singleton instance of visible filter */
+ public static final IOFileFilter VISIBLE = new NotFileFilter(HIDDEN);
+
/**
- * Construct a new {@link java.io.FileFilter} specifying whether the
- * criteria should be <i>inverted</i> or not.
- *
- * @param invert Whether the test criteria
- * should be inverted.
+ * Restrictive consructor.
*/
- public HiddenFilter(boolean invert) {
- super(invert);
+ protected HiddenFilter() {
}
-
+
/**
- * Tests whether the specified {@link File} is
- * hidden.
+ * Checks to see if the file is hidden.
*
- * @param file The {@link File} to test.
- * @return <code>true</code> if the {@link File}
- * is hidden, otherwise <code>false</code> .
+ * @param file the File to check
+ * @return true if the file is a directory
*/
- protected boolean test(File file) {
+ public boolean accept(File file) {
return file.isHidden();
}
-
- /**
- * Return a String representation of this class.
- * @return a String representation of the class.
- */
- public String toString() {
- return super.toString() + "}";
- }
+
}
Modified: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/NameFilter.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/NameFilter.java?rev=424496&r1=424495&r2=424496&view=diff
==============================================================================
--- jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/NameFilter.java (original)
+++ jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/NameFilter.java Fri Jul 21 16:46:59 2006
@@ -16,13 +16,12 @@
package org.apache.commons.finder.filters;
import java.io.File;
-import java.util.Stack;
-import java.util.ArrayList;
import org.apache.commons.io.FilenameUtils;
+import org.apache.commons.io.filefilter.AbstractFileFilter;
/**
- * {@link java.io.FileFilter} implementation that uses wildcard matching on the file name.
+ * <code>IOFileFilter</code> implementation that uses wildcard matching on the file name.
*
* @version $Id$
* @since 0.1
@@ -34,15 +33,14 @@
private String wildcardmatcher;
/**
- * Construct a new {@link java.io.FileFilter} specifying whether the
+ * Construct a new <code>IOFileFilter</code> specifying whether the
* wildcard criteria.
*
- * @param invert Whether the test criteria should be inverted.
* @param wildcardmatcher the wildcard string to match against
* @param ignoreCase whether to ignore the case
*/
- public NameFilter(boolean invert, String wildcardmatcher, boolean ignoreCase) {
- super(invert);
+ public NameFilter(String wildcardmatcher, boolean ignoreCase) {
+ super();
this.wildcardmatcher = wildcardmatcher;
this.ignoreCase = ignoreCase;
}
@@ -71,7 +69,7 @@
* @return a String representation of the class.
*/
public String toString() {
- return super.toString() + ", wildcard=[" + getWildcardmatcher() + "]" +
+ return "NameFilter{wildcard=[" + getWildcardmatcher() + "]" +
", ignoreCase=" + isIgnoreCase() + "}";
}
@@ -84,7 +82,7 @@
* matches the specified Wildcard criteria, otherwise
* <code>false</code> .
*/
- protected boolean test(File file) {
+ public boolean accept(File file) {
if( isIgnoreCase() ) {
// TODO: Switch to using the IOCase API when IO 1.3 comes out
return FilenameUtils.wildcardMatch(getName(file).toLowerCase(), getWildcardmatcher().toLowerCase());
Modified: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/PathFilter.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/PathFilter.java?rev=424496&r1=424495&r2=424496&view=diff
==============================================================================
--- jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/PathFilter.java (original)
+++ jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/PathFilter.java Fri Jul 21 16:46:59 2006
@@ -18,7 +18,7 @@
import java.io.File;
/**
- * {@link java.io.FileFilter} implementation that uses wildcard matching on the file's path.
+ * <code>IOFileFilter</code> implementation that uses wildcard matching on the file's path.
*
* @version $Id$
* @since 0.1
@@ -26,15 +26,14 @@
public class PathFilter extends NameFilter {
/**
- * Construct a new {@link java.io.FileFilter} specifying whether the
+ * Construct a new <code>IOFileFilter</code> specifying whether the
* wildcard criteria.
*
- * @param invert Whether the test criteria should be inverted.
* @param wildcardmatcher the wildcard string to match against
* @param matchOnSystem whether to use the system (windows or unix)
*/
- public PathFilter(boolean invert, String wildcardmatcher, boolean matchOnSystem) {
- super(invert, wildcardmatcher, matchOnSystem);
+ public PathFilter(String wildcardmatcher, boolean matchOnSystem) {
+ super(wildcardmatcher, matchOnSystem);
}
/**
Modified: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/RegexFilter.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/RegexFilter.java?rev=424496&r1=424495&r2=424496&view=diff
==============================================================================
--- jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/RegexFilter.java (original)
+++ jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/RegexFilter.java Fri Jul 21 16:46:59 2006
@@ -17,9 +17,10 @@
import java.io.File;
import java.util.regex.Pattern;
+import org.apache.commons.io.filefilter.AbstractFileFilter;
/**
- * {@link java.io.FileFilter} implementation that uses regular
+ * <code>IOFileFilter</code> implementation that uses regular
* expression matching on the file path.
*
* @version $Id$
@@ -32,15 +33,14 @@
private Pattern pattern;
/**
- * Construct a new {@link java.io.FileFilter} specifying the
+ * Construct a new <code>IOFileFilter</code> specifying the
* regular expresion criteria.
*
- * @param invert Whether the test criteria should be inverted.
* @param regex The regular expression.
* @param ignoreCase Whether the case should be ignored.
*/
- public RegexFilter(boolean invert, String regex, boolean ignoreCase) {
- super(invert);
+ public RegexFilter(String regex, boolean ignoreCase) {
+ super();
this.regex = regex;
this.ignoreCase = ignoreCase;
if (ignoreCase) {
@@ -78,7 +78,7 @@
* matches the regular expression, otherwise
* <code>false</code>.
*/
- protected boolean test(File file) {
+ public boolean accept(File file) {
return pattern.matcher(file.getPath()).matches();
}
@@ -87,7 +87,7 @@
* @return a String representation of the class.
*/
public String toString() {
- return super.toString() + ", regex=[" + regex + "]" +
+ return "RefexFilter{regex=[" + regex + "]" +
", ignoreCase=" + ignoreCase + "}";
}
}
Modified: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/SizeFilter.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/SizeFilter.java?rev=424496&r1=424495&r2=424496&view=diff
==============================================================================
--- jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/SizeFilter.java (original)
+++ jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/SizeFilter.java Fri Jul 21 16:46:59 2006
@@ -16,9 +16,10 @@
package org.apache.commons.finder.filters;
import java.io.File;
+import org.apache.commons.io.filefilter.AbstractFileFilter;
/**
- * {@link java.io.FileFilter} implementation that matches on the file size.
+ * <code>IOFileFilter</code> implementation that matches on the file size.
*
* @version $Id$
* @since 0.1
@@ -32,26 +33,24 @@
private String origSize;
/**
- * Construct a new {@link java.io.FileFilter} specifying the
+ * Construct a new <code>IOFileFilter</code> specifying the
* file size.
*
- * @param invert Whether the test criteria should be inverted.
* @param size The minimum file size.
*/
- public SizeFilter(boolean invert, String size) {
- this(invert, size, true);
+ public SizeFilter(String size) {
+ this(size, true);
}
/**
- * Construct a new {@link java.io.FileFilter} specifying the
+ * Construct a new <code>IOFileFilter</code> specifying the
* file size.
*
- * @param invert Whether the test criteria should be inverted.
* @param size The minimum file size.
* @param roundUp Whether equals compares should round up or down.
*/
- public SizeFilter(boolean invert, String size, boolean roundUp) {
- super(invert);
+ public SizeFilter(String size, boolean roundUp) {
+ super();
this.roundUp = roundUp;
this.origSize = origSize;
String parseSize = (size == null ? "" : size.trim());
@@ -114,7 +113,7 @@
* is a specified size, otherwise
* <code>false</code>.
*/
- protected boolean test(File file) {
+ public boolean accept(File file) {
long fileSize = file.length();
switch (comparator) {
case '>':
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org