# [10] RFR 8134512 : provide Alpha-Numeric (logical) Comparator

Peter Levart peter.levart at gmail.com
Fri Jul 28 14:32:25 UTC 2017

```Hi Ivan,

In the light of what Stuart Marks wrote, then what do you think about a
parameterized comparator (would be sub-optimal, I know) where one would
supply
2 Comparator(s) which would be used to compare Ax and Nx sub-sequences
respectively as described below...

For Nx sub-sequences, one would need a comparator comparing the reversed
sequence lexicographically, but for Ax sub-sequences, one could choose
from a plethora of case-(in)sensitive comparator(s) and collators
already available on the platform.

Regards, peter

On 07/28/2017 04:12 PM, Peter Levart wrote:
> Hi Ivan,
>
> Would I be wrong if I described the logic of these two comparators as
> the following:
>
> The comparator compares two character sequences as though each of them
> would be 1st transformed into a tuple of the form:
>
> (A0, N0, A1, N1, ..., An-1, Nn-1, An)
>
> where:
>
> A0 and An are (possibly empty) sub-sequences consisting of
> non-decimal-digit characters
> A1 ... An-1 are non-empty sub-sequences consisting of
> non-decimal-digit characters
> N0 ... Nn-1 are non-empty sub-sequences consisting of decimal-digit
> characters
>
> ...such that all sub-sequences concatenated together in order as they
> appear in the tuple yield the original character sequence.
>
> Any characher sequence can be uniquely transformed into such tuple.
> For example:
>
> "" -> (A0); where A0 == ""
> "ab10" -> (A0, N0, A1); where A0 == "ab", N0 == "10", A1 = ""
> "1" -> (A0, N0, A1); where A0 == "", N0 == "1", A1 = ""
> ...
>
> After transformation, the tuples are compared by their elements (from
> left to right) so that corresponding Ax elements are compared
> lexicographically and Nx elements are compared as decimal integers
> (with two variations considering leading zeroes).
>
> If I am right than perhaps such description would be easier to
> understand.
>
> What do you think?
>
>
> Regards, Peter
>
> On 07/19/2017 10:41 AM, Ivan Gerasimov wrote:
>> Hello!
>>
>> It is a proposal to provide a String comparator, which will pay
>> attention to the numbers embedded into the strings (should they
>> present).
>>
>> This proposal was initially discussed back in 2014 and seemed to
>> bring some interest from the community:
>> http://mail.openjdk.java.net/pipermail/core-libs-dev/2014-December/030343.html
>>
>>
>> In the latest webrev two methods are added to the public API:
>> j.u.Comparator.comparingNumerically() and
>> j.u.Comparator.comparingNumericallyLeadingZerosAhead().
>>
>> The regression test is extended to exercise this new comparator.
>>
>> BUGURL: https://bugs.openjdk.java.net/browse/JDK-8134512
>> WEBREV: http://cr.openjdk.java.net/~igerasim/8134512/01/webrev/
>>
>> Comments, suggestions are very welcome!
>>
>

```

More information about the core-libs-dev mailing list