FileDocCategorySizeDatePackage
FindFilter.javaAPI DocExample1635Sat May 31 17:18:34 BST 2003None

FindFilter

public class FindFilter extends Object implements FilenameFilter
Class to encapsulate the filtration for Find. For now just setTTTFilter() methods. Really needs to be a real data structure to allow complex things like -n "*.html" -a \( -size < 0 -o mtime < 5 \).
version
$Id: FindFilter.java,v 1.4 2003/05/31 21:18:34 ian Exp $

Fields Summary
boolean
sizeSet
int
size
String
name
Pattern
nameRE
Constructors Summary
public FindFilter()

	
Methods Summary
public booleanaccept(java.io.File dir, java.lang.String fileName)
Do the filtering. For now, only filter on name

		File f = new File(dir, fileName);
		if (f.isDirectory()) {
			return true;	// allow recursion
		}

		if (nameRE != null) {
			return nameRE.matcher(fileName).matches();
		}

		// TODO size handling.

		// Catchall
		return false;
	
voidsetNameFilter(java.lang.String nameFilter)
Convert the given shell wildcard pattern into internal form (an RE)

		name = nameFilter;
		StringBuffer sb = new StringBuffer('^");
		for (int i = 0; i < nameFilter.length(); i++) {
			char c = nameFilter.charAt(i);
			switch(c) {
				case '.":	sb.append("\\."); break;
				case '*":	sb.append(".*"); break;
				case '?":	sb.append('."); break;
				default:	sb.append(c); break;
			}
		}
		sb.append('$");
		Debug.println("name", "RE=\"" + sb + "\".");
		try {
			nameRE = Pattern.compile(sb.toString());
		} catch (PatternSyntaxException ex) {
			System.err.println("Error: RE " + sb.toString() +
				" didn't compile: " + ex);
		}
	
voidsetSizeFilter(java.lang.String sizeFilter)

		size = Integer.parseInt(sizeFilter);
		sizeSet = true;