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 jgnash by ccavanaugh.
the class DefaultCurrencies method buildNode.
/**
* Creates a valid CurrencyNode given a locale.
*
* @param locale Locale to create a CurrencyNode for
* @return The new CurrencyNode
*/
public static CurrencyNode buildNode(final Locale locale) {
DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale);
Currency c = symbols.getCurrency();
CurrencyNode node = new CurrencyNode();
node.setSymbol(c.getCurrencyCode());
node.setPrefix(symbols.getCurrencySymbol());
node.setScale((byte) c.getDefaultFractionDigits());
return node;
}
use of java.text.DecimalFormatSymbols in project jgnash by ccavanaugh.
the class CommodityFormat method getFullNumberFormat.
/**
* Returns a thread safe {@code NumberFormat} for a given {@code CommodityNode}.
*
* @param node CommodityNode to format to
* @return thread safe {@code NumberFormat}
*/
public static NumberFormat getFullNumberFormat(@NotNull final CommodityNode node) {
final ThreadLocal<DecimalFormat> o = fullInstanceMap.get(node);
if (o != null) {
return o.get();
}
final ThreadLocal<DecimalFormat> threadLocal = ThreadLocal.withInitial(() -> {
final DecimalFormat df = (DecimalFormat) NumberFormat.getCurrencyInstance();
final DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();
dfs.setCurrencySymbol(node.getPrefix());
df.setDecimalFormatSymbols(dfs);
df.setMaximumFractionDigits(node.getScale());
// required for some locale
df.setMinimumFractionDigits(df.getMaximumFractionDigits());
if (node.getSuffix() != null && !node.getSuffix().isEmpty()) {
df.setPositiveSuffix(node.getSuffix() + df.getPositiveSuffix());
df.setNegativeSuffix(node.getSuffix() + df.getNegativeSuffix());
}
// for positive suffix padding for fraction alignment
final int negSufLen = df.getNegativeSuffix().length();
final int posSufLen = df.getPositiveSuffix().length();
if (negSufLen > posSufLen) {
StringBuilder buf = new StringBuilder(df.getPositiveSuffix());
for (int i = negSufLen - posSufLen; i <= negSufLen; i++) {
buf.append(' ');
}
df.setPositiveSuffix(buf.toString());
} else if (posSufLen > negSufLen) {
StringBuilder buf = new StringBuilder(df.getNegativeSuffix());
for (int i = posSufLen - negSufLen; i <= posSufLen; i++) {
buf.append(' ');
}
df.setNegativeSuffix(buf.toString());
}
return df;
});
fullInstanceMap.put(node, threadLocal);
return threadLocal.get();
}
Aggregations