KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > io > filefilter > AndFileFilter


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 JavaDoc;
19
20 /**
21  * This filter produces a logical AND of the two filters specified.
22  *
23  * @since Commons IO 1.0
24  * @version $Revision: 1.8 $ $Date: 2004/02/23 04:37:57 $
25  *
26  * @author Stephen Colebourne
27  */

28 public class AndFileFilter extends AbstractFileFilter {
29     
30     /** The first filter */
31     private IOFileFilter filter1;
32     /** The second filter */
33     private IOFileFilter filter2;
34
35     /**
36      * Constructs a new file filter that ANDs the result of two other filters.
37      *
38      * @param filter1 the first filter, must not be null
39      * @param filter2 the second filter, must not be null
40      * @throws IllegalArgumentException if either filter is null
41      */

42     public AndFileFilter(IOFileFilter filter1, IOFileFilter filter2) {
43         if (filter1 == null || filter2 == null) {
44             throw new IllegalArgumentException JavaDoc("The filters must not be null");
45         }
46         this.filter1 = filter1;
47         this.filter2 = filter2;
48     }
49
50     /**
51      * Checks to see if both filters are true.
52      *
53      * @param file the File to check
54      * @return true if both filters are true
55      */

56     public boolean accept(File JavaDoc file) {
57         return filter1.accept(file) && filter2.accept(file);
58     }
59     
60     /**
61      * Checks to see if both filters are true.
62      *
63      * @param file the File directory
64      * @param name the filename
65      * @return true if both filters are true
66      */

67     public boolean accept(File JavaDoc file, String JavaDoc name) {
68         return filter1.accept(file, name) && filter2.accept(file, name);
69     }
70     
71 }
72
Popular Tags