You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "David Felsenthal (JIRA)" <ji...@apache.org> on 2008/08/14 16:47:45 UTC
[jira] Created: (IO-176) Add an overridable sort callback to the
filenames
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
Priority: Minor
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.
[jira] Resolved: (IO-176) Add an overridable sort callback to the
filenames
Posted by "Niall Pemberton (JIRA)" <ji...@apache.org>.
[ 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.
[jira] Commented: (IO-176) Add an overridable sort callback to the
filenames
Posted by "David Felsenthal (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/IO-176?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12651992#action_12651992 ]
David Felsenthal commented on IO-176:
-------------------------------------
Thank you.
David
> 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.
[jira] Issue Comment Edited: (IO-176) Add an overridable sort
callback to the filenames
Posted by "Niall Pemberton (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/IO-176?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12651696#action_12651696 ]
niallp edited comment on IO-176 at 11/28/08 9:24 PM:
--------------------------------------------------------------
btw Commons IO has had a set of Comparator implementations[1] for files since version 1.4 - including a file name implementation that can do case-insensitive compares[2]:
[1] http://commons.apache.org/io/api-release/org/apache/commons/io/comparator/package-summary.html
[2] http://commons.apache.org/io/api-release/org/apache/commons/io/comparator/NameFileComparator.html#NAME_INSENSITIVE_COMPARATOR
I also just added sort methods to those implementations (IO-142) so you will be able to do what you want with the following in DirectoryWalker:
{code}
protected File[] filterDirectoryContents(File directory, int depth, File[] files) throws IOException {
return NameFileComparator.NAME_INSENSITIVE_COMPARATOR.sort(files);
}
{code}
was (Author: niallp):
btw Commons IO has had a set of Comparator implementations[1] for files since version 1.4 - including a file name implementation that can do case-insensitive compares[2]:
[1] http://commons.apache.org/io/api-release/org/apache/commons/io/comparator/package-summary.html
[2] http://commons.apache.org/io/api-release/org/apache/commons/io/comparator/NameFileComparator.html#NAME_INSENSITIVE_COMPARATOR
I also just added sort methods to those implementations (IO-142) so you will be able to do what you want with the following in DirectoryWalker:
[code]
protected File[] filterDirectoryContents(File directory, int depth, File[] files) throws IOException {
return NameFileComparator.NAME_INSENSITIVE_COMPARATOR.sort(files);
}
[code]
> 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.
[jira] Issue Comment Edited: (IO-176) Add an overridable sort
callback to the filenames
Posted by "Niall Pemberton (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/IO-176?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12651696#action_12651696 ]
niallp edited comment on IO-176 at 11/28/08 9:20 PM:
--------------------------------------------------------------
btw Commons IO has had a set of Comparator implementations[1] for files since version 1.4 - including a file name implementation that can do case-insensitive compares[2]:
[1] http://commons.apache.org/io/api-release/org/apache/commons/io/comparator/package-summary.html
[2] http://commons.apache.org/io/api-release/org/apache/commons/io/comparator/NameFileComparator.html#NAME_INSENSITIVE_COMPARATOR
I also just added sort methods to those implementations (IO-142) so you will be able to do what you want with the following in DirectoryWalker:
[code]
protected File[] filterDirectoryContents(File directory, int depth, File[] files) throws IOException {
return NameFileComparator.NAME_INSENSITIVE_COMPARATOR.sort(files);
}
[code]
was (Author: niallp):
btw Commons IO has had a set of Comparator implementations[1] for files since version 1.4 - including a file name implementation that can do case-insensitive compares[2]:
[1] http://commons.apache.org/io/api-release/org/apache/commons/io/comparator/package-summary.html
[2] http://commons.apache.org/io/api-release/org/apache/commons/io/comparator/NameFileComparator.html#NAME_INSENSITIVE_COMPARATOR
I also just added sort methods to those implementations (IO-142) so you will be able to do what you want with the following in DirectoryWalker:
protected File[] filterDirectoryContents(File directory, int depth, File[] files) throws IOException {
return NameFileComparator.NAME_INSENSITIVE_COMPARATOR.sort(files);
}
> 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.
[jira] Commented: (IO-176) Add an overridable sort callback to the
filenames
Posted by "Niall Pemberton (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/IO-176?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12651696#action_12651696 ]
Niall Pemberton commented on IO-176:
------------------------------------
btw Commons IO has had a set of Comparator implementations[1] for files since version 1.4 - including a file name implementation that can do case-insensitive compares[2]:
[1] http://commons.apache.org/io/api-release/org/apache/commons/io/comparator/package-summary.html
[2] http://commons.apache.org/io/api-release/org/apache/commons/io/comparator/NameFileComparator.html#NAME_INSENSITIVE_COMPARATOR
I also just added sort methods to those implementations (IO-142) so you will be able to do what you want with the following in DirectoryWalker:
protected File[] filterDirectoryContents(File directory, int depth, File[] files) throws IOException {
return NameFileComparator.NAME_INSENSITIVE_COMPARATOR.sort(files);
}
> 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.