From f71f8474119e92c568ffeab2320f9e070512128a Mon Sep 17 00:00:00 2001 From: konsoletyper Date: Thu, 19 Jun 2014 16:07:08 +0400 Subject: [PATCH] Adds DecimalFormatSymbols support --- .../impl/unicode/CLDRDecimalData.java | 36 ++++ .../classlib/java/text/TDecimalFormat.java | 20 ++- .../java/text/TDecimalFormatSymbols.java | 156 +++++++++++++++++- 3 files changed, 201 insertions(+), 11 deletions(-) diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRDecimalData.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRDecimalData.java index 77777ad42..7eef6db84 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRDecimalData.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRDecimalData.java @@ -37,4 +37,40 @@ public interface CLDRDecimalData extends Resource { int getMinimumIntegerDigits(); void setMinimumIntegerDigits(int value); + + int getGroupingSeparator(); + + void setGroupingSeparator(int value); + + int getDecimalSeparator(); + + void setDecimalSeparator(int value); + + int getPerMill(); + + void setPerMill(int value); + + int getPercent(); + + void setPercent(int value); + + String getNaN(); + + void setNaN(String nan); + + String getInfinity(); + + void setInfinity(String infinity); + + int getMinusSign(); + + void setMinusSign(int value); + + int getMonetaryDecimalSeparator(); + + void setMonetaryDecimalSeparator(int value); + + String getExponentSeparator(); + + void setExponentSeparator(String value); } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDecimalFormat.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDecimalFormat.java index cb237ce16..ac94ff1e4 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDecimalFormat.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDecimalFormat.java @@ -25,8 +25,7 @@ import org.teavm.classlib.java.util.TLocale; * @author Alexey Andreev */ public class TDecimalFormat extends TNumberFormat { - private transient boolean parseBigDecimal = false; - private transient TDecimalFormatSymbols symbols; + private TDecimalFormatSymbols symbols; public TDecimalFormat() { this(CLDRHelper.resolveDecimalFormat(TLocale.getDefault().getLanguage(), TLocale.getDefault().getCountry())); @@ -37,8 +36,9 @@ public class TDecimalFormat extends TNumberFormat { } public TDecimalFormat(String pattern, TDecimalFormatSymbols value) { - symbols = (TDecimalFormatSymbols) value.clone(); + symbols = (TDecimalFormatSymbols)value.clone(); TLocale locale = symbols.getLocale(); + applyPattern(pattern); CLDRDecimalData decimalData = CLDRHelper.resolveDecimalData(locale.getLanguage(), locale.getCountry()); super.setMaximumFractionDigits(decimalData.getMaximumFractionDigits()); @@ -47,13 +47,12 @@ public class TDecimalFormat extends TNumberFormat { super.setMinimumIntegerDigits(decimalData.getMinimumIntegerDigits()); } - public DecimalFormatSymbols getDecimalFormatSymbols() { - return (DecimalFormatSymbols) symbols.clone(); + public void applyPattern(String pattern) { + } - @Override - public StringBuffer format(double value, StringBuffer buffer, TFieldPosition field) { - return null; + public DecimalFormatSymbols getDecimalFormatSymbols() { + return (DecimalFormatSymbols)symbols.clone(); } @Override @@ -65,4 +64,9 @@ public class TDecimalFormat extends TNumberFormat { public Number parse(String string, TParsePosition position) { return null; } + + @Override + public StringBuffer format(double value, StringBuffer buffer, TFieldPosition field) { + return null; + } } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDecimalFormatSymbols.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDecimalFormatSymbols.java index 68b19d26d..56191625a 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDecimalFormatSymbols.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDecimalFormatSymbols.java @@ -15,6 +15,8 @@ */ package org.teavm.classlib.java.text; +import org.teavm.classlib.impl.unicode.CLDRDecimalData; +import org.teavm.classlib.impl.unicode.CLDRHelper; import org.teavm.classlib.java.util.TLocale; /** @@ -22,19 +24,167 @@ import org.teavm.classlib.java.util.TLocale; * @author Alexey Andreev */ public class TDecimalFormatSymbols { - public TDecimalFormatSymbols() { + private TLocale locale; + private char zeroDigit; + private char groupingSeparator; + private char decimalSeparator; + private char perMill; + private char percent; + private char digit; + private char patternSeparator; + private String NaN; + private String infinity; + private char minusSign; + private char monetaryDecimalSeparator; + private String exponentSeparator; + public TDecimalFormatSymbols() { + this(TLocale.getDefault()); } public TDecimalFormatSymbols(TLocale locale) { + this.locale = locale; + initData(); + } + private void initData() { + CLDRDecimalData data = CLDRHelper.resolveDecimalData(locale.getLanguage(), locale.getCountry()); + zeroDigit = '0'; + groupingSeparator = (char)data.getGroupingSeparator(); + decimalSeparator = (char)data.getDecimalSeparator(); + perMill = (char)data.getPerMill(); + percent = (char)data.getPercent(); + digit = '#'; + patternSeparator = ';'; + NaN = data.getNaN(); + infinity = data.getInfinity(); + minusSign = (char)data.getMinusSign(); + monetaryDecimalSeparator = (char)data.getMonetaryDecimalSeparator(); + exponentSeparator = data.getExponentSeparator(); + } + + public static TLocale[] getAvailableLocales() { + return TLocale.getAvailableLocales(); + } + + public static final TDecimalFormatSymbols getInstance() { + return new TDecimalFormatSymbols(); + } + + public static final TDecimalFormatSymbols getInstance(TLocale locale) { + return new TDecimalFormatSymbols(locale); + } + + public char getZeroDigit() { + return zeroDigit; + } + + public void setZeroDigit(char zeroDigit) { + this.zeroDigit = zeroDigit; + } + + public char getGroupingSeparator() { + return groupingSeparator; + } + + public void setGroupingSeparator(char groupingSeparator) { + this.groupingSeparator = groupingSeparator; + } + + public char getPerMill() { + return perMill; + } + + public void setPerMill(char perMill) { + this.perMill = perMill; + } + + public char getPercent() { + return percent; + } + + public void setPercent(char percent) { + this.percent = percent; } public TLocale getLocale() { - return null; + return locale; } + public char getDecimalSeparator() { + return decimalSeparator; + } + + public void setDecimalSeparator(char decimalSeparator) { + this.decimalSeparator = decimalSeparator; + } + + public char getDigit() { + return digit; + } + + public void setDigit(char digit) { + this.digit = digit; + } + + public char getPatternSeparator() { + return patternSeparator; + } + + public void setPatternSeparator(char patternSeparator) { + this.patternSeparator = patternSeparator; + } + + public String getNaN() { + return NaN; + } + + public void setNaN(String naN) { + NaN = naN; + } + + public String getInfinity() { + return infinity; + } + + public void setInfinity(String infinity) { + this.infinity = infinity; + } + + public char getMinusSign() { + return minusSign; + } + + public void setMinusSign(char minusSign) { + this.minusSign = minusSign; + } + + public char getMonetaryDecimalSeparator() { + return monetaryDecimalSeparator; + } + + public void setMonetaryDecimalSeparator(char monetaryDecimalSeparator) { + this.monetaryDecimalSeparator = monetaryDecimalSeparator; + } + + public String getExponentSeparator() { + return exponentSeparator; + } + + public void setExponentSeparator(String exponentSeparator) { + this.exponentSeparator = exponentSeparator; + } + + public void setLocale(TLocale locale) { + this.locale = locale; + } + + @Override public Object clone() { - return null; + try { + return super.clone(); + } catch (CloneNotSupportedException e) { + throw new AssertionError("This exception should not been thrown", e); + } } }