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. * This filter produces a logical OR of the two filters specified.
  20. *
  21. * @since Commons IO 1.0
  22. * @version $Revision: 1.8 $ $Date: 2004/02/23 04:37:57 $
  23. *
  24. * @author Stephen Colebourne
  25. */
  26. public class OrFileFilter extends AbstractFileFilter {
  27. /** The first filter */
  28. private IOFileFilter filter1;
  29. /** The second filter */
  30. private IOFileFilter filter2;
  31. /**
  32. * Constructs a new file filter that ORs the result of two other filters.
  33. *
  34. * @param filter1 the first filter, must not be null
  35. * @param filter2 the second filter, must not be null
  36. * @throws IllegalArgumentException if either filter is null
  37. */
  38. public OrFileFilter(IOFileFilter filter1, IOFileFilter filter2) {
  39. if (filter1 == null || filter2 == null) {
  40. throw new IllegalArgumentException("The filters must not be null");
  41. }
  42. this.filter1 = filter1;
  43. this.filter2 = filter2;
  44. }
  45. /**
  46. * Checks to see if either filter is true.
  47. *
  48. * @param file the File to check
  49. * @return true if either filter is true
  50. */
  51. public boolean accept(File file) {
  52. return filter1.accept(file) || filter2.accept(file);
  53. }
  54. /**
  55. * Checks to see if either filter is true.
  56. *
  57. * @param file the File directory
  58. * @param name the filename
  59. * @return true if either filter is true
  60. */
  61. public boolean accept(File file, String name) {
  62. return filter1.accept(file, name) || filter2.accept(file, name);
  63. }
  64. }