[ 
https://issues.apache.org/jira/browse/MATH-962?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13625010#comment-13625010
 ] 

Thomas Neidhart commented on MATH-962:
--------------------------------------

This is because internally the number format for the default locale is used in 
your test-case (without specifying another number format). As in this case 
grouping is activated (with ',' being the grouping character, e.g. for US 
locale), the string "1, 2, 3" is interpreted as 123. As there are no other 
values but 3 are expected, the return value is null.

To use the Vector3DFormat with ',' as separator, you should explicitly disable 
grouping like this:

{noformat}
        NumberFormat nf = NumberFormat.getInstance(Locale.getDefault());
        nf.setGroupingUsed(false);
        Vector3DFormat vf = new Vector3DFormat("(", ")", ",", nf);
        System.out.println(vf.parse("(1, 2, 3)")); // prints {1; 2; 3}
        System.out.println(vf.parse("(1,2,3)")); // prints null
{noformat}

Afaik, this is one of the reasons why we use ';' as default separator for these 
vector formats, as this one does not interfere with the usual grouping 
characters for various locale settings.

I am not sure this is really a bug, but the error handling could be improved.
                
> Vector3DFormat.parse does not ignore whitespace
> -----------------------------------------------
>
>                 Key: MATH-962
>                 URL: https://issues.apache.org/jira/browse/MATH-962
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 3.1.1
>         Environment: Macosxm, Java 1.6.0
>            Reporter: Leon French
>            Priority: Minor
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> Vector3DFormat notes it ingores whitespace in the javadoc but in the below 
> example it does not:
>       Vector3DFormat vf = new Vector3DFormat("(", ")", ",");
>       System.out.println(vf.parse("(1, 2, 3)")); //prints {1; 2; 3}
>       System.out.println(vf.parse("(1,2,3)"));   //prints null

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to