This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Summary: | HardCoded DataFolder.SortModes do not conform to standard file sorting behaviour when numbers are in the filename | ||
---|---|---|---|
Product: | platform | Reporter: | sproger1 |
Component: | Data Systems | Assignee: | Jaroslav Havlin <jhavlin> |
Status: | RESOLVED FIXED | ||
Severity: | normal | CC: | apireviews, sproger1, ssazonov |
Priority: | P3 | Keywords: | API_REVIEW_FAST |
Version: | 8.0 | ||
Hardware: | All | ||
OS: | All | ||
Issue Type: | ENHANCEMENT | Exception Reporter: | |
Attachments: | Proposed Patch |
Description
sproger1
2014-02-22 16:27:00 UTC
Please Change: 1) org.openide.loaders.FolderComparator.java From: /** for sorting data objects by names */ private int compareNames(Object o1, Object o2) { return findFileObject(o1).getNameExt().compareTo(findFileObject(o2).getNameExt()); } To: /** for sorting data objects by names in a natural (human intuitive) way */ private int compareNames(Object o1, Object o2) { return NaturalOrderComparator.compare(fo1.getNameExt(), fo2.getNameExt()); } Where NaturalOrderComparator behaves like: org.apache.commons.collections.ComparatorUtils.NaturalOrderComparator http://blog.gomilko.com/2007/05/31/natural-order-for-strings-with-numbers-in-java http://www.java2s.com/Code/Java/Collections-Data-Structure/NaturalOrderComparator.htm ... There are many open source examples. 2) Either make FolderComparator.java a public class OR do not cast DataFolder.SortMode objects to FolderComparator objects without first checking that it is assignable... 3) Allow DataFolder.setMode() method to support custom user-defined(developer defined) SortModes and not just the hardcoded 'public static final SortMode' fields in the DataFolder class. > Problem: Every modern operating system, file browser ... takes into account the fact that file names can have numbers and handles this case by sorting them in a natural way.
Really?? I always have to name my images, movis etc. with 01, 02, ..., 10,... to be correctly sorted (at least on Windows 7 OS).
My Mac OSX 10.9 does alphanumeric sort of the files in the Finder app. The built-in filesystem explorer in Windows 7 also supports alfanumeric sort. So it seems reasonable to have some NaturalOrderComparator in NetBeans. Case-insensitive sorting should also be an option. See related bug https://netbeans.org/bugzilla/show_bug.cgi?id=139753 Created attachment 156875 [details]
Proposed Patch
(In reply to sproger1 from comment #1) > Please Change: > 1) > org.openide.loaders.FolderComparator.java [...] Added new comparator, which supports natural number-sequence ordering and is case insensitive. > 2) [...] OR do not cast DataFolder.SortMode objects to FolderComparator objects > without first checking that it is assignable... OK > 3) Allow DataFolder.setMode() method to support custom SortModes [...] It should work fine now. Thank you for reporting. The fix requires an API change, there is a new public field: org.openide.loaders.DataFolder.SortMode.NATURAL Please review this change. Thank you. Comment on attachment 156875 [details]
Proposed Patch
looks good. Thanks.
Unless there are any objections, I will integrate the patch on Thursday. The patch was integrated as http://hg.netbeans.org/core-main/rev/8ada1ab80a18. Thank you for reviewing. Integrated into 'main-silver', will be available in build *201510300002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress) Changeset: http://hg.netbeans.org/main-silver/rev/8ada1ab80a18 User: Jaroslav Havlin <jhavlin@netbeans.org> Log: #242226: Add natural sorting to DataFolder.SortModes *** Bug 237989 has been marked as a duplicate of this bug. *** |