8317612: ChoiceFormat and MessageFormat constructors call non-final public method

Reviewed-by: naoto, lancea
This commit is contained in:
Justin Lu 2023-11-01 21:29:45 +00:00
parent f262f06c97
commit ee57e731d0
2 changed files with 50 additions and 17 deletions

View file

@ -246,6 +246,17 @@ public class ChoiceFormat extends NumberFormat {
* @see #ChoiceFormat(String)
*/
public void applyPattern(String newPattern) {
applyPatternImpl(newPattern);
}
/**
* Implementation of applying a pattern to this ChoiceFormat.
* This method processes a String pattern in accordance with the ChoiceFormat
* pattern syntax and populates the internal {@code limits} and {@code formats}
* array variables. See the {@linkplain ##patterns} section for
* further understanding of certain special characters: "#", "<", "\u2264", "|".
*/
private void applyPatternImpl(String newPattern) {
StringBuilder[] segments = new StringBuilder[2];
for (int i = 0; i < segments.length; ++i) {
segments[i] = new StringBuilder();
@ -326,8 +337,8 @@ public class ChoiceFormat extends NumberFormat {
}
/**
* {@return a pattern {@code string} that represents the the limits and formats
* of this ChoiceFormat object}
* {@return a pattern {@code string} that represents the {@code limits} and
* {@code formats} of this ChoiceFormat object}
*
* The {@code string} returned is not guaranteed to be the same input
* {@code string} passed to either {@link #applyPattern(String)} or
@ -396,7 +407,7 @@ public class ChoiceFormat extends NumberFormat {
* @see #applyPattern
*/
public ChoiceFormat(String newPattern) {
applyPattern(newPattern);
applyPatternImpl(newPattern);
}
/**
@ -411,11 +422,12 @@ public class ChoiceFormat extends NumberFormat {
* @see #setChoices
*/
public ChoiceFormat(double[] limits, String[] formats) {
setChoices(limits, formats);
setChoicesImpl(limits, formats);
}
/**
* Set the choices to be used in formatting.
*
* @param limits contains the top value that you want
* parsed with that format, and should be in ascending sorted order. When
* formatting X, the choice will be the i, where
@ -429,6 +441,14 @@ public class ChoiceFormat extends NumberFormat {
* and {@code formats} are not equal
*/
public void setChoices(double[] limits, String[] formats) {
setChoicesImpl(limits, formats);
}
/**
* Implementation of populating the {@code limits} and
* {@code formats} of this ChoiceFormat. Defensive copies are made.
*/
private void setChoicesImpl(double[] limits, String[] formats) {
if (limits.length != formats.length) {
throw new IllegalArgumentException(
"Input arrays must be of the same length.");
@ -441,16 +461,14 @@ public class ChoiceFormat extends NumberFormat {
* {@return the limits of this ChoiceFormat}
*/
public double[] getLimits() {
double[] newLimits = Arrays.copyOf(choiceLimits, choiceLimits.length);
return newLimits;
return Arrays.copyOf(choiceLimits, choiceLimits.length);
}
/**
* {@return the formats of this ChoiceFormat}
*/
public Object[] getFormats() {
Object[] newFormats = Arrays.copyOf(choiceFormats, choiceFormats.length);
return newFormats;
return Arrays.copyOf(choiceFormats, choiceFormats.length);
}
// Overrides