~ubuntu-branches/ubuntu/maverick/commons-io/maverick

« back to all changes in this revision

Viewing changes to src/java/org/apache/commons/io/filefilter/NotFileFilter.java

  • Committer: Bazaar Package Importer
  • Author(s): Wolfgang Baer
  • Date: 2005-10-16 13:44:21 UTC
  • Revision ID: james.westby@ubuntu.com-20051016134421-v2gfddy6iovz449t
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2002-2004 The Apache Software Foundation.
 
3
 * 
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * You may obtain a copy of the License at
 
7
 * 
 
8
 *      http://www.apache.org/licenses/LICENSE-2.0
 
9
 * 
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS IS" BASIS,
 
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 */
 
16
package org.apache.commons.io.filefilter;
 
17
 
 
18
import java.io.File;
 
19
 
 
20
/**
 
21
 * This filter produces a logical NOT of the filters specified.
 
22
 *
 
23
 * @since Commons IO 1.0
 
24
 * @version $Revision: 1.6 $ $Date: 2004/02/23 04:37:57 $
 
25
 * 
 
26
 * @author Stephen Colebourne
 
27
 */
 
28
public class NotFileFilter extends AbstractFileFilter {
 
29
    
 
30
    /** The filter */
 
31
    private IOFileFilter filter;
 
32
 
 
33
    /**
 
34
     * Constructs a new file filter that NOTs the result of another filters.
 
35
     * 
 
36
     * @param filter  the filter, must not be null
 
37
     * @throws IllegalArgumentException if the filter is null
 
38
     */
 
39
    public NotFileFilter(IOFileFilter filter) {
 
40
        if (filter == null) {
 
41
            throw new IllegalArgumentException("The filter must not be null");
 
42
        }
 
43
        this.filter = filter;
 
44
    }
 
45
 
 
46
    /**
 
47
     * Checks to see if both filters are true.
 
48
     * 
 
49
     * @param file  the File to check
 
50
     * @return true if the filter returns false
 
51
     */
 
52
    public boolean accept(File file) {
 
53
        return ! filter.accept(file);
 
54
    }
 
55
    
 
56
    /**
 
57
     * Checks to see if both filters are true.
 
58
     * 
 
59
     * @param file  the File directory
 
60
     * @param name  the filename
 
61
     * @return true if the filter returns false
 
62
     */
 
63
    public boolean accept(File file, String name) {
 
64
        return ! filter.accept(file, name);
 
65
    }
 
66
    
 
67
}