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. import java.io.File;
  18. /**
  19. * An abstract class which implements the Java FileFilter and FilenameFilter
  20. * interfaces via the IOFileFilter interface.
  21. * <p>
  22. * Note that a subclass <b>must</b> override one of the accept methods,
  23. * otherwise your class will infinitely loop.
  24. *
  25. * @since Commons IO 1.0
  26. * @version $Revision: 1.9 $ $Date: 2004/02/23 04:37:57 $
  27. *
  28. * @author Henri Yandell
  29. * @author Stephen Colebourne
  30. */
  31. public abstract class AbstractFileFilter implements IOFileFilter {
  32. /**
  33. * Checks to see if the File should be accepted by this filter.
  34. *
  35. * @param file the File to check
  36. * @return true if this file matches the test
  37. */
  38. public boolean accept(File file) {
  39. return accept(file.getParentFile(), file.getName());
  40. }
  41. /**
  42. * Checks to see if the File should be accepted by this filter.
  43. *
  44. * @param dir the directory File to check
  45. * @param name the filename within the directory to check
  46. * @return true if this file matches the test
  47. */
  48. public boolean accept(File dir, String name) {
  49. String filename = dir.getName() + File.separator + name;
  50. return accept(new File(filename));
  51. }
  52. }