commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Niall Pemberton (JIRA)" <j...@apache.org>
Subject [jira] Resolved: (IO-176) Add an overridable sort callback to the filenames
Date Sat, 29 Nov 2008 05:08:44 GMT

     [ https://issues.apache.org/jira/browse/IO-176?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Niall Pemberton resolved IO-176.
--------------------------------

       Resolution: Fixed
    Fix Version/s: 2.0
         Assignee: Niall Pemberton

Thanks for the suggestion - I have added this:

http://svn.apache.org/viewvc?view=rev&revision=721635

> Add an overridable sort  callback to the filenames
> --------------------------------------------------
>
>                 Key: IO-176
>                 URL: https://issues.apache.org/jira/browse/IO-176
>             Project: Commons IO
>          Issue Type: Improvement
>         Environment: Windows (others too I'm sure)
>            Reporter: David Felsenthal
>            Assignee: Niall Pemberton
>            Priority: Minor
>             Fix For: 2.0
>
>
> Several people have requested the ability to sort the file names that are used by the
directory walker. I'd suggest (and have done for myself) using an overridable callback rather
than a filter. This allows current code to operate unbroken.
> I changed line 394 of DirectoryWalker:
> 	
> 			File[] childFiles = handleFileNames((filter == null ? directory.listFiles() : directory.listFiles(filter)));
> Added:
> 	/**
> 	 * Overridable callback method invoked when a directory is visited.
> 	 * <p>
> 	 * This implementation does nothing.
> 	 * 
> 	 * @param names
> 	 *            the array of File objects in arbitrary order
> 	 *            
> 	 * @return the (possibly manipulated) array of File           
> 	 * @throws IOException
> 	 *             if an I/O Error occurs
> 	 *             
> 	 *             
> 	 */
> 	protected File[] handleFileNames(File [] names) throws IOException {
> 		// do nothing - overridable by subclass
> 		return names;
> 	}
> And overrode it like this in my case, as I wanted reverse alphabetic:
> 			@Override
> 			protected File[] handleFileNames(File[] names) throws IOException {
> 				Arrays.sort(names, new Comparator<File>() {
> 					public int compare(File file1, File file2) {
> 						return file2.getName().toUpperCase().compareTo(
> 								file1.getName().toUpperCase());
> 					}
> 				});
> 				return names;
> 			}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message