<i18n dev> RFR: JDK-8318761: MessageFormat pattern support for CompactNumberFormat, ListFormat, and DateTimeFormatter [v4]

Roger Riggs rriggs at openjdk.org
Tue Feb 6 23:12:54 UTC 2024


On Tue, 6 Feb 2024 22:31:32 GMT, Justin Lu <jlu at openjdk.org> wrote:

>> src/java.base/share/classes/java/text/MessageFormat.java line 681:
>> 
>>> 679:         if (fmt instanceof NumberFormat) {
>>> 680:             // Add any instances returned from the NumberFormat factory methods
>>> 681:             if (fmt.equals(NumberFormat.getInstance(locale))) {
>> 
>> This looks like wack-a-mole code, no good design; likely to be hard to maintain.
>> (I don't have a better idea at the moment though).
>
> I agree, it was the existing design that caused for example, CompactNumberFormat to not automatically be supported by MessageFormat. A simple alternative would be storing the potential pre-defined NumberFormats in some data structure that we could just iterate through to feel less “whack a mole” like, but that array would still suffer from the same maintenance issues. I’ll try to think of something better.

One idea would be to delegate to a (package-private) method in the formatXXX class. 
That would localize to the respective class the details.
(An abstract protected method might be preferred, but its not worth creating extra public API surface area for this).

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/17663#discussion_r1480644067


More information about the i18n-dev mailing list