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/21 07:04:59 UTC
svn commit: r424180 - in /jakarta/commons/sandbox/finder/trunk: ./
src/java/org/apache/commons/finder/
src/java/org/apache/commons/finder/filters/
src/test/org/apache/commons/finder/
Author: niallp
Date: Thu Jul 20 22:04:57 2006
New Revision: 424180
URL: http://svn.apache.org/viewvc?rev=424180&view=rev
Log:
SANDBOX-159 - Extract FileFilter implementationsinto separate package and add new CompositeFilter implementation.
Added:
jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/
jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/AbstractFileFilter.java (with props)
jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/CanReadFilter.java (with props)
jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/CanWriteFilter.java (with props)
jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/CompositeFilter.java (with props)
jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/EmptyFilter.java (with props)
jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/HiddenFilter.java (with props)
jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/MinFilter.java (with props)
jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/NameFilter.java (with props)
jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/NewerFilter.java (with props)
jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/PathFilter.java (with props)
jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/RegexFilter.java (with props)
jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/SizeFilter.java (with props)
jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/TimeFilter.java (with props)
jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/TypeFilter.java (with props)
jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/package.html
jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/package.html
Modified:
jakarta/commons/sandbox/finder/trunk/project.xml
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/test/org/apache/commons/finder/FileFinderTest.java
Modified: jakarta/commons/sandbox/finder/trunk/project.xml
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/finder/trunk/project.xml?rev=424180&r1=424179&r2=424180&view=diff
==============================================================================
--- jakarta/commons/sandbox/finder/trunk/project.xml (original)
+++ jakarta/commons/sandbox/finder/trunk/project.xml Thu Jul 20 22:04:57 2006
@@ -65,12 +65,6 @@
<dependencies>
<dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- <version>1.2</version>
- <url>http://jakarta.apache.org/commons/io/</url>
- </dependency>
- <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
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=424180&r1=424179&r2=424180&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 Thu Jul 20 22:04:57 2006
@@ -16,7 +16,13 @@
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;
/**
* A Finder of Files. Though the structure the files are in is
@@ -40,7 +46,8 @@
public static final String TIME = "TIME";
// size based tests
- public static final String EMPTY = "EMPTY";
+ public static final FileFilter EMPTY = new EmptyFilter(false);
+ public static final FileFilter NOT_EMPTY = new EmptyFilter(true);
public static final String SIZE = "SIZE";
// name based tests
@@ -52,12 +59,16 @@
public static final String IREGEX = "IREGEX";
// type of file
- public static final String TYPE = "TYPE"; // supports 'd' and 'f'
- public static final String HIDDEN = "HIDDEN";
+ 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);
// permission replacements
- public static final String CAN_READ = "CAN_READ";
- public static final String CAN_WRITE = "CAN_WRITE";
+ 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 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=424180&r1=424179&r2=424180&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 Thu Jul 20 22:04:57 2006
@@ -19,13 +19,15 @@
import java.io.File;
import java.io.FileFilter;
import java.util.Map;
-import java.util.List;
-import java.util.LinkedList;
import java.util.Iterator;
-import java.util.regex.Pattern;
-import java.util.regex.Matcher;
-
-import org.apache.commons.io.FilenameUtils;
+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;
/**
* Filters that can check whether to include a file in the response or not.
@@ -39,12 +41,8 @@
* @version $Id$
* @since 1.1
*/
-public class FindingFilter implements FileFilter {
+public class FindingFilter extends CompositeFilter {
- /** The options to use. */
- private Map options;
- /** The filters to use. */
- private List filters = new LinkedList();
/** The daystart flag. */
private boolean daystart;
@@ -54,22 +52,30 @@
* @param options the options to use
*/
public FindingFilter(Map options) {
- this.options = options;
+ super(false, true);
+ this.daystart = options.containsKey(Finder.DAYSTART);
Collection entries = options.entrySet();
Iterator itr = entries.iterator();
while(itr.hasNext()) {
Map.Entry entry = (Map.Entry)itr.next();
if( entry.getKey().equals(Finder.DAYSTART) ) {
- this.daystart = true;
continue;
}
- // knows that the key is a String
- filters.add( createFilter(entry.getKey().toString(), entry.getValue()) );
+ Object key = entry.getKey();
+ if (key instanceof FileFilter) {
+ addFilter((FileFilter)key);
+ } else {
+ addFilter(createFilter(key.toString(), entry.getValue()));
+ }
}
}
private FileFilter createFilter(String option, Object argument) {
+ if (argument instanceof FileFilter) {
+ return (FileFilter)argument;
+ }
+
boolean invert = false;
if( option.startsWith(Finder.NOT) ) {
invert = true;
@@ -77,310 +83,52 @@
option = option.substring(Finder.NOT.length());
}
if( option.equals(Finder.MIN) ) {
- return new MinFilter(option, argument, invert, this);
+ if (argument instanceof Number) {
+ return new MinFilter(invert, ((Number)argument).intValue(), daystart);
+ } else {
+ return new MinFilter(invert, argument.toString(), daystart);
+ }
}
if( option.equals(Finder.NEWER) ) {
- return new NewerFilter(option, argument, invert);
+ if (argument instanceof File) {
+ return new NewerFilter(invert, (File)argument);
+ } else {
+ return new NewerFilter(invert, argument.toString());
+ }
}
if( option.equals(Finder.TIME) ) {
- return new TimeFilter(option, argument, invert, this);
- }
- if( option.equals(Finder.EMPTY) ) {
- return new EmptyFilter(option, argument, invert);
+ if (argument instanceof Number) {
+ return new TimeFilter(invert, ((Number)argument).intValue(), daystart);
+ } else {
+ return new TimeFilter(invert, argument.toString(), daystart);
+ }
}
if( option.equals(Finder.SIZE) ) {
- return new SizeFilter(option, argument, invert);
+ return new SizeFilter(invert, argument.toString());
}
if( option.equals(Finder.NAME) ) {
- return new NameFilter(option, argument, invert, false);
+ return new NameFilter(invert, argument.toString(), false);
}
if( option.equals(Finder.INAME) ) {
- return new NameFilter(option, argument, invert, true);
+ return new NameFilter(invert, argument.toString(), true);
}
if( option.equals(Finder.PATH) ) {
- return new PathFilter(option, argument, invert, false);
+ return new PathFilter(invert, argument.toString(), false);
}
if( option.equals(Finder.IPATH) ) {
- return new PathFilter(option, argument, invert, true);
+ return new PathFilter(invert, argument.toString(), true);
}
if( option.equals(Finder.REGEX) ) {
- return new RegexFilter(option, argument, invert, false);
+ return new RegexFilter(invert, argument.toString(), false);
}
if( option.equals(Finder.IREGEX) ) {
- return new RegexFilter(option, argument, invert, true);
- }
- if( option.equals(Finder.TYPE) ) {
- return new TypeFilter(option, argument, invert);
- }
- if( option.equals(Finder.HIDDEN) ) {
- return new HiddenFilter(option, argument, invert);
- }
- if( option.equals(Finder.CAN_READ) ) {
- return new CanReadFilter(option, argument, invert);
- }
- if( option.equals(Finder.CAN_WRITE) ) {
- return new CanWriteFilter(option, argument, invert);
+ return new RegexFilter(invert, argument.toString(), true);
}
return null;
}
- public boolean accept(File file) {
- Iterator itr = filters.iterator();
- while(itr.hasNext()) {
- FileFilter filter = (FileFilter) itr.next();
- if(filter == null) {
- continue;
- }
- boolean result = filter.accept(file);
- if(result == false) {
- return false;
- }
- }
- return true;
- }
-
public boolean isDaystartConfigured() {
return this.daystart;
}
- // helper method to make the inverting easier.
- // possibly the Filters should be inner classes.
- // possibly there should be an abstract FindFilter class.
- static boolean invert(boolean invert, boolean answer) {
- if(invert) {
- answer = !answer;
- }
- return answer;
- }
-
-}
-
- /**
- * @todo need to implement the daystart bits
- */
- class MinFilter implements FileFilter {
- private Object option;
- private boolean invert;
- private int argument;
- private FindingFilter parent;
- public MinFilter(Object option, Object argument, boolean invert, FindingFilter parent) {
- this.option = option;
- this.invert = invert;
- try {
- this.argument = Integer.parseInt(argument.toString());
- } catch(NumberFormatException nfe) {
- throw new IllegalArgumentException("Argument "+argument+" must be an integer. ");
- }
- this.parent = parent;
- }
- public boolean accept(File file) {
- boolean daystart = this.parent.isDaystartConfigured();
- return FindingFilter.invert( this.invert,
- file.lastModified() > System.currentTimeMillis() - this.argument * 60000L );
- }
- }
-
- class NewerFilter implements FileFilter {
- private Object option;
- private boolean invert;
- private File argument;
- public NewerFilter(Object option, Object argument, boolean invert) {
- this.option = option;
- this.invert = invert;
- this.argument = new File(argument.toString());
- }
- public boolean accept(File file) {
- return FindingFilter.invert( this.invert, file.lastModified() > this.argument.lastModified() );
- }
- }
-
- /**
- * @todo need to implement the daystart bits
- */
- class TimeFilter implements FileFilter {
- private Object option;
- private boolean invert;
- private int argument;
- private FindingFilter parent;
- public TimeFilter(Object option, Object argument, boolean invert, FindingFilter parent) {
- this.option = option;
- this.invert = invert;
- try {
- this.argument = Integer.parseInt(argument.toString());
- } catch(NumberFormatException nfe) {
- throw new IllegalArgumentException("Argument "+argument+" must be an integer. ");
- }
- this.parent = parent;
- }
- public boolean accept(File file) {
- boolean daystart = this.parent.isDaystartConfigured();
- return FindingFilter.invert( this.invert,
- file.lastModified() > System.currentTimeMillis() - this.argument * 60000L * 60L * 24L );
- }
- }
-
- class EmptyFilter implements FileFilter {
- private Object option;
- private boolean invert;
- private boolean argument;
- public EmptyFilter(Object option, Object argument, boolean invert) {
- this.option = option;
- this.invert = invert;
- this.argument = new Boolean(argument.toString()).booleanValue();
- }
- public boolean accept(File file) {
- return FindingFilter.invert( this.invert, (!file.isDirectory() && file.length() == 0) == this.argument );
- }
- }
-
- /**
- * @todo needs to handle +5 for > 5 and -5 for < 5.
- * @todo Also needs to handle k, m, g, as suffixes.
- * @todo Switch from 512 byte block size to bytes
- */
- class SizeFilter implements FileFilter {
- private Object option;
- private boolean invert;
- private int argument;
- public SizeFilter(Object option, Object argument, boolean invert) {
- this.option = option;
- this.invert = invert;
- try {
- this.argument = Integer.parseInt(argument.toString());
- } catch(NumberFormatException nfe) {
- throw new IllegalArgumentException("Argument "+argument+" must be an integer. ");
- }
- }
- public boolean accept(File file) {
- return FindingFilter.invert( this.invert, (int)(file.length()/512) == this.argument );
- }
- }
-
- class NameFilter implements FileFilter {
- private Object option;
- private boolean invert;
- private Object argument;
- private boolean ignoreCase;
- public NameFilter(Object option, Object argument, boolean invert, boolean ignoreCase) {
- this.option = option;
- this.invert = invert;
- this.argument = argument;
- this.ignoreCase = ignoreCase;
- }
- public boolean accept(File file) {
- if(this.ignoreCase) {
- return FindingFilter.invert( this.invert, FilenameUtils.wildcardMatch(file.getName().toLowerCase(), this.argument.toString().toLowerCase()) );
- } else {
- return FindingFilter.invert( this.invert, FilenameUtils.wildcardMatch(file.getName(), this.argument.toString()) );
- }
- }
- }
-
- class PathFilter implements FileFilter {
- private Object option;
- private boolean invert;
- private Object argument;
- private boolean ignoreCase;
- public PathFilter(Object option, Object argument, boolean invert, boolean ignoreCase) {
- this.option = option;
- this.invert = invert;
- this.argument = argument;
- this.ignoreCase = ignoreCase;
- }
- public boolean accept(File file) {
- if(this.ignoreCase) {
- return FindingFilter.invert( this.invert, FilenameUtils.wildcardMatch(file.getPath().toLowerCase(), this.argument.toString().toLowerCase()) );
- } else {
- return FindingFilter.invert( this.invert, FilenameUtils.wildcardMatch(file.getPath(), this.argument.toString()) );
- }
- }
- }
-
- class RegexFilter implements FileFilter {
- private Object option;
- private boolean invert;
- private Object argument;
- private boolean ignoreCase;
- public RegexFilter(Object option, Object argument, boolean invert, boolean ignoreCase) {
- this.option = option;
- this.invert = invert;
- this.argument = argument;
- this.ignoreCase = ignoreCase;
- }
- public boolean accept(File file) {
- if(this.ignoreCase) {
- Pattern pattern = Pattern.compile(this.argument.toString(), Pattern.CASE_INSENSITIVE);
- Matcher matcher = pattern.matcher(file.getPath());
- return FindingFilter.invert( this.invert, matcher.matches() );
- } else {
- return FindingFilter.invert( this.invert, file.getPath().matches(this.argument.toString()) );
- }
- }
- }
-
- class TypeFilter implements FileFilter {
- private Object option;
- private boolean invert;
- private Object argument;
- public TypeFilter(Object option, Object argument, boolean invert) {
- this.option = option;
- this.invert = invert;
- if(!"d".equals(argument) && !"f".equals(argument)) {
- throw new IllegalArgumentException("Type option must be 'f' or 'd'. ");
- }
- this.argument = argument;
- }
- public boolean accept(File file) {
- if("d".equals(argument)) {
- return FindingFilter.invert( this.invert, file.isDirectory() );
- } else
- if("f".equals(argument)) {
- return FindingFilter.invert( this.invert, !file.isDirectory() );
- } else {
- throw new IllegalArgumentException("Type option must be 'f' or 'd'. ");
- }
- }
- }
-
- class HiddenFilter implements FileFilter {
- private Object option;
- private boolean invert;
- private boolean argument;
- public HiddenFilter(Object option, Object argument, boolean invert) {
- this.option = option;
- this.invert = invert;
- this.argument = new Boolean(argument.toString()).booleanValue();
- }
- public boolean accept(File file) {
- return FindingFilter.invert( this.invert, file.isHidden() == this.argument );
- }
- }
-
- class CanReadFilter implements FileFilter {
- private Object option;
- private boolean invert;
- private boolean argument;
- public CanReadFilter(Object option, Object argument, boolean invert) {
- this.option = option;
- this.invert = invert;
- this.argument = new Boolean(argument.toString()).booleanValue();
- }
- public boolean accept(File file) {
- return FindingFilter.invert( this.invert, file.canRead() == this.argument );
- }
- }
-
- class CanWriteFilter implements FileFilter {
- private Object option;
- private boolean invert;
- private boolean argument;
- public CanWriteFilter(Object option, Object argument, boolean invert) {
- this.option = option;
- this.invert = invert;
- this.argument = new Boolean(argument.toString()).booleanValue();
- }
- public boolean accept(File file) {
- return FindingFilter.invert( this.invert, file.canWrite() == this.argument );
- }
}
-
Added: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/AbstractFileFilter.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/AbstractFileFilter.java?rev=424180&view=auto
==============================================================================
--- jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/AbstractFileFilter.java (added)
+++ jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/AbstractFileFilter.java Thu Jul 20 22:04:57 2006
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2005-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.finder.filters;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.Serializable;
+
+/**
+ * Abstract {@link FileFilter} implementation.
+ *
+ * @version $Id$
+ * @since 0.1
+ */
+public abstract class AbstractFileFilter implements FileFilter, Serializable {
+
+ private boolean invert;
+
+ /**
+ * Construct a new {@link FileFilter} specifying whether the
+ * criteria should be <i>inverted</i> or not.
+ *
+ * @param invert Whether the test criteria
+ * should be inverted.
+ */
+ public AbstractFileFilter(boolean invert) {
+ this.invert = invert;
+ }
+
+ /**
+ * Are the {@link FileFilter} criteria be inverted.
+ *
+ * @return <code>true</code> if the filter criteria
+ * should be inverted.
+ */
+ public boolean isInvert() {
+ return invert;
+ }
+
+ /**
+ * Tests whether the specified {@link File} meets
+ * the find criteria (<i>inverted</i> if required).
+ *
+ * @param file The {@link File} to test.
+ * @return <code>true</code> if the {@link File}
+ * meets the criteria.
+ */
+ public boolean accept(File file) {
+ boolean result = test(file);
+ if (isInvert()) {
+ return (result ? false : true);
+ } else {
+ return result;
+ }
+ }
+
+ /**
+ * Tests whether the specified {@link File} meets
+ * the find criteria (ignorning <code>invert</code>).
+ *
+ * @param file The {@link File} to test.
+ * @return <code>true</code> if the {@link File}
+ * meets the criteria.
+ */
+ protected abstract boolean test(File file);
+
+ /**
+ * Return a String representation of this class.
+ * @return a String representation of the class.
+ */
+ public String toString() {
+ String className = getClass().getName();
+ int idx = className.lastIndexOf('.');
+ if (idx > 0) {
+ className = className.substring(idx + 1);
+ }
+ return className + "{invert=" + isInvert();
+ }
+
+}
+
Propchange: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/AbstractFileFilter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/AbstractFileFilter.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: 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=424180&view=auto
==============================================================================
--- jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/CanReadFilter.java (added)
+++ jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/CanReadFilter.java Thu Jul 20 22:04:57 2006
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2005-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.finder.filters;
+
+import java.io.File;
+
+/**
+ * {@link java.io.FileFilter} that tests whether a File can be read.
+ *
+ * @version $Id$
+ * @since 0.1
+ */
+public class CanReadFilter extends AbstractFileFilter {
+
+ /**
+ * 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.
+ */
+ public CanReadFilter(boolean invert) {
+ super(invert);
+ }
+
+ /**
+ * Tests whether the {@link 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> .
+ */
+ protected boolean test(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() + "}";
+ }
+}
Propchange: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/CanReadFilter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/CanReadFilter.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: 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=424180&view=auto
==============================================================================
--- jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/CanWriteFilter.java (added)
+++ jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/CanWriteFilter.java Thu Jul 20 22:04:57 2006
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2005-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.finder.filters;
+
+import java.io.File;
+
+/**
+ * {@link java.io.FileFilter} that tests whether a File can be written.
+ *
+ * @version $Id$
+ * @since 0.1
+ */
+public class CanWriteFilter extends AbstractFileFilter {
+
+ /**
+ * 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.
+ */
+ public CanWriteFilter(boolean invert) {
+ super(invert);
+ }
+
+ /**
+ * Tests whether the specified {@link File} can
+ * be written.
+ *
+ * @param file The {@link File} to test.
+ * @return <code>true</code> if the {@link File}
+ * can be written, otherwise <code>false</code> .
+ */
+ protected boolean test(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() + "}";
+ }
+}
Propchange: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/CanWriteFilter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/CanWriteFilter.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/CompositeFilter.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/CompositeFilter.java?rev=424180&view=auto
==============================================================================
--- jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/CompositeFilter.java (added)
+++ jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/CompositeFilter.java Thu Jul 20 22:04:57 2006
@@ -0,0 +1,182 @@
+/*
+ * 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.finder.filters;
+
+import java.util.Collection;
+import java.io.File;
+import java.io.FileFilter;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+/**
+ * <p>{@link FileFilter} thats composed of other {@link FileFilter}s.</p>
+ *
+ * <p>This provides a way of combining filters to produce more complex
+ * criteria.</p>
+ *
+ * @version $Id$
+ * @since 0.1
+ */
+public class CompositeFilter extends AbstractFileFilter {
+
+ /** The filters to use. */
+ private List filters = new ArrayList();
+
+ /** Whether any or all of the {@link FileFilter}s must be satisfied. */
+ private boolean satisfyAll;
+
+ /**
+ * Constructs a new composite {@link FileFilter}.
+ *
+ * @param invert Whether the test criteria should be inverted.
+ * @param satisfyAll <code>true</code> if all of the component
+ * {@link FileFilter}s must be satisfied or <code>true</code>
+ * if just one needs to be satisfied.
+ */
+ public CompositeFilter(boolean invert, boolean satisfyAll) {
+ super(invert);
+ this.satisfyAll = satisfyAll;
+ }
+
+ /**
+ * Constructs a new composite {@link FileFilter} with an array
+ * of {@link FileFilter}s.
+ *
+ * @param invert Whether the test criteria should be inverted.
+ * @param satisfyAll <code>true</code> if all of the component
+ * {@link FileFilter}s must be satisfied or <code>true</code>
+ * if just one needs to be satisfied.
+ * @param filters Collection of component {@link FileFilter}s.
+ */
+ public CompositeFilter(boolean invert, boolean satisfyAll, FileFilter[] filters) {
+ this(invert, satisfyAll);
+ addFilters(filters);
+ }
+
+ /**
+ * Constructs a new composite {@link FileFilter} with an array
+ * of {@link FileFilter}s.
+ *
+ * @param invert Whether the test criteria should be inverted.
+ * @param satisfyAll <code>true</code> if all of the component
+ * {@link FileFilter}s must be satisfied or <code>true</code>
+ * if just one needs to be satisfied.
+ * @param filters Collection of component {@link FileFilter}s.
+ */
+ public CompositeFilter(boolean invert, boolean satisfyAll, Collection filters) {
+ this(invert, satisfyAll);
+ addFilters(filters);
+ }
+
+ /**
+ * Indicate whether all component {@link FileFilter}s must be satisfied
+ * or just one.
+ *
+ * @return <code>true</code> if all of the component
+ * {@link FileFilter}s must be satisfied or <code>true</code>
+ * if just one needs to be satisfied.
+ */
+ public boolean isSatisfyAll() {
+ return satisfyAll;
+ }
+
+ /**
+ * Add a component {@link FileFilter} to this composite {@link FileFilter}.
+ *
+ * @param filter The component {@link FileFilter}.
+ */
+ public void addFilter(FileFilter filter) {
+ if (filter != null) {
+ filters.add(filter);
+ }
+ }
+
+ /**
+ * Add a collection of component {@link FileFilter}s to this
+ * composite {@link FileFilter}.
+ *
+ * @param filters The collection of component {@link FileFilter}s.
+ */
+ public void addFilters(Collection filters) {
+ filters.add(filters);
+ }
+
+ /**
+ * Add an array of component {@link FileFilter}s to this
+ * composite {@link FileFilter}.
+ *
+ * @param filters The collection of component {@link FileFilter}s.
+ */
+ public void addFilters(FileFilter[] filters) {
+ if (filters != null) {
+ for (int i = 0; i < filters.length; i++) {
+ addFilter(filters[i]);
+ }
+ }
+ }
+
+ /**
+ * Return the collection of component {@link FileFilter}s that
+ * make up this composite {@link FileFilter}.
+ *
+ * @return The collection of component {@link FileFilter}s.
+ */
+ public Iterator getFilters() {
+ return filters.iterator();
+ }
+
+ /**
+ * Determine if the {@link File} meets the criteria
+ *
+ * @param file The file to test.
+ * @return <code>true</code> if the {@link File} meets
+ * the criteria, otherwise <code>false</code>.
+ */
+ protected boolean test(File file) {
+ Iterator iterator = getFilters();
+ while(iterator.hasNext()) {
+ FileFilter filter = (FileFilter)iterator.next();
+ if (filter != null) {
+ boolean result = filter.accept(file);
+ if ((!isSatisfyAll() && result) ||
+ (isSatisfyAll() && !result)) {
+ return result;
+ }
+ }
+ }
+ return (isSatisfyAll() ? true : false);
+ }
+
+ /**
+ * Return a String representation of this class.
+ * @return a String representation of the class.
+ */
+ public String toString() {
+ StringBuffer buffer = new StringBuffer(super.toString());
+ Iterator iterator = getFilters();
+ boolean first = true;
+ buffer.append(", satisfyAll=");
+ buffer.append(isSatisfyAll());
+ while (iterator.hasNext()) {
+ buffer.append("\n ");
+ buffer.append(iterator.next());
+ }
+ buffer.append("\n}");
+ return buffer.toString();
+ }
+
+}
Propchange: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/CompositeFilter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/CompositeFilter.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: 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=424180&view=auto
==============================================================================
--- jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/EmptyFilter.java (added)
+++ jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/EmptyFilter.java Thu Jul 20 22:04:57 2006
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2005-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.finder.filters;
+
+import java.io.File;
+
+/**
+ * {@link java.io.FileFilter} that tests whether a file/directory is empty or not.
+ *
+ * @version $Id$
+ * @since 0.1
+ */
+public class EmptyFilter extends AbstractFileFilter {
+
+ /**
+ * 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.
+ */
+ public EmptyFilter(boolean invert) {
+ super(invert);
+ }
+
+ /**
+ * Tests whether the {@link File} or directory
+ * is empty.
+ *
+ * @param file The {@link File} to test.
+ * @return <code>true</code> if the {@link File}
+ * is empty, otherwise <code>false</code> .
+ */
+ protected boolean test(File file) {
+ if (file.isDirectory()) {
+ File[] files = file.listFiles();
+ return (files == null || files.length == 0);
+ } else {
+ return (file.length() == 0);
+ }
+ }
+
+ /**
+ * Return a String representation of this class.
+ * @return a String representation of the class.
+ */
+ public String toString() {
+ return super.toString() + "}";
+ }
+}
Propchange: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/EmptyFilter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/EmptyFilter.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: 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=424180&view=auto
==============================================================================
--- jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/HiddenFilter.java (added)
+++ jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/HiddenFilter.java Thu Jul 20 22:04:57 2006
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2005-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.finder.filters;
+
+import java.io.File;
+
+/**
+ * {@link java.io.FileFilter} that tests whether a File is <i>hidden</i>.
+ *
+ * @version $Id$
+ * @since 0.1
+ */
+public class HiddenFilter extends AbstractFileFilter {
+
+ /**
+ * 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.
+ */
+ public HiddenFilter(boolean invert) {
+ super(invert);
+ }
+
+ /**
+ * Tests whether the specified {@link File} is
+ * hidden.
+ *
+ * @param file The {@link File} to test.
+ * @return <code>true</code> if the {@link File}
+ * is hidden, otherwise <code>false</code> .
+ */
+ protected boolean test(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() + "}";
+ }
+}
Propchange: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/HiddenFilter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/HiddenFilter.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/MinFilter.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/MinFilter.java?rev=424180&view=auto
==============================================================================
--- jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/MinFilter.java (added)
+++ jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/MinFilter.java Thu Jul 20 22:04:57 2006
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2005-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.finder.filters;
+
+import java.io.File;
+
+/**
+ * {@link java.io.FileFilter} that tests whether a File has been modified within a specified
+ * number of minutes.
+ *
+ * @version $Id$
+ * @since 0.1
+ */
+public class MinFilter extends AbstractFileFilter {
+
+ private int minutes;
+ private boolean daystart;
+
+ /**
+ * 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.
+ * @param minutes The number of minutes
+ * @param daystart Day Start
+ */
+ public MinFilter(boolean invert, int minutes, boolean daystart) {
+ super(invert);
+ this.minutes = minutes;
+ this.daystart = daystart;
+ }
+
+ /**
+ * 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.
+ * @param minutes The number of minutes
+ * @param daystart Day Start
+ */
+ public MinFilter(boolean invert, String minutes, boolean daystart) {
+ super(invert);
+ try {
+ this.minutes = Integer.parseInt(minutes);
+ } catch(NumberFormatException nfe) {
+ throw new IllegalArgumentException("Minutes " + minutes + " must be an integer.");
+ }
+ this.daystart = daystart;
+ }
+
+ /**
+ * Return the number of minutes.
+ *
+ * @return The number of minutes
+ */
+ public int getMinutes() {
+ return minutes;
+ }
+
+ /**
+ * Return the amount of time in milliseconds.
+ *
+ * @return The time in milliseconds
+ */
+ public long getTimeInMillis() {
+ return ((long)getMinutes()* 60000L);
+ }
+
+ /**
+ * Return a String representation of this class.
+ * @return a String representation of the class.
+ */
+ public String toString() {
+ return super.toString() + ", minutes=" + getMinutes() +
+ ", daystart=" + daystart+ "}";
+ }
+
+ /**
+ * Tests whether the {@link File} has been
+ * modified with the specified number of minutes.
+ *
+ * @todo need to implement the daystart bits
+ *
+ * @param file The {@link File} to test.
+ * @return <code>true</code> if the {@link File}
+ * has been modified within the period, otherwise
+ * <code>false</code>.
+ */
+ protected boolean test(File file) {
+ return (file.lastModified() > System.currentTimeMillis() - getTimeInMillis());
+ }
+}
Propchange: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/MinFilter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/MinFilter.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: 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=424180&view=auto
==============================================================================
--- jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/NameFilter.java (added)
+++ jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/NameFilter.java Thu Jul 20 22:04:57 2006
@@ -0,0 +1,245 @@
+/*
+ * Copyright 2005-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.finder.filters;
+
+import java.io.File;
+import java.util.Stack;
+import java.util.ArrayList;
+
+/**
+ * {@link java.io.FileFilter} implementation that uses wildcard matching on the file name.
+ *
+ * @version $Id$
+ * @since 0.1
+ */
+public class NameFilter extends AbstractFileFilter {
+
+ /**
+ * The Windows separator character.
+ */
+ private static final char WINDOWS_SEPARATOR = '\\';
+
+ /**
+ * The system separator character.
+ */
+ private static final char SYSTEM_SEPARATOR = File.separatorChar;
+
+ private boolean matchOnSystem;
+ private String wildcardmatcher;
+
+ /**
+ * Construct a new {@link java.io.FileFilter} 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 NameFilter(boolean invert, String wildcardmatcher, boolean matchOnSystem) {
+ super(invert);
+ this.wildcardmatcher = wildcardmatcher;
+ this.matchOnSystem = matchOnSystem;
+ }
+
+ /**
+ * Indicates whether the system case sensitivity/insensitivity
+ * should be taken into account.
+ *
+ * @return <code>true</code> if the system case sensitivity/insensitivity
+ * is taken into account, otherwise <code>false</code> .
+ */
+ public boolean isMatchOnSystem() {
+ return matchOnSystem;
+ }
+
+ /**
+ * Return the wildcard criteria.
+ *
+ * @return the wildcard criteria
+ */
+ public String getWildcardmatcher() {
+ return wildcardmatcher;
+ }
+
+ /**
+ * Return a String representation of this class.
+ * @return a String representation of the class.
+ */
+ public String toString() {
+ return super.toString() + ", wildcard=[" + getWildcardmatcher() + "]" +
+ ", matchOnSystem=" + isMatchOnSystem() + "}";
+ }
+
+ /**
+ * Tests whether the {@link File} name
+ * matches the specified Wildcard criteria.
+ *
+ * @param file The {@link File} to test.
+ * @return <code>true</code> if the {@link File}
+ * matches the specified Wildcard criteria, otherwise
+ * <code>false</code> .
+ */
+ protected boolean test(File file) {
+ return wildcardMatch(getName(file), getWildcardmatcher(), isMatchOnSystem());
+ }
+
+ /**
+ * Return the name of the file.
+ *
+ * @param file The {@link File} to test.
+ * @return the name of the file
+ */
+ protected String getName(File file) {
+ return file.getName();
+ }
+
+ // ****************************************************************************
+ // ********** FOLLOWING METHODS WERE COPIED FROM Commons IO *******************
+ // ********** FilenameUtils.wildcardMatch() *******************
+ // ********** FilenameUtils.splitOnTokens() *******************
+ // ****************************************************************************
+
+ /**
+ * Checks a filename to see if it matches the specified wildcard matcher.
+ * <p>
+ * The wildcard matcher uses the characters '?' and '*' to represent a
+ * single or multiple wildcard characters.
+ *
+ * @param filename the filename to match on
+ * @param wildcardMatcher the wildcard string to match against
+ * @param system whether to use the system (windows or unix)
+ * @return true if the filename matches the wilcard string
+ */
+ private static boolean wildcardMatch(String filename, String wildcardMatcher, boolean system) {
+ if (filename == null && wildcardMatcher == null) {
+ return true;
+ }
+ if (filename == null || wildcardMatcher == null) {
+ return false;
+ }
+ if (system && (SYSTEM_SEPARATOR == WINDOWS_SEPARATOR)) {
+ filename = filename.toLowerCase();
+ wildcardMatcher = wildcardMatcher.toLowerCase();
+ }
+ String[] wcs = splitOnTokens(wildcardMatcher);
+ boolean anyChars = false;
+ int textIdx = 0;
+ int wcsIdx = 0;
+ Stack backtrack = new Stack();
+
+ // loop around a backtrack stack, to handle complex * matching
+ do {
+ if (backtrack.size() > 0) {
+ int[] array = (int[]) backtrack.pop();
+ wcsIdx = array[0];
+ textIdx = array[1];
+ anyChars = true;
+ }
+
+ // loop whilst tokens and text left to process
+ while (wcsIdx < wcs.length) {
+
+ if (wcs[wcsIdx].equals("?")) {
+ // ? so move to next text char
+ textIdx++;
+ anyChars = false;
+
+ } else if (wcs[wcsIdx].equals("*")) {
+ // set any chars status
+ anyChars = true;
+ if (wcsIdx == wcs.length - 1) {
+ textIdx = filename.length();
+ }
+
+ } else {
+ // matching text token
+ if (anyChars) {
+ // any chars then try to locate text token
+ textIdx = filename.indexOf(wcs[wcsIdx], textIdx);
+ if (textIdx == -1) {
+ // token not found
+ break;
+ }
+ int repeat = filename.indexOf(wcs[wcsIdx], textIdx + 1);
+ if (repeat >= 0) {
+ backtrack.push(new int[] {wcsIdx, repeat});
+ }
+ } else {
+ // matching from current position
+ if (!filename.startsWith(wcs[wcsIdx], textIdx)) {
+ // couldnt match token
+ break;
+ }
+ }
+
+ // matched text token, move text index to end of matched token
+ textIdx += wcs[wcsIdx].length();
+ anyChars = false;
+ }
+
+ wcsIdx++;
+ }
+
+ // full match
+ if (wcsIdx == wcs.length && textIdx == filename.length()) {
+ return true;
+ }
+
+ } while (backtrack.size() > 0);
+
+ return false;
+ }
+
+ /**
+ * Splits a string into a number of tokens.
+ *
+ * @param text the text to split
+ * @return the tokens, never null
+ */
+ static String[] splitOnTokens(String text) {
+ // used by wildcardMatch
+ // package level so a unit test may run on this
+
+ if (text.indexOf("?") == -1 && text.indexOf("*") == -1) {
+ return new String[] { text };
+ }
+
+ char[] array = text.toCharArray();
+ ArrayList list = new ArrayList();
+ StringBuffer buffer = new StringBuffer();
+ for (int i = 0; i < array.length; i++) {
+ if (array[i] == '?' || array[i] == '*') {
+ if (buffer.length() != 0) {
+ list.add(buffer.toString());
+ buffer.setLength(0);
+ }
+ if (array[i] == '?') {
+ list.add("?");
+ } else if (list.size() == 0 ||
+ (i > 0 && list.get(list.size() - 1).equals("*") == false)) {
+ list.add("*");
+ }
+ } else {
+ buffer.append(array[i]);
+ }
+ }
+ if (buffer.length() != 0) {
+ list.add(buffer.toString());
+ }
+
+ return (String[]) list.toArray(new String[0]);
+ }
+}
Propchange: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/NameFilter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/NameFilter.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/NewerFilter.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/NewerFilter.java?rev=424180&view=auto
==============================================================================
--- jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/NewerFilter.java (added)
+++ jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/NewerFilter.java Thu Jul 20 22:04:57 2006
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2005-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.finder.filters;
+
+import java.io.File;
+
+/**
+ * {@link java.io.FileFilter} that tests whether a File is newer than a specified file.
+ *
+ * @version $Id$
+ * @since 0.1
+ */
+public class NewerFilter extends AbstractFileFilter {
+
+ private File compareFile;
+
+ /**
+ * Construct a new {@link java.io.FileFilter} specifying the
+ * file to compare to.
+ *
+ * @param invert Whether the test criteria should be inverted.
+ * @param compareFile The file to compare to.
+ */
+ public NewerFilter(boolean invert, File compareFile) {
+ super(invert);
+ this.compareFile = compareFile;
+ }
+
+ /**
+ * Construct a new {@link java.io.FileFilter} specifying the
+ * name of the file to compare to.
+ *
+ * @param invert Whether the test criteria should be inverted.
+ * @param compareFileName The name of the file to compare to.
+ */
+ public NewerFilter(boolean invert, String compareFileName) {
+ super(invert);
+ this.compareFile = new File(compareFileName);
+ }
+
+ /**
+ * Return the file to compare to.
+ *
+ * @return The file to compare to.
+ */
+ public File getCompareFile() {
+ return compareFile;
+ }
+
+ /**
+ * Return a String representation of this class.
+ * @return a String representation of the class.
+ */
+ public String toString() {
+ return super.toString() + ", file=[" + getCompareFile()+ "]}";
+ }
+
+ /**
+ * Tests whether the {@link File} is newer
+ * than a specified file.
+ *
+ * @param file The {@link File} to test.
+ * @return <code>true</code> if the {@link File}
+ * can be read, otherwise <code>false</code> .
+ */
+ protected boolean test(File file) {
+ return (file.lastModified() > getCompareFile().lastModified());
+ }
+}
Propchange: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/NewerFilter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/NewerFilter.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: 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=424180&view=auto
==============================================================================
--- jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/PathFilter.java (added)
+++ jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/PathFilter.java Thu Jul 20 22:04:57 2006
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2005-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.finder.filters;
+
+import java.io.File;
+
+/**
+ * {@link java.io.FileFilter} implementation that uses wildcard matching on the file's path.
+ *
+ * @version $Id$
+ * @since 0.1
+ */
+public class PathFilter extends NameFilter {
+
+ /**
+ * Construct a new {@link java.io.FileFilter} 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);
+ }
+
+ /**
+ * Return the name of the path.
+ *
+ * @param file The {@link File} to test.
+ * @return the name of the path
+ */
+ protected String getName(File file) {
+ return file.getPath();
+ }
+}
Propchange: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/PathFilter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/PathFilter.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: 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=424180&view=auto
==============================================================================
--- jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/RegexFilter.java (added)
+++ jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/RegexFilter.java Thu Jul 20 22:04:57 2006
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2005-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.finder.filters;
+
+import java.io.File;
+import java.util.regex.Pattern;
+
+/**
+ * {@link java.io.FileFilter} implementation that uses regular
+ * expression matching on the file path.
+ *
+ * @version $Id$
+ * @since 0.1
+ */
+public class RegexFilter extends AbstractFileFilter {
+
+ private boolean ignoreCase;
+ private String regex;
+ private Pattern pattern;
+
+ /**
+ * Construct a new {@link java.io.FileFilter} 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);
+ this.regex = regex;
+ this.ignoreCase = ignoreCase;
+ if (ignoreCase) {
+ pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
+ } else {
+ pattern = Pattern.compile(regex);
+ }
+ }
+
+ /**
+ * Indicates whether the case should be ignored.
+ *
+ * @return <code>true</code> if the case should be ignored,
+ * otherwise <code>false</code>
+ */
+ public boolean isIgnoreCase() {
+ return ignoreCase;
+ }
+
+ /**
+ * Returnt the regular expression.
+ *
+ * @return The regular expression.
+ */
+ public String getRegex() {
+ return regex;
+ }
+
+ /**
+ * Tests whether the {@link File} can
+ * matches a specified regular expression.
+ *
+ * @param file The {@link File} to test.
+ * @return <code>true</code> if the {@link File}
+ * matches the regular expression, otherwise
+ * <code>false</code>.
+ */
+ protected boolean test(File file) {
+ return pattern.matcher(file.getPath()).matches();
+ }
+
+ /**
+ * Return a String representation of this class.
+ * @return a String representation of the class.
+ */
+ public String toString() {
+ return super.toString() + ", regex=[" + regex + "]" +
+ ", ignoreCase=" + ignoreCase + "}";
+ }
+}
Propchange: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/RegexFilter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/RegexFilter.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: 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=424180&view=auto
==============================================================================
--- jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/SizeFilter.java (added)
+++ jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/SizeFilter.java Thu Jul 20 22:04:57 2006
@@ -0,0 +1,132 @@
+/*
+ * Copyright 2005-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.finder.filters;
+
+import java.io.File;
+
+/**
+ * {@link java.io.FileFilter} implementation that matches on the file size.
+ *
+ * @version $Id$
+ * @since 0.1
+ */
+public class SizeFilter extends AbstractFileFilter {
+
+ private long size;
+ private long factor = 1L;
+ private char comparator = '=';
+ private boolean roundUp = true;
+ private String origSize;
+
+ /**
+ * Construct a new {@link java.io.FileFilter} 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);
+ }
+
+ /**
+ * Construct a new {@link java.io.FileFilter} 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);
+ this.roundUp = roundUp;
+ this.origSize = origSize;
+ String parseSize = (size == null ? "" : size.trim());
+ if (parseSize.length() > 0) {
+ if (parseSize.charAt(0) == '+') {
+ comparator = '>';
+ parseSize = parseSize.substring(1);
+ } else if (parseSize.charAt(0) == '-') {
+ comparator = '<';
+ parseSize = parseSize.substring(1);
+ }
+ }
+
+ if (parseSize.length() > 0) {
+ int lastIdx = parseSize.length() - 1;
+ char lastChar = parseSize.charAt(lastIdx);
+ lastChar = Character.isLetter(lastChar) ? Character.toLowerCase(lastChar) : lastChar;
+ if (lastChar == 'k') {
+ factor = 1024L;
+ } else if (lastChar == 'm') {
+ factor = 1024L * 1024L;
+ } else if (lastChar == 'g') {
+ factor = 1024L * 1024L * 1024L;
+ }
+ if (factor > 1L) {
+ parseSize = parseSize.substring(0, lastIdx);
+ }
+ }
+ try {
+ this.size = (Long.parseLong(parseSize) * factor);
+ } catch(NumberFormatException nfe) {
+ throw new IllegalArgumentException("Argument " + size + " must be an integer.");
+ }
+
+ }
+
+ /**
+ * Return a String representation of this class.
+ * @return a String representation of the class.
+ */
+ public String toString() {
+ StringBuffer buffer = new StringBuffer(super.toString());
+ buffer.append(", size ");
+ buffer.append(comparator);
+ buffer.append(" ");
+ buffer.append(origSize);
+ if (comparator == '=' && factor > 1L) {
+ buffer.append(", roundUp=");
+ buffer.append(roundUp);
+ }
+ return buffer.toString();
+ }
+
+ /**
+ * Tests whether the {@link File} is
+ * a specified size.
+ *
+ * @param file The {@link File} to test.
+ * @return <code>true</code> if the {@link File}
+ * is a specified size, otherwise
+ * <code>false</code>.
+ */
+ protected boolean test(File file) {
+ long fileSize = file.length();
+ switch (comparator) {
+ case '>':
+ return (fileSize > size);
+ case '<':
+ return (fileSize < size);
+ default:
+ if (roundUp) {
+ return (fileSize > (size - factor) && fileSize <= size);
+ } else {
+ return (fileSize >= size && fileSize < (size + factor));
+ }
+ }
+ }
+}
Propchange: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/SizeFilter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/SizeFilter.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/TimeFilter.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/TimeFilter.java?rev=424180&view=auto
==============================================================================
--- jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/TimeFilter.java (added)
+++ jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/TimeFilter.java Thu Jul 20 22:04:57 2006
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2005-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.finder.filters;
+
+import java.io.File;
+
+/**
+ * {@link java.io.FileFilter} that tests whether a File has been modified within a specified
+ * number of days.
+ *
+ * @version $Id$
+ * @since 0.1
+ */
+public class TimeFilter extends AbstractFileFilter {
+
+ private int days;
+ private boolean daystart;
+
+ /**
+ * 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.
+ * @param days The number of days
+ * @param daystart Day Start
+ */
+ public TimeFilter(boolean invert, int days, boolean daystart) {
+ super(invert);
+ this.days = days;
+ this.daystart = daystart;
+ }
+
+ /**
+ * 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.
+ * @param days The number of days
+ * @param daystart Day Start
+ */
+ public TimeFilter(boolean invert, String days, boolean daystart) {
+ super(invert);
+ try {
+ this.days = Integer.parseInt(days);
+ } catch(NumberFormatException nfe) {
+ throw new IllegalArgumentException("Days " + days + " must be an integer.");
+ }
+ this.daystart = daystart;
+ }
+
+ /**
+ * Return the number of days.
+ *
+ * @return The number of days
+ */
+ public int getDays() {
+ return days;
+ }
+
+ /**
+ * Return the amount of time in milliseconds.
+ *
+ * @return The time in milliseconds
+ */
+ public long getTimeInMillis() {
+ return ((long)getDays() * 60000L * 60L * 24L);
+ }
+
+ /**
+ * Return a String representation of this class.
+ * @return a String representation of the class.
+ */
+ public String toString() {
+ return super.toString() + ", days=" + getDays() +
+ ", daystart=" + daystart+ "}";
+ }
+
+ /**
+ * Tests whether the {@link File} has been
+ * modified with the specified number of days.
+ *
+ * @todo need to implement the daystart bits
+ *
+ * @param file The {@link File} to test.
+ * @return <code>true</code> if the {@link File}
+ * has been accessed within the number of days, otherwise
+ * <code>false</code>.
+ */
+ protected boolean test(File file) {
+ return (file.lastModified() > System.currentTimeMillis() - getTimeInMillis());
+ }
+}
Propchange: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/TimeFilter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/TimeFilter.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/TypeFilter.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/TypeFilter.java?rev=424180&view=auto
==============================================================================
--- jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/TypeFilter.java (added)
+++ jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/TypeFilter.java Thu Jul 20 22:04:57 2006
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2005-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.finder.filters;
+
+import java.io.File;
+
+/**
+ * {@link java.io.FileFilter} implementation can test whether a file is a directory
+ * or a file.
+ *
+ * @version $Id$
+ * @since 0.1
+ */
+public class TypeFilter extends AbstractFileFilter {
+
+ /**
+ * Construct a new {@link java.io.FileFilter} specifying whether the
+ * the type required is directories or files.
+ *
+ * @param directory <code>true</code> for directories or
+ * <code>false</code> for files.
+ */
+ public TypeFilter(boolean directory) {
+ super(directory);
+ }
+
+ /**
+ * Return a String representation of this class.
+ * @return a String representation of the class.
+ */
+ public String toString() {
+ return super.toString() + "}";
+ }
+
+ /**
+ * Tests whether the {@link File} is a directory.
+ *
+ * @param file The {@link File} to test.
+ * @return <code>true</code> if the {@link File}
+ * is a directory, otherwise <code>false</code>.
+ */
+ protected boolean test(File file) {
+ return file.isDirectory();
+ }
+}
Propchange: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/TypeFilter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/TypeFilter.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/package.html
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/package.html?rev=424180&view=auto
==============================================================================
--- jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/package.html (added)
+++ jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/filters/package.html Thu Jul 20 22:04:57 2006
@@ -0,0 +1,8 @@
+<html>
+<head>
+<title>Package Documentation for org.apache.commons.finder.filters</title>
+</head>
+<body>
+<p>Concrete {@link java.io.FileFilter} implementations.</p>
+</body>
+</html>
Added: jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/package.html
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/package.html?rev=424180&view=auto
==============================================================================
--- jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/package.html (added)
+++ jakarta/commons/sandbox/finder/trunk/src/java/org/apache/commons/finder/package.html Thu Jul 20 22:04:57 2006
@@ -0,0 +1,8 @@
+<html>
+<head>
+<title>Package Documentation for org.apache.commons.finder</title>
+</head>
+<body>
+<p>Commons Finder is an implementation of the UNIX command line find tool in Java.</p>
+</body>
+</html>
Modified: jakarta/commons/sandbox/finder/trunk/src/test/org/apache/commons/finder/FileFinderTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/finder/trunk/src/test/org/apache/commons/finder/FileFinderTest.java?rev=424180&r1=424179&r2=424180&view=diff
==============================================================================
--- jakarta/commons/sandbox/finder/trunk/src/test/org/apache/commons/finder/FileFinderTest.java (original)
+++ jakarta/commons/sandbox/finder/trunk/src/test/org/apache/commons/finder/FileFinderTest.java Thu Jul 20 22:04:57 2006
@@ -97,45 +97,45 @@
}
public void testFindSize() {
- options.put(Finder.SIZE, "1");
+ options.put(Finder.SIZE, "1k");
File[] files = finder.find(new File(dir, "size"), options);
assertEquals(1, files.length);
}
// finds one in file and also one in dir as
// CVS needs a file in dir for people to commonly have it checked out
- public void testFindTypeF() {
- options.put(Finder.TYPE, "f");
+ public void testFindTypeFile() {
+ options.put(Finder.DIRECTORY, "f");
File[] files = finder.find(new File(dir, "type"), options);
assertEquals(2, files.length);
}
public void testFindTypeD() {
- options.put(Finder.TYPE, "d");
+ options.put(Finder.FILE, "d");
File[] files = finder.find(new File(dir, "type"), options);
assertEquals(2, files.length);
}
- public void testCanReadTrue() {
+ public void testCanWriteTrue() {
options.put(Finder.CAN_WRITE, "true");
File[] files = finder.find(new File(dir, "can_write"), options);
assertEquals(2, files.length);
}
- public void testCanWriteTrue() {
+ public void testCanReadTrue() {
options.put(Finder.CAN_READ, "true");
File[] files = finder.find(new File(dir, "can_read"), options);
assertEquals(2, files.length);
}
- public void testCanReadFalse() {
- options.put(Finder.CAN_WRITE, "false");
+ public void testCanWriteFalse() {
+ options.put(Finder.CANNOT_WRITE, "false");
File[] files = finder.find(new File(dir, "can_write"), options);
assertEquals(0, files.length);
}
- public void testCanWriteFalse() {
- options.put(Finder.CAN_READ, "false");
+ public void testCanReadFalse() {
+ options.put(Finder.CANNOT_READ, "false");
File[] files = finder.find(new File(dir, "can_read"), options);
assertEquals(0, files.length);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org