Java implementation of Alpha-numeric comparator

Xueming Shen xueming.shen at oracle.com
Tue Dec 16 19:51:09 UTC 2014


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 sooner or later a "locale-based" variant will be asked :-)

-Sherman

On 12/16/2014 11:32 AM, Naoto Sato wrote:
> 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 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.timeLineOrder
>>> <https://docs.oracle.com/javase/8/docs/api/java/time/chrono/ChronoZonedDateTime.html#timeLineOrder-->()[1]
>>>
>>>
>>> For example a static method could be added to CharSequence:
>>> public static int Comparator<CharSequence> alphaNumericComparator() ...
>>>
>>> In use it would be
>>> CharSequence.alphaNumericComparator().compare("012", "234");
>>>
>>
>> This is more like a special case of j.t.Collator. I'm not sure it's a
>> good idea to put this "special"
>> comparator into CharSequence, without careful planning. I will assume
>> there are more useful
>> utility comparators people would like to see here. To use the original
>> example, while the
>> it's good to have this comparator to compare "jdk 10" and "jdk9", how
>> about "jdk-10" and
>> "jdk 9"? Yes, it is more like a collator:-)
>>
>> -Sherman




More information about the core-libs-dev mailing list