commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Niall Pemberton" <niall.pember...@gmail.com>
Subject Re: Enhanced DirectoryWalker
Date Thu, 21 Feb 2008 00:55:12 GMT
This was been raised before here: http://tinyurl.com/3dmkcl

The one thing that makes me hesitate is it could be confusing since
the user might expect the Collection to be sorted. Anyway, it needs to
be filed as an enhancement request in JIRA - preferably with a patch -
since thats easier to see the proposed changes and to apply:

http://commons.apache.org/io/issue-tracking.html

Niall

On Wed, Feb 20, 2008 at 10:10 PM, Jeff higgins <oohiggins@yahoo.com> wrote:
>
>  Hi,
>  I would like to request a feature enhancement for
>  org.apache.commons.io.DirectoryWalker.
>
>  add sort comparator to walk method
>
>  Thank you for any consideration.
>  Jeff Higgins
>
>
>
>   private final FileFilter defaultFilter;
>   private FileFilter currentFilter;
>   private final int defaultDepthLimit;
>   private int currentDepthLimit;
>   private final Comparator defaultComparator;
>   private Comparator currentComparator;
>
>   protected DirectoryWalker() {
>     this(null, null, -1);
>   }
>
>
>   protected DirectoryWalker(FileFilter defaultFilter,
>       Comparator defaultComparator, int defaultDepthLimit) {
>     this.defaultFilter = defaultFilter;
>     this.currentFilter = this.defaultFilter;
>     this.defaultDepthLimit = defaultDepthLimit;
>     this.currentDepthLimit = this.defaultDepthLimit;
>     this.defaultComparator = defaultComparator;
>     this.currentComparator = this.defaultComparator;
>   }
>
>
>   protected DirectoryWalker(IOFileFilter directoryFilter,
>       IOFileFilter fileFilter, Comparator defaultComparator,
>       int depthLimit) {
>     if (directoryFilter == null && fileFilter == null) {
>       this.defaultFilter = null;
>     } else {
>       directoryFilter = (directoryFilter != null ? directoryFilter
>           : TrueFileFilter.TRUE);
>       fileFilter = (fileFilter != null ? fileFilter : TrueFileFilter.TRUE);
>       directoryFilter = FileFilterUtils.makeDirectoryOnly(directoryFilter);
>       fileFilter = FileFilterUtils.makeFileOnly(fileFilter);
>       this.defaultFilter = FileFilterUtils.orFileFilter(directoryFilter,
>           fileFilter);
>     }
>     this.currentFilter = this.defaultFilter;
>     this.defaultDepthLimit = depthLimit;
>     this.currentDepthLimit = this.defaultDepthLimit;
>     this.defaultComparator = defaultComparator;
>     this.currentComparator = this.defaultComparator;
>   }
>
>
>   protected final void walk(File startDirectory, Collection results)
>       throws IOException {
>     if (startDirectory == null) {
>       throw new NullPointerException("Start Directory is null");
>     }
>     try {
>       handleStart(startDirectory, results);
>       walk(startDirectory, 0, results);
>       handleEnd(results);
>     } catch (CancelException cancel) {
>       handleCancelled(startDirectory, results, cancel);
>     }
>   }
>
>
>   private void walk(File directory, int depth, Collection results)
>       throws IOException {
>
>     checkIfCancelled(directory, depth, results);
>     if (handleDirectory(directory, depth, results)) {
>       handleDirectoryStart(directory, depth, results);
>       int childDepth = depth + 1;
>       if (currentDepthLimit < 0 || childDepth <= currentDepthLimit) {
>         checkIfCancelled(directory, depth, results);
>         File[] childFiles = (currentFilter == null ? directory.listFiles()
>             : directory.listFiles(currentFilter));
>         if (childFiles == null) {
>           handleRestricted(directory, childDepth, results);
>         } else {
>           if (currentComparator != null)
>             Arrays.sort(childFiles, currentComparator);
>           for (int i = 0; i < childFiles.length; i++) {
>             File childFile = childFiles[i];
>             if (childFile.isDirectory()) {
>               walk(childFile, childDepth, results);
>             } else {
>               checkIfCancelled(childFile, childDepth, results);
>               handleFile(childFile, childDepth, results);
>               checkIfCancelled(childFile, childDepth, results);
>             }
>           }
>         }
>       }
>       handleDirectoryEnd(directory, depth, results);
>     }
>     checkIfCancelled(directory, depth, results);
>   }
>
>   public FileFilter getDefaultFilter() {
>     return defaultFilter;
>   }
>
>   public FileFilter getCurrentFilter() {
>     return currentFilter;
>   }
>
>   public void setCurrentFilter(FileFilter filter) {
>     this.currentFilter = filter;
>   }
>
>   public Comparator getDefaultComparator() {
>     return defaultComparator;
>   }
>
>   public Comparator getCurrentComparator() {
>     return currentComparator;
>   }
>
>   public void setCurrentComparator(Comparator comparator) {
>     this.currentComparator = comp;
>   }
>
>   public int getDefaultDepthLimit() {
>     return defaultDepthLimit;
>   }
>
>   public int getCurrentDepthLimit() {
>     return currentDepthLimit;
>   }
>
>   public void setCurrentDepthLimit(int depth) {
>     this.currentDepthLimit = depth;
>   }
>
>
>
>  --
>  View this message in context: http://www.nabble.com/Enhanced-DirectoryWalker-tp15600006p15600006.html
>  Sent from the Commons - User mailing list archive at Nabble.com.
>
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>  For additional commands, e-mail: user-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message