Java implementation of Alpha-numeric comparator

roger riggs roger.riggs at oracle.com
Mon Dec 15 22:31:33 UTC 2014


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 static method to define a CharSequence from a char array.

$.02, Roger

On 12/15/2014 5:53 AM, Ivan Gerasimov wrote:
> 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's presented a sample implementation of the comparator, which 
> supports this way of sorting.
> I placed it under src/sample directory.
>
> http://cr.openjdk.java.net/~igerasim/XXXXXXX-AlphaNumeric/0/webrev/
>
>
> MSDN provides the function StrCmpLogicalW(), which can be used for 
> similar sort order.
> http://msdn.microsoft.com/en-us/library/windows/desktop/bb759947%28v=vs.85%29.aspx 
>
>
> The differences are:
>  - case-sensitivity (StrCmpLogicalW is case-insensitive);
>  - treating leading zeroes;
>  - more accurate handling of strings with big numbers, which cannot be 
> converted to int/long.
>
> I guess this comparator may become particularly useful when we'll have 
> 'java10' and update releases/build numbers > 99 in the lists :)
>
> I want to ask the community about how useful this comparator may be to 
> you?
>
> Sincerely yours,
> Ivan
>




More information about the core-libs-dev mailing list