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