Search in sources :

Example 6 with DecimalFormatSymbols

use of java.text.DecimalFormatSymbols in project robovm by robovm.

the class OldDecimalFormatSymbolsTest method test_clone.

public void test_clone() {
    // case 1: Compare of internal variables of cloned objects
    DecimalFormatSymbols fs = new DecimalFormatSymbols(Locale.US);
    DecimalFormatSymbols fsc = (DecimalFormatSymbols) fs.clone();
    assertEquals(fs.getCurrency(), fsc.getCurrency());
    // case 2: Compare of clones
    fs = new DecimalFormatSymbols();
    DecimalFormatSymbols fsc2 = (DecimalFormatSymbols) (fs.clone());
    // make sure the objects are equal
    assertTrue("Object's clone isn't equal!", fs.equals(fsc2));
    // case 3:
    // change the content of the clone and make sure it's not equal
    // anymore
    // verifies that it's data is now distinct from the original
    fs.setNaN("not-a-number");
    assertTrue("Object's changed clone should not be equal!", !fs.equals(fsc2));
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols)

Example 7 with DecimalFormatSymbols

use of java.text.DecimalFormatSymbols in project robovm by robovm.

the class OldDecimalFormatSymbolsTest method test_hashCode.

public void test_hashCode() {
    DecimalFormatSymbols dfs1 = new DecimalFormatSymbols();
    DecimalFormatSymbols dfs2 = (DecimalFormatSymbols) dfs1.clone();
    assertTrue("Hash codes of equal object are equal", dfs2.hashCode() == dfs1.hashCode());
    dfs1.setInfinity("infinity_infinity");
    assertTrue("Hash codes of non-equal objects are equal", dfs2.hashCode() != dfs1.hashCode());
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols)

Example 8 with DecimalFormatSymbols

use of java.text.DecimalFormatSymbols in project robovm by robovm.

the class OldDecimalFormatSymbolsTest method test_RIHarmony_compatible.

public void test_RIHarmony_compatible() throws Exception {
    ObjectInputStream i = null;
    try {
        DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.FRANCE);
        i = new ObjectInputStream(getClass().getClassLoader().getResourceAsStream("serialization/java/text/DecimalFormatSymbols.ser"));
        DecimalFormatSymbols riSymbols = (DecimalFormatSymbols) i.readObject();
        // RI's default NaN is U+FFFD, Harmony's is based on ICU
        // This suggests an RI bug, assuming that non-UTF8 bytes are UTF8 and
        // getting a conversion failure.
        riSymbols.setNaN("NaN");
        assertEquals(symbols, riSymbols);
    } catch (NullPointerException e) {
        assertNotNull("Failed to load /serialization/java/text/" + "DecimalFormatSymbols.ser", i);
    } finally {
        try {
            if (i != null) {
                i.close();
            }
        } catch (Exception e) {
        }
    }
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) ObjectInputStream(java.io.ObjectInputStream)

Example 9 with DecimalFormatSymbols

use of java.text.DecimalFormatSymbols in project robovm by robovm.

the class OldDecimalFormatTest method test_toLocalizedPattern.

public void test_toLocalizedPattern() {
    DecimalFormat format = new DecimalFormat();
    format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US));
    try {
        format.applyLocalizedPattern("#.#");
        assertEquals("Wrong pattern 1", "#0.#", format.toLocalizedPattern());
        format.applyLocalizedPattern("#.");
        assertEquals("Wrong pattern 2", "#0.", format.toLocalizedPattern());
        format.applyLocalizedPattern("#");
        assertEquals("Wrong pattern 3", "#", format.toLocalizedPattern());
        format.applyLocalizedPattern(".#");
        assertEquals("Wrong pattern 4", "#.0", format.toLocalizedPattern());
    } catch (Exception e) {
        fail("Unexpected exception " + e.toString());
    }
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) Support_DecimalFormat(tests.support.Support_DecimalFormat) DecimalFormat(java.text.DecimalFormat) ParseException(java.text.ParseException)

Example 10 with DecimalFormatSymbols

use of java.text.DecimalFormatSymbols in project robovm by robovm.

the class Scanner method removeLocaleInfo.

/*
     * Remove the locale specific prefixes, group separators, and locale
     * specific suffixes from input string
     */
private String removeLocaleInfo(String token, Class<?> type) {
    DecimalFormatSymbols dfs = decimalFormat.getDecimalFormatSymbols();
    StringBuilder tokenBuilder = new StringBuilder(token);
    boolean negative = removeLocaleSign(tokenBuilder);
    // Remove group separator
    String groupSeparator = String.valueOf(dfs.getGroupingSeparator());
    int separatorIndex = -1;
    while ((separatorIndex = tokenBuilder.indexOf(groupSeparator)) != -1) {
        tokenBuilder.delete(separatorIndex, separatorIndex + 1);
    }
    // Remove decimal separator
    String decimalSeparator = String.valueOf(dfs.getDecimalSeparator());
    separatorIndex = tokenBuilder.indexOf(decimalSeparator);
    StringBuilder result = new StringBuilder("");
    if (type == int.class) {
        for (int i = 0; i < tokenBuilder.length(); i++) {
            if (Character.digit(tokenBuilder.charAt(i), Character.MAX_RADIX) != -1) {
                result.append(tokenBuilder.charAt(i));
            }
        }
    } else if (type == float.class) {
        if (tokenBuilder.toString().equals(dfs.getNaN())) {
            result.append("NaN");
        } else if (tokenBuilder.toString().equals(dfs.getInfinity())) {
            result.append("Infinity");
        } else {
            for (int i = 0; i < tokenBuilder.length(); i++) {
                if (Character.digit(tokenBuilder.charAt(i), 10) != -1) {
                    result.append(Character.digit(tokenBuilder.charAt(i), 10));
                }
            }
        }
    } else {
        throw new AssertionError("Unsupported type: " + type);
    }
    // Token is NaN or Infinity
    if (result.length() == 0) {
        result = tokenBuilder;
    }
    if (separatorIndex != -1) {
        result.insert(separatorIndex, ".");
    }
    // If input is negative
    if (negative) {
        result.insert(0, '-');
    }
    return result.toString();
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols)

Aggregations

DecimalFormatSymbols (java.text.DecimalFormatSymbols)127 DecimalFormat (java.text.DecimalFormat)88 NumberFormat (java.text.NumberFormat)14 Locale (java.util.Locale)13 ParseException (java.text.ParseException)8 Currency (java.util.Currency)7 ObjectInputStream (java.io.ObjectInputStream)6 BigDecimal (java.math.BigDecimal)6 Test (org.junit.Test)6 IOException (java.io.IOException)5 ParsePosition (java.text.ParsePosition)5 BufferedChecksumIndexInput (org.apache.lucene.store.BufferedChecksumIndexInput)5 ChecksumIndexInput (org.apache.lucene.store.ChecksumIndexInput)5 IndexInput (org.apache.lucene.store.IndexInput)5 BytesRefBuilder (org.apache.lucene.util.BytesRefBuilder)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 ObjectOutputStream (java.io.ObjectOutputStream)4 BytesRef (org.apache.lucene.util.BytesRef)4 ArrayList (java.util.ArrayList)3