|
134 | 134 | * Use two single quotes in a row to produce a literal single quote. For example, |
135 | 135 | * {@code new ChoiceFormat("1# ''one'' ").format(1)} returns {@code " 'one' "}. |
136 | 136 | * |
| 137 | + * @apiNote A subclass could perform more consistent pattern validation by |
| 138 | + * throwing an {@code IllegalArgumentException} for all incorrect cases. |
| 139 | + * @implNote Given an incorrect pattern, this implementation may either |
| 140 | + * throw an exception or succeed and discard the incorrect portion. A {@code |
| 141 | + * NumberFormatException} is thrown if a {@code limit} can not be |
| 142 | + * parsed as a numeric value and an {@code IllegalArgumentException} is thrown |
| 143 | + * if a {@code SubPattern} is missing, or the intervals are not ascending. |
| 144 | + * Discarding the incorrect portion may result in a ChoiceFormat with |
| 145 | + * empty {@code limits} and {@code formats}. |
| 146 | + * |
137 | 147 | * <h2>Usage Information</h2> |
138 | 148 | * |
139 | 149 | * <p> |
@@ -227,11 +237,12 @@ public class ChoiceFormat extends NumberFormat { |
227 | 237 | private static final long serialVersionUID = 1795184449645032964L; |
228 | 238 |
|
229 | 239 | /** |
230 | | - * Apply the given pattern to this ChoiceFormat object. The syntax |
231 | | - * for the ChoiceFormat pattern can be seen in the {@linkplain ##patterns |
232 | | - * Patterns} section. Unlike {@link #setChoices(double[], String[])} this |
233 | | - * method will throw an {@code IllegalArgumentException} if the {@code |
234 | | - * limits} are not in ascending order. |
| 240 | + * Apply the given pattern to this ChoiceFormat object. The syntax and error |
| 241 | + * related caveats for the ChoiceFormat pattern can be found in the |
| 242 | + * {@linkplain ##patterns Patterns} section. Unlike {@link #setChoices(double[], |
| 243 | + * String[])}, this method will throw an {@code IllegalArgumentException} if |
| 244 | + * the {@code limits} are not in ascending order. |
| 245 | + * |
235 | 246 | * @param newPattern a pattern string |
236 | 247 | * @throws NullPointerException if {@code newPattern} |
237 | 248 | * is {@code null} |
@@ -399,9 +410,11 @@ public String toPattern() { |
399 | 410 |
|
400 | 411 | /** |
401 | 412 | * Constructs a ChoiceFormat with limits and corresponding formats |
402 | | - * based on the pattern. |
403 | | - * The syntax for the ChoiceFormat pattern can be seen in the {@linkplain |
404 | | - * ##patterns Patterns} section. |
| 413 | + * based on the pattern. The syntax and error related caveats for the |
| 414 | + * ChoiceFormat pattern can be found in the {@linkplain ##patterns Patterns} |
| 415 | + * section. Unlike {@link #ChoiceFormat(double[], String[])}, this constructor will |
| 416 | + * throw an {@code IllegalArgumentException} if the {@code limits} are not |
| 417 | + * in ascending order. |
405 | 418 | * |
406 | 419 | * @param newPattern the new pattern string |
407 | 420 | * @throws NullPointerException if {@code newPattern} is |
|
0 commit comments