Re: Java implementation of Alpha-numeric comparator

2014-12-17 Thread Ivan Gerasimov
Thanks Sherman for the comments! By the way, the Microsoft's StrCmpLogicalW() does it in the opposite direction, i.e. strings with more leading zeros come earlier. If people find it useful, we can make it configurable. It's always desired to have a "customizable" approach for numeric order

Re: Java implementation of Alpha-numeric comparator

2014-12-16 Thread Xueming Shen
Maybe it can be considered as a special "tailoring" of UCA. It's "alphabetic" + "numeric", the "alphabetic" part got to be "locale sensitive". The "non-locale-sensitive-alphabetic-order" is a special case of locale sensitive sorting. It might be true most people don't care about it here, but so

Re: Java implementation of Alpha-numeric comparator

2014-12-16 Thread Naoto Sato
j.t.Collator is basically for locale sensitive sorting, and I think this use case is locale independent. Aside from how significant to have it in the library, I am not sure j.t.Collator is the right place. Naoto On 12/16/14 11:04 AM, Xueming Shen wrote: On 12/16/2014 06:58 AM, roger riggs wro

Re: Java implementation of Alpha-numeric comparator

2014-12-16 Thread Xueming Shen
On 12/16/2014 10:44 AM, Ivan Gerasimov wrote: On 16.12.2014 17:58, roger riggs wrote: Hi Ivan, In which package/class do you propose to add the API to get the comparator? I was thinking of java.text package, though I don't see a specific class in which the static method could be naturally i

Re: Java implementation of Alpha-numeric comparator

2014-12-16 Thread Xueming Shen
On 12/16/2014 06:58 AM, roger riggs wrote: Hi Ivan, In which package/class do you propose to add the API to get the comparator? In java.time, comparators are returned from static methods in an interface. This allows lambda to be used for the implementation. For example, ChronoZonedDateTime.time

Re: Java implementation of Alpha-numeric comparator

2014-12-16 Thread Ivan Gerasimov
On 16.12.2014 17:58, roger riggs wrote: Hi Ivan, In which package/class do you propose to add the API to get the comparator? I was thinking of java.text package, though I don't see a specific class in which the static method could be naturally included. This kind of Comparator doesn't seem

Re: Java implementation of Alpha-numeric comparator

2014-12-16 Thread roger riggs
Corrected the internal string example below to reflect the case intended. On 12/16/2014 9:58 AM, roger riggs wrote: Hi Ivan, In which package/class do you propose to add the API to get the comparator? In java.time, comparators are returned from static methods in an interface. This allows l

Re: Java implementation of Alpha-numeric comparator

2014-12-16 Thread roger riggs
Hi Ivan, In which package/class do you propose to add the API to get the comparator? In java.time, comparators are returned from static methods in an interface. This allows lambda to be used for the implementation. For example, ChronoZonedDateTime.timeLineOrder

Re: Java implementation of Alpha-numeric comparator

2014-12-16 Thread Ivan Gerasimov
Got it, thanks! Please find the updated webrev at the same location: http://cr.openjdk.java.net/~igerasim/XXX-AlphaNumeric/1/webrev/ Sincerely yours, Ivan On 16.12.2014 11:23, Remi Forax wrote: On 12/16/2014 09:13 AM, Ivan Gerasimov wrote: Thanks Remi for the comments! As you and Roger

Re: Java implementation of Alpha-numeric comparator

2014-12-16 Thread Remi Forax
On 12/16/2014 09:13 AM, Ivan Gerasimov wrote: Thanks Remi for the comments! As you and Roger suggested I only left a CharSequence variant of the comparator. I also removed the custom Comparator altogether for now, for the sake of simplicity. I guess for the purpose of a sample Character.com

Re: Java implementation of Alpha-numeric comparator

2014-12-16 Thread Ivan Gerasimov
Thanks Remi for the comments! As you and Roger suggested I only left a CharSequence variant of the comparator. I also removed the custom Comparator altogether for now, for the sake of simplicity. I guess for the purpose of a sample Character.compare(ch1, ch2) should be good enough. Here's

Re: Java implementation of Alpha-numeric comparator

2014-12-16 Thread Ivan Gerasimov
Thanks Naoto, good point! Since Character.isDigit is used to determine the numeric part of a string, the full width digits are already taken into account. I only had to modify handling of leading zeros: instead of comparing the character with '0', it's now checking if Character.digit(ch, 10) eq

Re: Java implementation of Alpha-numeric comparator

2014-12-15 Thread Ivan Gerasimov
Thanks Roger! Yes, I agree that a CharSequence variant should be enough. The function is wrapped into a Comparator, so it can easily be plugged into an application. If many people find it useful, I guess it can later be moved from samples to jdk. Here's the updated webrev: http://cr.openjdk.

Re: Java implementation of Alpha-numeric comparator

2014-12-15 Thread Remi Forax
Hi Ivan, hi Roger, Roger, the API already exists it's the interface Comparator. I agree with Roger that a comparator that use a CharSequence is better that the one that use a char array. The thing that worry me is the Comparator taken as parameter, it means that each time the method compare(

Re: Java implementation of Alpha-numeric comparator

2014-12-15 Thread Naoto Sato
Hello, It seems useful to me too, but it should also take digits other than '0' to '9' into account, for example, 1234567890. Naoto On 12/15/14, 2:31 PM, roger riggs wrote: Hi Ivan, It does seem like a useful function, though I would have started with the API, not the implementation. Can i

Re: Java implementation of Alpha-numeric comparator

2014-12-15 Thread roger riggs
Hi Ivan, It does seem like a useful function, though I would have started with the API, not the implementation. Can it apply to CharSequence not only String and maybe skip the separate char[] version, a char[] array can be wrapped to become a CharSequence via CharBuffer. Or a via a new stati

Java implementation of Alpha-numeric comparator

2014-12-15 Thread Ivan Gerasimov
Hello everyone! In certain situations the preferred way of sorting strings is a combination of char-comparing sorting with numeric sorting, where applicable. List of strings sorted this way often look more natural to the human eyes: { "alpha", "java1", "java2", "java10", "zero" } Here