View Javadoc

1   /* 
2    * Copyright 2002-2006 The Apache Software Foundation
3    * Licensed  under the  Apache License,  Version 2.0  (the "License");
4    * you may not use  this file  except in  compliance with the License.
5    * You may obtain a copy of the License at 
6    * 
7    *   http://www.apache.org/licenses/LICENSE-2.0
8    * 
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed  under the  License is distributed on an "AS IS" BASIS,
11   * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
12   * implied.
13   * 
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.james.util.io;
18  
19  import java.io.File;
20  import java.io.FilenameFilter;
21  
22  /***
23   * Accepts a selection if it is acceptable to both of two {@link FilenameFilter}s.
24   * This takes two {@link FilenameFilter}s as input.
25   *
26   * <p>Eg., to print all files beginning with <code>A</code> and ending with <code>.java</code>:</p>
27   *
28   * <pre>
29   * File dir = new File(".");
30   * String[] files = dir.list( new AndFileFilter(
31   *         new PrefixFileFilter("A"),
32   *         new ExtensionFileFilter(".java")
33   *         )
34   *     );
35   * for ( int i=0; i&lt;files.length; i++ )
36   * {
37   *     System.out.println(files[i]);
38   * }
39   * </pre>
40   *
41   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
42   * @version $Revision: 365582 $ $Date: 2006-01-03 08:51:21 +0000 (mar, 03 gen 2006) $
43   * @since 4.0
44   */
45  public class AndFileFilter
46      implements FilenameFilter
47  {
48      private final FilenameFilter m_filter1;
49      private final FilenameFilter m_filter2;
50  
51      public AndFileFilter( final FilenameFilter filter1, final FilenameFilter filter2 )
52      {
53          m_filter1 = filter1;
54          m_filter2 = filter2;
55      }
56  
57      public boolean accept( final File file, final String name )
58      {
59          return m_filter1.accept( file, name ) && m_filter2.accept( file, name );
60      }
61  }
62  
63