Return-Path: Delivered-To: apmail-commons-user-archive@www.apache.org Received: (qmail 69244 invoked from network); 21 Feb 2008 00:55:48 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 21 Feb 2008 00:55:48 -0000 Received: (qmail 31803 invoked by uid 500); 21 Feb 2008 00:55:39 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 31739 invoked by uid 500); 21 Feb 2008 00:55:39 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Jakarta Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 31730 invoked by uid 99); 21 Feb 2008 00:55:39 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Feb 2008 16:55:39 -0800 X-ASF-Spam-Status: No, hits=0.2 required=10.0 tests=SPF_PASS,WHOIS_MYPRIVREG X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of niall.pemberton@gmail.com designates 72.14.204.228 as permitted sender) Received: from [72.14.204.228] (HELO qb-out-0506.google.com) (72.14.204.228) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Feb 2008 00:55:05 +0000 Received: by qb-out-0506.google.com with SMTP id c7so3329479qbc.16 for ; Wed, 20 Feb 2008 16:55:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=WQX1b/RQOFnOvTCWs14lY6FFhK2uhbG/rRPBFqJBgMc=; b=L1MB4Nx7VpSOC6rMBQi7vAhpqJG224MoZsF/T8bbu2H5nxppHgMKxPGtGXOOrY+wO4BVNsPm7ZvdsiWMqE9ZKPTLyVjIry4YchQtZ/fy4CyIqQePx61qy1YCikxyc3PnaXzpWHEIx56l/UwtupEQn1AQlHLvwUYEGryC7kTNJgE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=mfTxH5HUY91slu+YFudC65BkNzKOKjSN2ajeO28SoinNWP43SbTWJP6b6m6bwCtBI12N7Km4JM+kjKo5499kviWtCUXbFQk12LCj89gnPHmQp1eguVh268zdrnKDsei8Gax84UWJ1CYmW7Lf8qDxTMwFcpbvqATtfyIYdOtYjpc= Received: by 10.114.254.1 with SMTP id b1mr8212340wai.140.1203555313365; Wed, 20 Feb 2008 16:55:13 -0800 (PST) Received: by 10.114.155.12 with HTTP; Wed, 20 Feb 2008 16:55:12 -0800 (PST) Message-ID: <55afdc850802201655o48a1aeadv1ed640cbfb46cc77@mail.gmail.com> Date: Thu, 21 Feb 2008 00:55:12 +0000 From: "Niall Pemberton" To: "Jakarta Commons Users List" Subject: Re: Enhanced DirectoryWalker In-Reply-To: <15600006.post@talk.nabble.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <15600006.post@talk.nabble.com> X-Virus-Checked: Checked by ClamAV on apache.org 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 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