FileDocCategorySizeDatePackage
OrFileFilter.javaAPI DocAndroid 1.5 API5091Wed May 06 22:42:46 BST 2009org.apache.commons.io.filefilter

OrFileFilter

public class OrFileFilter extends AbstractFileFilter implements Serializable, ConditionalFileFilter
A {@link java.io.FileFilter} providing conditional OR logic across a list of file filters. This filter returns true if any filters in the list return true. Otherwise, it returns false. Checking of the file filter list stops when the first filter returns true.
since
Commons IO 1.0
version
$Revision: 606381 $ $Date: 2007-12-22 02:03:16 +0000 (Sat, 22 Dec 2007) $
author
Steven Caswell

Fields Summary
private List
fileFilters
The list of file filters.
Constructors Summary
public OrFileFilter()
Constructs a new instance of OrFileFilter.

since
Commons IO 1.1

        this.fileFilters = new ArrayList();
    
public OrFileFilter(List fileFilters)
Constructs a new instance of OrFileFilter with the specified filters.

param
fileFilters the file filters for this filter, copied, null ignored
since
Commons IO 1.1

        if (fileFilters == null) {
            this.fileFilters = new ArrayList();
        } else {
            this.fileFilters = new ArrayList(fileFilters);
        }
    
public OrFileFilter(IOFileFilter filter1, IOFileFilter filter2)
Constructs a new file filter that ORs the result of two other filters.

param
filter1 the first filter, must not be null
param
filter2 the second filter, must not be null
throws
IllegalArgumentException if either filter is null

        if (filter1 == null || filter2 == null) {
            throw new IllegalArgumentException("The filters must not be null");
        }
        this.fileFilters = new ArrayList();
        addFileFilter(filter1);
        addFileFilter(filter2);
    
Methods Summary
public booleanaccept(java.io.File file)
{@inheritDoc}

        for (Iterator iter = this.fileFilters.iterator(); iter.hasNext();) {
            IOFileFilter fileFilter = (IOFileFilter) iter.next();
            if (fileFilter.accept(file)) {
                return true;
            }
        }
        return false;
    
public booleanaccept(java.io.File file, java.lang.String name)
{@inheritDoc}

        for (Iterator iter = this.fileFilters.iterator(); iter.hasNext();) {
            IOFileFilter fileFilter = (IOFileFilter) iter.next();
            if (fileFilter.accept(file, name)) {
                return true;
            }
        }
        return false;
    
public voidaddFileFilter(org.apache.commons.io.filefilter.IOFileFilter ioFileFilter)
{@inheritDoc}

        this.fileFilters.add(ioFileFilter);
    
public java.util.ListgetFileFilters()
{@inheritDoc}

        return Collections.unmodifiableList(this.fileFilters);
    
public booleanremoveFileFilter(org.apache.commons.io.filefilter.IOFileFilter ioFileFilter)
{@inheritDoc}

        return this.fileFilters.remove(ioFileFilter);
    
public voidsetFileFilters(java.util.List fileFilters)
{@inheritDoc}

        this.fileFilters = fileFilters;
    
public java.lang.StringtoString()
Provide a String representaion of this file filter.

return
a String representaion

        StringBuffer buffer = new StringBuffer();
        buffer.append(super.toString());
        buffer.append("(");
        if (fileFilters != null) {
            for (int i = 0; i < fileFilters.size(); i++) {
                if (i > 0) {
                    buffer.append(",");
                }
                Object filter = fileFilters.get(i);
                buffer.append(filter == null ? "null" : filter.toString());
            }
        }
        buffer.append(")");
        return buffer.toString();