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