Looks good to me.

--Sean

On 10/13/19 4:27 AM, Weijun Wang wrote:
Please take a review at

    http://cr.openjdk.java.net/~weijun/8231950/webrev.00/

Before this fix, the oneOf(s,list) method compares s to each item of the list 
in a case-insensitive way, and if there are multiple matches, it errors out 
saying input is ambiguous. The comparison looks like

    item.toLowerCase().startsWith(s.toLowerCase()) || 
item.toCamelCase().equalsIgnoreCase(s)

Here, "howAreYou".toCamelCase() == "hAY".

This means "de" or "dE" would match both "decipherOnly" and "dataEncipherment", 
and thus treated ambiguous.

After this fix, the comparison is broken into 2 steps. If there is a single case-sensitive match, it's returned. 
Otherwise, fallback to case-insensitive. This means "de" would match "decipherOnly" and 
"dE" would match "dataEncipherment". This is a behavior change but all working cases still work, 
it's only those ambiguous cases are clean now.

Also, in order to deal with the case that one option starts with another 
option, I've added an exact match at the beginning.

Precisely, the steps are now

    item.equals(s)
    item.startsWith(s) || item.toCamelCase().equals(s)
    item.toLowerCase().startsWith(s.toLowerCase()) || 
item.toCamelCase().equalsIgnoreCase(s)

A new test is added. An existing test is modified, where ambiguous case becomes 
not now.

Thanks,
Max

Reply via email to