Uploaded image for project: 'Commons Sandbox'
  1. Commons Sandbox
  2. SANDBOX-159

[finder] Make FileFilter implementations public classes in their own package.

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • None
    • Finder
    • None

    Description

      I'm attaching a patch which extracts the FileFilter implementations out of the FindingFilter class into a separate "filters" package. This will allow them to be re-used in conjunction with a new CompositeFilter.

      I've created a new CompositeFilter implementation (which FindingFilter is now based on) which can do AND or OR processing which I think will allow quite powerful FileFilter implementations to be created - since CompositeFilters themselves can be used as component FileFilters for more complex CompositeFilters.

      For example to select files which are less than 1MB and have been modified in the last 20 days

      CompositeFilter filter1 = new CompositeFilter(false, true);
      filter1.addFilter(new SizeFilter(false, "-1m"));
      filter1.addFilter(new TimeFilter(false, 20, false));

      As a by-product IMO it will also make creating test cases for the individual FileFilter implementations easier.

      Attachments

        1. finder-filters-package.txt
          125 kB
          Niall Pemberton

        Activity

          bayard Henri Yandell added a comment -

          +1, go for it.

          Looks like there are a few different types of things fixed - so commits per action would be good if possible.

          bayard Henri Yandell added a comment - +1, go for it. Looks like there are a few different types of things fixed - so commits per action would be good if possible.

          Sorry, only just read your comment after I commited it all in one go. I've summarized additional changes below:

          I've removed the dependency on Commons IO (see comments below on NameFilter and PathFilter).

          The extracted FileFilter implementations also have the following changes/corrections:

          1) Created new AbstractFileFilter and CompositeFilter classes
          2) EmptyFilter now checks that directories contain no files
          3) SizeFilter has switched to using bytes (from blocks) and caters for specifying sizes in Byes, KB, MG and GB. It also can now do "equals", "less than" and "greater than"
          4) NameFilter - removed the dependency on Commons IO (by copying the 2 methods used from FilenameUtils) - same for PathFilter which now extends NameFilter.
          5) RegexFilter now caches the java.util.regex.Pattern
          6) All the FileFilter implementations are now Serializable

          I modified Finder and FindingFilter to use static versions of CanReadFilter, CanWriteFilter, EmptyFilter and TypeFilter and also changed FindingFilter so that FileFilter implementations could be passed in through the "options" Map. FindingFilter now extends the new CompositeFilter class.

          I also corrected a couple of mistakes (incorrect method names) in FileFinderTest and changed it so that it still works with the above changes.

          niallp Niall Pemberton added a comment - Sorry, only just read your comment after I commited it all in one go. I've summarized additional changes below: I've removed the dependency on Commons IO (see comments below on NameFilter and PathFilter). The extracted FileFilter implementations also have the following changes/corrections: 1) Created new AbstractFileFilter and CompositeFilter classes 2) EmptyFilter now checks that directories contain no files 3) SizeFilter has switched to using bytes (from blocks) and caters for specifying sizes in Byes, KB, MG and GB. It also can now do "equals", "less than" and "greater than" 4) NameFilter - removed the dependency on Commons IO (by copying the 2 methods used from FilenameUtils) - same for PathFilter which now extends NameFilter. 5) RegexFilter now caches the java.util.regex.Pattern 6) All the FileFilter implementations are now Serializable I modified Finder and FindingFilter to use static versions of CanReadFilter, CanWriteFilter, EmptyFilter and TypeFilter and also changed FindingFilter so that FileFilter implementations could be passed in through the "options" Map. FindingFilter now extends the new CompositeFilter class. I also corrected a couple of mistakes (incorrect method names) in FileFinderTest and changed it so that it still works with the above changes.
          bayard Henri Yandell added a comment -

          I think this is a finished issue.

          bayard Henri Yandell added a comment - I think this is a finished issue.

          People

            Unassigned Unassigned
            niallp Niall Pemberton
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: