6228794: java.text.ChoiceFormat pattern behavior is not well documented.#15392
6228794: java.text.ChoiceFormat pattern behavior is not well documented.#15392justin-curtis-lu wants to merge 16 commits intoopenjdk:masterfrom
Conversation
|
👋 Welcome back jlu! A progress list of the required criteria for merging this PR into |
|
@justin-curtis-lu The following labels will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
|
@justin-curtis-lu this pull request can not be integrated into git checkout JDK-6228794-cFmt-Doc
git fetch https://git.openjdk.org/jdk.git master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push |
| * System.out.println("Format with 1.5 : " + fmt.format(1.5)); | ||
| * System.out.println("Format with 2 : " + fmt.format(2)); | ||
| * System.out.println("Format with 2.1 : " + fmt.format(2.1)); | ||
| * // ... |
There was a problem hiding this comment.
Commenting out (with ellipsis) would not print the result below
There was a problem hiding this comment.
I felt it was redundant to have both the long lines of println and output, so I commented out the println(s) except for the ones of interest, which are Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, and Double.NaN.
However, you're right that commenting it out would not print the below result. I have updated it so that the println and output lines are combined, to provide a more concise example.
| * <i>SubPattern:</i> | ||
| * Limit Relation Format | ||
| * <i>Limit:</i> | ||
| * {@code String} that can be parsed as a {@code double} / "∞" ({@code U+221E}) / "-∞" (-{@code U+221E}). |
There was a problem hiding this comment.
Could the first choice be more specific? Also, do SubPatterns need to be sorted with Limits?
There was a problem hiding this comment.
Could the first choice be more specific?
Updated with a more syntactical definition. Please let me know if you think this is too specific.
Also, do SubPatterns need to be sorted with Limits?
If I am interpreting the question right, you're asking if a subPattern needs a limit to be valid. If that's the question, the answer is yes, ChoiceFormat is designed to have an equal amount of limits and formats (whether from the arrays, or the String pattern). But please let me know if I misinterpreted the question.
subpattern "xyz" where both limit and relation are omitted
jshell> var a = new ChoiceFormat("0#abc|xyz")
a ==> java.text.ChoiceFormat@17863
jshell> a.getLimits()
$21 ==> double[1] { 0.0 }
jshell> a.getFormats()
$22 ==> String[1] { "abc" }
subpattern "#xyz" where limit is omitted
jshell> var b = new ChoiceFormat("0#abc|#xyz")
| Exception java.lang.IllegalArgumentException: Each interval must contain a number before a format
There was a problem hiding this comment.
Please let me know if you think this is too specific.
I think the updated one is better.
For the second part, I meant:
jshell> new ChoiceFormat("0#def|-1#abc|xyz")
| Exception java.lang.IllegalArgumentException: Incorrect order of intervals, must be in ascending order
This should be excluded from the pattern syntax
There was a problem hiding this comment.
This should be excluded from the pattern syntax
I presume you meant that the syntax should include the required ascending order of limits. Updated to make this apparent, I also adjusted the syntax a little bit to be more accurate. The previous syntax could technically have an empty Number
|
|
||
| /** | ||
| * Constructs with limits and corresponding formats based on the pattern. | ||
| * Constructs this ChoiceFormat with limits and corresponding formats |
|
|
||
| /** | ||
| * Get the limits passed in the constructor. | ||
| * Get the limits of this ChoiceFormat. |
|
|
||
| /** | ||
| * Get the formats passed in the constructor. | ||
| * Get the formats of this ChoiceFormat. |
There was a problem hiding this comment.
Fixed, as well as in the other instance, I have also updated https://cr.openjdk.org/~jlu/api/java.base/java/text/ChoiceFormat.html to reflect the changes. Thanks for the review
…wording, a choiceFormat does NOT have to be created with only the arrays constructor.
| * "#" / "<" / "≤" | ||
| * <i>Format:</i> | ||
| * {@code String} | ||
| * Any unicode characters except the <i>Relation</i> symbols |
There was a problem hiding this comment.
Nit: since characters in Java are of Unicode code points, no need to mention unicode here.
| * | ||
| * <i>Note:The relation ≤ is not equivalent to <=</i> | ||
| * | ||
| * <p>Below is an example of constructing a ChoiceFormat with a pattern: |
There was a problem hiding this comment.
FWIW, in other parts of core libs such as java.lang.Double, I've used a definition list <dl> with terms <dt> and definitions <dd> to represent such grammars.
|
@justin-curtis-lu This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be: You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 117 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
|
/integrate |
|
Going to push as commit ce93d27.
Your commit was automatically rebased without conflicts. |
|
@justin-curtis-lu Pushed as commit ce93d27. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Please review this PR and associated CSR which expands on the
java.text.ChoiceFormatspecification regarding its pattern.j.text.ChoiceFormatprovides an example pattern in the class description, but beyond that it does not specify any well-defined syntax for creating a pattern. In addition, methods related to the pattern String are under-specified.The wording for
getLimits()andgetFormats()was also adjusted, as there are other ways to set the limits and formats beyond the constructor.The pattern syntax may be easier to view -> https://cr.openjdk.org/~jlu/api/java.base/java/text/ChoiceFormat.html
Progress
Issues
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/15392/head:pull/15392$ git checkout pull/15392Update a local copy of the PR:
$ git checkout pull/15392$ git pull https://git.openjdk.org/jdk.git pull/15392/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 15392View PR using the GUI difftool:
$ git pr show -t 15392Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/15392.diff
Webrev
Link to Webrev Comment