import java.text.ParsePosition;
import java.util.Collection;
import java.util.HashMap;
+import java.util.Locale;
import java.util.Map;
import com.ibm.icu.text.CompactDecimalDataCache.Data;
// null if created internally using explicit prefixes and suffixes.
private final PluralRules pluralRules;
+ /**
+ * Style parameter for CompactDecimalFormat.
+ * @draft ICU 50
+ * @provisional This API might change or be removed in a future release.
+ */
+ public enum CompactStyle {
+ /**
+ * Short version, like "1.2T"
+ * @draft ICU 50
+ * @provisional This API might change or be removed in a future release.
+ */
+ SHORT,
+ /**
+ * Longer version, like "1.2 trillion", if available. May return same result as SHORT if not.
+ * @draft ICU 50
+ * @provisional This API might change or be removed in a future release.
+ */
+ LONG
+ }
+
+ /**
+ * Create a CompactDecimalFormat appropriate for a locale. The result may
+ * be affected by the number system in the locale, such as ar-u-nu-latn.
+ *
+ * @param locale the desired locale
+ * @param style the compact style
+ * @draft ICU 50
+ * @provisional This API might change or be removed in a future release.
+ */
+ public static CompactDecimalFormat getCompactDecimalInstance(ULocale locale, CompactStyle style) {
+ return new CompactDecimalFormat(locale, style);
+ }
+
+ /**
+ * Create a CompactDecimalFormat appropriate for a locale. The result may
+ * be affected by the number system in the locale, such as ar-u-nu-latn.
+ *
+ * @param locale the desired locale
+ * @param style the compact style
+ * @draft ICU 50
+ * @provisional This API might change or be removed in a future release.
+ */
+ public static CompactDecimalFormat getCompactDecimalInstance(Locale locale, CompactStyle style) {
+ return new CompactDecimalFormat(ULocale.forLocale(locale), style);
+ }
+
/**
* The public mechanism is NumberFormat.getCompactDecimalInstance().
*
* @see java.text.Format#format(Object, StringBuffer, FieldPosition)
* @stable ICU 2.0
*/
+ @Override
public StringBuffer format(Object number,
StringBuffer toAppendTo,
FieldPosition pos) {
* @see java.text.NumberFormat#parseObject(String, ParsePosition)
* @stable ICU 2.0
*/
+ @Override
public final Object parseObject(String source,
ParsePosition parsePosition) {
return parse(source, parsePosition);
return getInstance(inLocale, SCIENTIFICSTYLE);
}
- /**
- * Style parameter for CompactDecimalFormat.
- * @draft ICU 49
- * @provisional This API might change or be removed in a future release.
- */
- public enum CompactStyle {
- /**
- * Short version, like "1.2T"
- * @draft ICU 49
- * @provisional This API might change or be removed in a future release.
- */
- SHORT,
- /**
- * Longer version, like "1.2 trillion", if available. May return same result as SHORT if not.
- * @draft ICU 49
- * @provisional This API might change or be removed in a future release.
- */
- LONG
- }
-
- /**
- * Create a CompactDecimalFormat appropriate for a locale. The result may
- * be affected by the number system in the locale, such as ar-u-nu-latn.
- *
- * @param locale the desired locale
- * @param style the compact style
- * @draft ICU 49
- * @provisional This API might change or be removed in a future release.
- */
- public static final CompactDecimalFormat getCompactDecimalInstance(ULocale locale, CompactStyle style) {
- return new CompactDecimalFormat(locale, style);
- }
-
- /**
- * Create a CompactDecimalFormat appropriate for a locale. The result may
- * be affected by the number system in the locale, such as ar-u-nu-latn.
- *
- * @param locale the desired locale
- * @param style the compact style
- * @draft ICU 49
- * @provisional This API might change or be removed in a future release.
- */
- public static final CompactDecimalFormat getCompactDecimalInstance(Locale locale, CompactStyle style) {
- return new CompactDecimalFormat(ULocale.forLocale(locale), style);
- }
-
-
// ===== Factory stuff =====
/**
* A NumberFormatFactory is used to register new number formats. The factory
* {@inheritDoc}
* @stable ICU 2.6
*/
+ @Override
public final boolean visible() {
return visible;
}
* {@inheritDoc}
* @stable ICU 2.6
*/
+ @Override
public final Set<String> getSupportedLocaleNames() {
return localeNames;
}
* Overrides hashCode.
* @stable ICU 2.0
*/
+ @Override
public int hashCode() {
return maximumIntegerDigits * 37 + maxFractionDigits;
// just enough fields for a reasonable distribution
* @return true if the object is equal to this.
* @stable ICU 2.0
*/
+ @Override
public boolean equals(Object obj) {
if (obj == null) return false;
if (this == obj)
* Overrides clone.
* @stable ICU 2.0
*/
+ @Override
public Object clone() {
NumberFormat other = (NumberFormat) super.clone();
return other;
* @internal
* @deprecated This API is ICU internal only.
*/
+ @Deprecated
protected Currency getEffectiveCurrency() {
Currency c = getCurrency();
if (c == null) {
* @return the pattern
* @deprecated ICU 3.4 subclassers should override getPattern(ULocale, int) instead of this method.
*/
+ @Deprecated
protected static String getPattern(Locale forLocale, int choice) {
return getPattern(ULocale.forLocale(forLocale), choice);
}
int entry = (choice == INTEGERSTYLE) ? NUMBERSTYLE :
((choice == ISOCURRENCYSTYLE || choice == PLURALCURRENCYSTYLE)?
CURRENCYSTYLE : choice); //[Richard/GCL]
-
+
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.
getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, forLocale);
String[] numberPatternKeys = { "decimalFormat", "currencyFormat", "percentFormat", "scientificFormat" };
NumberingSystem ns = NumberingSystem.getInstance(forLocale);
-
+
String result = null;
try {
result = rb.getStringWithFallback("NumberElements/" + ns.getName() + "/patterns/"+numberPatternKeys[entry]);
} catch ( MissingResourceException ex ) {
result = rb.getStringWithFallback("NumberElements/latn/patterns/"+numberPatternKeys[entry]);
}
-
+
return result;
}
* NumberFormat.Field values
* @stable ICU 3.6
*/
+ @Override
protected Object readResolve() throws InvalidObjectException {
if (this.getName().equals(INTEGER.getName()))
return INTEGER;
import com.ibm.icu.dev.test.TestFmwk;
import com.ibm.icu.text.CompactDecimalFormat;
+import com.ibm.icu.text.CompactDecimalFormat.CompactStyle;
import com.ibm.icu.text.NumberFormat;
-import com.ibm.icu.text.NumberFormat.CompactStyle;
import com.ibm.icu.util.ULocale;
public class CompactDecimalFormatTest extends TestFmwk {
public void TestCharacterIterator() {
CompactDecimalFormat cdf =
- NumberFormat.getCompactDecimalInstance(ULocale.ENGLISH, CompactStyle.SHORT);
+ CompactDecimalFormat.getCompactDecimalInstance(ULocale.ENGLISH, CompactStyle.SHORT);
AttributedCharacterIterator iter = cdf.formatToCharacterIterator(12346);
assertEquals("CharacterIterator", "12K", iterToString(iter));
iter = cdf.formatToCharacterIterator(12346);
public void TestArabicLongStyle() {
NumberFormat cdf =
- NumberFormat.getCompactDecimalInstance(
+ CompactDecimalFormat.getCompactDecimalInstance(
ULocale.forLanguageTag("ar"), CompactStyle.LONG);
assertEquals("Arabic Long", "٥٫٣ ألف", cdf.format(5300));
}
}
public void checkLocale(ULocale locale, CompactStyle style, Object[][] testData) {
- CompactDecimalFormat cdf = NumberFormat.getCompactDecimalInstance(locale, style);
+ CompactDecimalFormat cdf = CompactDecimalFormat.getCompactDecimalInstance(locale, style);
for (Object[] row : testData) {
assertEquals(locale + " (" + locale.getDisplayName(locale) + ")", row[1], cdf.format(row[0]));
}