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));
}
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());
}
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) {
}
}
}
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());
}
}
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();
}
Aggregations