001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.commons.io.filefilter;
018
019 import java.io.File;
020 import java.io.Serializable;
021
022 /**
023 * This filter produces a logical NOT of the filters specified.
024 *
025 * @since Commons IO 1.0
026 * @version $Revision: 591058 $ $Date: 2007-11-01 15:47:05 +0000 (Thu, 01 Nov 2007) $
027 *
028 * @author Stephen Colebourne
029 */
030 public class NotFileFilter extends AbstractFileFilter implements Serializable {
031
032 /** The filter */
033 private final IOFileFilter filter;
034
035 /**
036 * Constructs a new file filter that NOTs the result of another filters.
037 *
038 * @param filter the filter, must not be null
039 * @throws IllegalArgumentException if the filter is null
040 */
041 public NotFileFilter(IOFileFilter filter) {
042 if (filter == null) {
043 throw new IllegalArgumentException("The filter must not be null");
044 }
045 this.filter = filter;
046 }
047
048 /**
049 * Checks to see if both filters are true.
050 *
051 * @param file the File to check
052 * @return true if the filter returns false
053 */
054 public boolean accept(File file) {
055 return ! filter.accept(file);
056 }
057
058 /**
059 * Checks to see if both filters are true.
060 *
061 * @param file the File directory
062 * @param name the filename
063 * @return true if the filter returns false
064 */
065 public boolean accept(File file, String name) {
066 return ! filter.accept(file, name);
067 }
068
069 /**
070 * Provide a String representaion of this file filter.
071 *
072 * @return a String representaion
073 */
074 public String toString() {
075 return super.toString() + "(" + filter.toString() + ")";
076 }
077
078 }