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