8318761: MessageFormat pattern support for CompactNumberFormat, ListFormat, and DateTimeFormatter

Reviewed-by: naoto, rriggs
This commit is contained in:
Justin Lu 2024-02-22 22:27:12 +00:00
parent d695af89f6
commit 00ffc42cef
7 changed files with 1092 additions and 360 deletions

View file

@ -482,6 +482,31 @@ public abstract class DateFormat extends Format {
*/
public static final int DEFAULT = MEDIUM;
/**
* A DateFormat style.
* {@code Style} is an enum which corresponds to the DateFormat style
* constants. Use {@code getValue()} to retrieve the associated int style
* value.
*/
enum Style {
FULL(DateFormat.FULL),
LONG(DateFormat.LONG),
MEDIUM(DateFormat.MEDIUM),
SHORT(DateFormat.SHORT),
DEFAULT(DateFormat.MEDIUM);
private final int value;
Style(int value){
this.value = value;
}
int getValue() {
return value;
}
}
/**
* Gets the time formatter with the default formatting style
* for the default {@link java.util.Locale.Category#FORMAT FORMAT} locale.

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -677,6 +677,33 @@ public abstract class NumberFormat extends Format {
return getInstance(locale, formatStyle, COMPACTSTYLE);
}
/**
* This method compares the passed NumberFormat to a number of pre-defined
* style NumberFormat instances, (created with the passed locale). Returns a
* matching FormatStyle string if found, otherwise null.
* This method is used by MessageFormat to provide string pattens for NumberFormat
* Subformats. Any future pre-defined NumberFormat styles should be added to this method.
*/
static String matchToStyle(NumberFormat fmt, Locale locale) {
if (fmt.equals(NumberFormat.getInstance(locale))) {
return "";
} else if (fmt.equals(NumberFormat.getCurrencyInstance(locale))) {
return "currency";
} else if (fmt.equals(NumberFormat.getPercentInstance(locale))) {
return "percent";
} else if (fmt.equals(NumberFormat.getIntegerInstance(locale))) {
return "integer";
} else if (fmt.equals(NumberFormat.getCompactNumberInstance(locale,
NumberFormat.Style.SHORT))) {
return "compact_short";
} else if (fmt.equals(NumberFormat.getCompactNumberInstance(locale,
NumberFormat.Style.LONG))) {
return "compact_long";
} else {
return null;
}
}
/**
* Returns an array of all locales for which the
* {@code get*Instance} methods of this class can return