One unreachable method removed in DigitList.
X-SVN-Rev: 39343
com/ibm/icu/text/CompactDecimalDataCache$FormatsTableKey#values:()[Lcom/ibm/icu/text/CompactDecimalDataCache$FormatsTableKey;
com/ibm/icu/text/CompactDecimalDataCache$PatternsTableKey#valueOf:(Ljava/lang/String;)Lcom/ibm/icu/text/CompactDecimalDataCache$PatternsTableKey;
com/ibm/icu/text/CompactDecimalDataCache$PatternsTableKey#values:()[Lcom/ibm/icu/text/CompactDecimalDataCache$PatternsTableKey;
-com/ibm/icu/text/CompactDecimalFormat#format:(Lcom/ibm/icu/math/BigDecimal;Ljava/lang/StringBuffer;Ljava/text/FieldPosition;)Ljava/lang/StringBuffer;
-com/ibm/icu/text/CompactDecimalFormat#format:(Ljava/math/BigDecimal;Ljava/lang/StringBuffer;Ljava/text/FieldPosition;)Ljava/lang/StringBuffer;
-com/ibm/icu/text/CompactDecimalFormat#format:(Ljava/math/BigInteger;Ljava/lang/StringBuffer;Ljava/text/FieldPosition;)Ljava/lang/StringBuffer;
-com/ibm/icu/text/CompactDecimalFormat#parse:(Ljava/lang/String;Ljava/text/ParsePosition;)Ljava/lang/Number;
-com/ibm/icu/text/CompactDecimalFormat#readObject:(Ljava/io/ObjectInputStream;)V
-com/ibm/icu/text/CompactDecimalFormat#recordError:(Ljava/util/Collection;Ljava/lang/String;)V
-com/ibm/icu/text/CompactDecimalFormat#writeObject:(Ljava/io/ObjectOutputStream;)V
com/ibm/icu/text/CompactDecimalFormat$CompactStyle#valueOf:(Ljava/lang/String;)Lcom/ibm/icu/text/CompactDecimalFormat$CompactStyle;
com/ibm/icu/text/ComposedCharIter#<init>:()V
com/ibm/icu/text/CurrencyDisplayNames#getInstance:(Ljava/util/Locale;)Lcom/ibm/icu/text/CurrencyDisplayNames;
com/ibm/icu/text/CurrencyFormat#clone:()Ljava/lang/Object;
com/ibm/icu/text/CurrencyFormat#readResolve:()Ljava/lang/Object;
-com/ibm/icu/text/CurrencyMetaInfo#currencies:(Lcom/ibm/icu/text/CurrencyMetaInfo$CurrencyFilter;)Ljava/util/List;
-com/ibm/icu/text/CurrencyMetaInfo#currencyDigits:(Ljava/lang/String;)Lcom/ibm/icu/text/CurrencyMetaInfo$CurrencyDigits;
-com/ibm/icu/text/CurrencyMetaInfo#currencyDigits:(Ljava/lang/String;Lcom/ibm/icu/util/Currency$CurrencyUsage;)Lcom/ibm/icu/text/CurrencyMetaInfo$CurrencyDigits;
com/ibm/icu/text/CurrencyMetaInfo#currencyInfo:(Lcom/ibm/icu/text/CurrencyMetaInfo$CurrencyFilter;)Ljava/util/List;
-com/ibm/icu/text/CurrencyMetaInfo#regions:(Lcom/ibm/icu/text/CurrencyMetaInfo$CurrencyFilter;)Ljava/util/List;
-com/ibm/icu/text/CurrencyMetaInfo$CurrencyFilter#onDate:(J)Lcom/ibm/icu/text/CurrencyMetaInfo$CurrencyFilter;
-com/ibm/icu/text/CurrencyMetaInfo$CurrencyFilter#onDateRange:(JJ)Lcom/ibm/icu/text/CurrencyMetaInfo$CurrencyFilter;
-com/ibm/icu/text/CurrencyMetaInfo$CurrencyFilter#onTender:()Lcom/ibm/icu/text/CurrencyMetaInfo$CurrencyFilter;
com/ibm/icu/text/CurrencyMetaInfo$CurrencyFilter#withDateRange:(JJ)Lcom/ibm/icu/text/CurrencyMetaInfo$CurrencyFilter;
-com/ibm/icu/text/CurrencyMetaInfo$CurrencyInfo#isTender:()Z
com/ibm/icu/text/CurrencyPluralInfo#hashCode:()I
com/ibm/icu/text/CurrencyPluralInfo#select:(D)Ljava/lang/String;
com/ibm/icu/text/DateFormat#hashCode:()I
com/ibm/icu/text/DecimalFormat$Unit#toString:()Ljava/lang/String;
com/ibm/icu/text/DictionaryBreakEngine$DequeI#grow:()V
com/ibm/icu/text/DictionaryData#<init>:()V
-com/ibm/icu/text/DigitList#equals:(Ljava/lang/Object;)Z
-com/ibm/icu/text/DigitList#getBigDecimal:(Z)Ljava/math/BigDecimal;
-com/ibm/icu/text/DigitList#hashCode:()I
-com/ibm/icu/text/DigitList#toString:()Ljava/lang/String;
com/ibm/icu/text/DisplayContext#valueOf:(Ljava/lang/String;)Lcom/ibm/icu/text/DisplayContext;
com/ibm/icu/text/DisplayContext$Type#valueOf:(Ljava/lang/String;)Lcom/ibm/icu/text/DisplayContext$Type;
com/ibm/icu/text/FractionalPartSubstitution#transformNumber:(J)J
return stringRep.toString();
}
- /**
- * Return a <code>BigDecimal</code> representing the value stored in this
- * <code>DigitList</code>.
- * [bnf]
- * @param isPositive determines the sign of the returned result
- * @return the value of this object as a <code>BigDecimal</code>
- */
- ///CLOVER:OFF
- // The method is in a protected class and is not called by anything
- public java.math.BigDecimal getBigDecimal(boolean isPositive) {
- if (isZero()) {
- return java.math.BigDecimal.valueOf(0);
- }
- // if exponential notion is negative,
- // we prefer to use BigDecimal constructor with scale,
- // because it works better when extremely small value
- // is used. See #5698.
- long scale = (long)count - (long)decimalAt;
- if (scale > 0) {
- int numDigits = count;
- if (scale > (long)Integer.MAX_VALUE) {
- // try to reduce the scale
- long numShift = scale - (long)Integer.MAX_VALUE;
- if (numShift < count) {
- numDigits -= numShift;
- } else {
- // fallback to 0
- return new java.math.BigDecimal(0);
- }
- }
- StringBuilder significantDigits = new StringBuilder(numDigits + 1);
- if (!isPositive) {
- significantDigits.append('-');
- }
- for (int i = 0; i < numDigits; i++) {
- significantDigits.append((char)digits[i]);
- }
- BigInteger unscaledVal = new BigInteger(significantDigits.toString());
- return new java.math.BigDecimal(unscaledVal, (int)scale);
- } else {
- // We should be able to use a negative scale value for a positive exponential
- // value on JDK1.5. But it is not supported by older JDK. So, for now,
- // we always use BigDecimal constructor which takes String.
- return new java.math.BigDecimal(getStringRep(isPositive));
- }
- }
- ///CLOVER:ON
-
/**
* Return an <code>ICU BigDecimal</code> representing the value stored in this
* <code>DigitList</code>.
//
// private static final double LOG10 = Math.log(10.0);
- // (The following boilerplate methods are currently not called,
- // and cannot be called by tests since this class is
- // package-private. The methods may be useful in the future, so
- // we do not delete them. 2003-06-11 ICU 2.6 Alan)
- ///CLOVER:OFF
/**
* equality test between two digit lists.
*/
buf.append(decimalAt);
return buf.toString();
}
- ///CLOVER:ON
}
*/
package com.ibm.icu.dev.test.format;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.NotSerializableException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.math.BigDecimal;
+import java.math.BigInteger;
import java.text.AttributedCharacterIterator;
import java.text.CharacterIterator;
import java.text.FieldPosition;
+import java.text.ParsePosition;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashSet;
1000000, 1000000, 1000000,
1000000000L, 1000000000L, 1000000000L,
1000000000000L, 1000000000000L, 1000000000000L};
+ long[] divisors_err = new long[] {
+ 0,0,0,
+ 13, 13, 13,
+ 1000000, 1000000, 1000000,
+ 1000000000L, 1000000000L, 1000000000L,
+ 1000000000000L, 1000000000000L, 1000000000000L};
checkCore(affixes, null, divisors, TestACoreCompactFormatList);
checkCore(affixes, currencyAffixes, divisors, TestACoreCompactFormatListCurrency);
+ try {
+ checkCore(affixes, null, divisors_err, TestACoreCompactFormatList);
+ } catch(AssertionError e) {
+ // Exception expected, thus return.
+ return;
+ }
+ fail("Error expected but passed");
}
private void checkCore(Map<String, String[][]> affixes, Map<String, String[]> currencyAffixes, long[] divisors, Object[][] testItems) {
}
+ @Test
+ public void TestBig() {
+ CompactDecimalFormat cdf = CompactDecimalFormat.getInstance(
+ ULocale.ENGLISH, CompactStyle.LONG);
+ BigInteger source_int = new BigInteger("31415926535897932384626433");
+ assertEquals("BigInteger format wrong: ", "31,000,000,000,000 trillion",
+ cdf.format(source_int));
+ BigDecimal source_dec = new BigDecimal(source_int);
+ assertEquals("BigDecimal format wrong: ", "31,000,000,000,000 trillion",
+ cdf.format(source_dec));
+ }
+
+ @Test
+ public void TestParsing() {
+ CompactDecimalFormat cdf = CompactDecimalFormat.getInstance(
+ ULocale.ENGLISH, CompactStyle.LONG);
+ try{
+ cdf.parse("Parse for failure", new ParsePosition(0));
+ } catch(UnsupportedOperationException e) {
+ // Exception expected, thus return.
+ return;
+ }
+ fail("Parsing currently unsupported, expected test to fail but passed");
+ }
+
public void checkLocale(ULocale locale, CompactStyle style, Object[][] testData) {
CompactDecimalFormat cdf = getCDFInstance(locale, style);
checkCdf(locale + " (" + locale.getDisplayName(locale) + ") for ", cdf, testData);
assertNotEquals("CDF(12,000) for no_NO shouldn't be 12 (12K or similar)", "12", result);
}
+ @Test
+ public void TestwriteObject() throws IOException {
+ FileOutputStream ba_stream = new FileOutputStream("tmp.ser");
+ ObjectOutputStream objoutstream = new ObjectOutputStream(ba_stream);
+ CompactDecimalFormat cdf = CompactDecimalFormat.getInstance(
+ ULocale.ENGLISH, CompactStyle.LONG);
+
+ try{
+ objoutstream.writeObject(cdf);
+ } catch (NotSerializableException e) {
+ // Exception expected, thus return.
+ objoutstream.close();
+ return;
+ }
+ objoutstream.close();
+ fail("writeObject currently unsupported, expected invokation to fail but passed");
+ }
+
+ @Test
+ public void TestReadObject() throws IOException, ClassNotFoundException {
+ FileInputStream fi_stream = new FileInputStream("tmp.ser");
+ ObjectInputStream objinstream = new ObjectInputStream(fi_stream);
+ CompactDecimalFormat cdf = CompactDecimalFormat.getInstance(
+ ULocale.ENGLISH, CompactStyle.LONG);
+
+ try{
+ CompactDecimalFormat cmpctDF = (CompactDecimalFormat) objinstream.readObject();
+ } catch (NotSerializableException e) {
+ // Exception expected, thus return.
+ objinstream.close();
+ return;
+ }
+ objinstream.close();
+ fail("readObject currently unsupported, expected invokation to fail but passed");
+ }
+
@Test
public void TestBug12422() {
CompactDecimalFormat cdf;
CurrencyFilter filter = CurrencyFilter.onRegion("DE"); // must be capitalized
List<CurrencyInfo> currenciesInGermany = metainfo.currencyInfo(filter);
- logln("currencies: " + currenciesInGermany.size());
+ CurrencyFilter filter_br = CurrencyFilter.onRegion("BR"); // must be capitalized
+ List<CurrencyInfo> currenciesInBrazil = metainfo.currencyInfo(filter_br);
+ logln("currencies Germany: " + currenciesInGermany.size());
+ logln("currencies Brazil: " + currenciesInBrazil.size());
+ long demFirstDate = Long.MIN_VALUE;
long demLastDate = Long.MAX_VALUE;
long eurFirstDate = Long.MIN_VALUE;
+ CurrencyInfo demInfo = null;
for (CurrencyInfo info : currenciesInGermany) {
logln(info.toString());
if (info.code.equals("DEM")) {
+ demInfo = info;
+ demFirstDate = info.from;
demLastDate = info.to;
} else if (info.code.equals("EUR")) {
eurFirstDate = info.from;
// but not one millisecond before the start of the first day
long eurFirstDateMinus1ms = eurFirstDate - 1;
- assertEquals("EUR not avilable before very start of first date", 1, metainfo.currencyInfo(filter.withDate(eurFirstDateMinus1ms)).size());
+ assertEquals("EUR not avilable before very start of first date", 1,
+ metainfo.currencyInfo(filter.withDate(eurFirstDateMinus1ms)).size());
+
+ // Deutschmark available from first millisecond on
+ assertEquals("Millisecond of DEM Big Bang", 1,
+ metainfo.currencyInfo(filter.onDate(demFirstDate).withRegion("DE")).size());
+
+ assertEquals("From Deutschmark to Euro", 2,
+ metainfo.currencyInfo(filter.onDateRange(demFirstDate, eurFirstDate).withRegion("DE")).size());
+
+ assertEquals("all Tender for Brazil", 7,
+ metainfo.currencyInfo(filter_br.onTender().withRegion("BR")).size());
+
+ assertTrue("No legal tender", demInfo.isTender());
}
@Test
new CurrencyMetaInfo.CurrencyInfo("region", "code", 0, 0, 1);
}
+ /**
+ * Class CurrencyMetaInfo has methods which are overwritten by its derived classes.
+ * A derived class is defined here for the purpose of testing these methods.
+ * Since the creator of CurrencyMetaInfo is defined as 'protected', no instance of
+ * this class can be created directly.
+ */
+ public class TestCurrencyMetaInfo extends CurrencyMetaInfo {
+ }
+
+ final TestCurrencyMetaInfo tcurrMetaInfo = new TestCurrencyMetaInfo();
+
+ /*
+ *
+ * Test methods of base class CurrencyMetaInfo. ICU4J only creates subclasses,
+ * never an instance of the base class.
+ */
+ @Test
+ public void TestCurrMetaInfoBaseClass() {
+ CurrencyFilter usFilter = CurrencyFilter.onRegion("US");
+
+ List<CurrencyInfo> listCurrInfo = tcurrMetaInfo.currencyInfo(usFilter);
+ assertEquals("Empty list expected", 0, tcurrMetaInfo.currencyInfo(usFilter).size());
+ assertEquals("Empty list expected", 0, tcurrMetaInfo.currencies(usFilter).size());
+ assertEquals("Empty list expected", 0, tcurrMetaInfo.regions(usFilter).size());
+
+ assertEquals("Iso format for digits expected",
+ "CurrencyDigits(fractionDigits='2',roundingIncrement='0')",
+ tcurrMetaInfo.currencyDigits("isoCode").toString());
+ }
+
/**
* Test cases for rounding and fractions.
*/
--- /dev/null
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html#License
+
+package com.ibm.icu.text;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.ibm.icu.dev.test.TestFmwk;
+import com.ibm.icu.dev.test.TestUtil;
+import com.ibm.icu.text.DigitList;
+import com.ibm.icu.text.NumberFormat;
+
+
+public class DigitListTest extends TestFmwk {
+
+ private static DigitList digitList = new DigitList();
+ private static long testdata = 1414213562;
+
+ @Before
+ public void init() {
+ digitList.set(testdata);
+ }
+
+ @Test
+ public void TestToString() {
+ String digitListStr = digitList.toString();
+ assertEquals("DigitList incorrect", "0.1414213562x10^10", digitListStr);
+ }
+ @Test
+ public void TestHashCode() {
+ int dlHashcode = digitList.hashCode();
+ assertEquals("DigitList hash code incorrect", -616183837, dlHashcode);
+ }
+
+ @Test
+ public void TestEquals() {
+ DigitList digitList2 = new DigitList();
+
+ // Test for success
+ digitList2.set(testdata);
+ assertTrue("DigitList objects with same values found unequal", digitList.equals(digitList2));
+ // Test for failure
+ digitList2.set(testdata+1);
+ assertFalse("DigitList objects with different values found equal", digitList.equals(digitList2));
+ }
+}