ICU-13453 Fixing DecimalFormat getPositivePrefix backwards compatibility.
X-SVN-Rev: 40847
This commit is contained in:
parent
eca52aa122
commit
9d9471e586
@ -138,31 +138,29 @@ public class FormattedNumber {
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @deprecated This API is ICU internal only.
|
||||
* @deprecated This API is ICU internal only. Use {@link #populateFieldPosition} or
|
||||
* {@link #getFieldIterator} for similar functionality.
|
||||
*/
|
||||
@Deprecated
|
||||
public String getPrefix() {
|
||||
NumberStringBuilder temp = new NumberStringBuilder();
|
||||
int length = micros.modOuter.apply(temp, 0, 0);
|
||||
length += micros.modMiddle.apply(temp, 0, length);
|
||||
/* length += */ micros.modInner.apply(temp, 0, length);
|
||||
int prefixLength = micros.modOuter.getPrefixLength() + micros.modMiddle.getPrefixLength()
|
||||
+ micros.modInner.getPrefixLength();
|
||||
// #13453: DecimalFormat wants the affixes from the pattern only (modMiddle).
|
||||
micros.modMiddle.apply(temp, 0, 0);
|
||||
int prefixLength = micros.modMiddle.getPrefixLength();
|
||||
return temp.subSequence(0, prefixLength).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @deprecated This API is ICU internal only.
|
||||
* @deprecated This API is ICU internal only. Use {@link #populateFieldPosition} or
|
||||
* {@link #getFieldIterator} for similar functionality.
|
||||
*/
|
||||
@Deprecated
|
||||
public String getSuffix() {
|
||||
NumberStringBuilder temp = new NumberStringBuilder();
|
||||
int length = micros.modOuter.apply(temp, 0, 0);
|
||||
length += micros.modMiddle.apply(temp, 0, length);
|
||||
length += micros.modInner.apply(temp, 0, length);
|
||||
int prefixLength = micros.modOuter.getPrefixLength() + micros.modMiddle.getPrefixLength()
|
||||
+ micros.modInner.getPrefixLength();
|
||||
// #13453: DecimalFormat wants the affixes from the pattern only (modMiddle).
|
||||
int length = micros.modMiddle.apply(temp, 0, 0);
|
||||
int prefixLength = micros.modMiddle.getPrefixLength();
|
||||
return temp.subSequence(prefixLength, length).toString();
|
||||
}
|
||||
|
||||
@ -206,7 +204,7 @@ public class FormattedNumber {
|
||||
// #equals() or #hashCode() on them directly.
|
||||
FormattedNumber _other = (FormattedNumber) other;
|
||||
return Arrays.equals(nsb.toCharArray(), _other.nsb.toCharArray())
|
||||
^ Arrays.equals(nsb.toFieldArray(), _other.nsb.toFieldArray())
|
||||
^ fq.toBigDecimal().equals(_other.fq.toBigDecimal());
|
||||
&& Arrays.equals(nsb.toFieldArray(), _other.nsb.toFieldArray())
|
||||
&& fq.toBigDecimal().equals(_other.fq.toBigDecimal());
|
||||
}
|
||||
}
|
@ -5331,6 +5331,23 @@ public class NumberFormatTest extends TestFmwk {
|
||||
assertEquals("Grouping should be off", false, df.isGroupingUsed());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Test13453_AffixContent() {
|
||||
DecimalFormat df = (DecimalFormat) DecimalFormat.getScientificInstance();
|
||||
assertEquals("Scientific should NOT be included", "", df.getPositiveSuffix());
|
||||
|
||||
df = CompactDecimalFormat.getInstance(ULocale.ENGLISH, CompactDecimalFormat.CompactStyle.SHORT);
|
||||
assertEquals("Compact should NOT be included", "", df.getPositiveSuffix());
|
||||
|
||||
df = (DecimalFormat) DecimalFormat.getInstance(NumberFormat.ISOCURRENCYSTYLE);
|
||||
df.setCurrency(Currency.getInstance("GBP"));
|
||||
assertEquals("ISO currency SHOULD be included", "GBP", df.getPositivePrefix());
|
||||
|
||||
df = (DecimalFormat) DecimalFormat.getInstance(NumberFormat.PLURALCURRENCYSTYLE);
|
||||
df.setCurrency(Currency.getInstance("GBP"));
|
||||
assertEquals("Plural name SHOULD be included", " British pounds", df.getPositiveSuffix());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Test11035_FormatCurrencyAmount() {
|
||||
double amount = 12345.67;
|
||||
|
Loading…
Reference in New Issue
Block a user