commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff higgins <oohigg...@yahoo.com>
Subject Re: Enhanced DirectoryWalker
Date Thu, 21 Feb 2008 03:46:00 GMT



Niall Pemberton-2 wrote:
> 
> 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:
> 
> Thanks for your reply and the links, Niall.
> 
> I think the issue of confusing the API can be alleviated by adding
> a couple of appropo constructors and the private final field
> defaultComparator
> and a non-final currentComparator field. With the above changes, and 
> installing the comparator from within an if(currentComparator != null)
> clause 
> will allow complete backward compatability, the user will have to want
> to install a sort comparator, all for the price of a couple reference
> fields
> and a single runtime comparison!  This arrangement will even allow
> changing
> the comparator on the fly.  The o.a.c.io.comparators package already
> has some nice comparators, not to mention the o.a.c.c.ComparatorUtils.
> 
> http://commons.apache.org/io/issue-tracking.html
> 
> I've registered with JIRA, and as soon as I've had a look around I'll
> file an enhancement request w/proposed patch.
> 
> Thanks again
> Jeff Higgins
> 
> 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
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Enhanced-DirectoryWalker-tp15600006p15604266.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


Mime
View raw message