FileDocCategorySizeDatePackage
FindFilter.javaAPI DocExample1563Thu Mar 08 13:20:10 GMT 2001None

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.3 2001/03/08 18:20:10 ian Exp $

Fields Summary
boolean
sizeSet
int
size
String
name
RE
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 (name != null) {
			return nameRE.match(fileName);
		}

		// 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 = new RE(sb.toString());
		} catch (RESyntaxException ex) {
			System.err.println("For shame! " + ex);
		}
	
voidsetSizeFilter(java.lang.String sizeFilter)

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