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

AndFileFilter

public class AndFileFilter extends AbstractFileFilter implements Serializable, ConditionalFileFilter
A {@link java.io.FileFilter} providing conditional AND logic across a list of file filters. This filter returns true if all filters in the list return true. Otherwise, it returns false. Checking of the file filter list stops when the first filter returns false.
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 AndFileFilter()
Constructs a new instance of AndFileFilter.

since
Commons IO 1.1

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

param
fileFilters a List of IOFileFilter instances, copied, null ignored
since
Commons IO 1.1

        if (fileFilters == null) {
            this.fileFilters = new ArrayList();
        } else {
            this.fileFilters = new ArrayList(fileFilters);
        }
    
public AndFileFilter(IOFileFilter filter1, IOFileFilter filter2)
Constructs a new file filter that ANDs 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}

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

        if (this.fileFilters.size() == 0) {
            return false;
        }
        for (Iterator iter = this.fileFilters.iterator(); iter.hasNext();) {
            IOFileFilter fileFilter = (IOFileFilter) iter.next();
            if (!fileFilter.accept(file, name)) {
                return false;
            }
        }
        return true;
    
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 = new ArrayList(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();