use of java.text.DecimalFormatSymbols in project robovm by robovm.
the class DecimalFormatSymbolsTest method testSerialization.
// http://code.google.com/p/android/issues/detail?id=14495
public void testSerialization() throws Exception {
DecimalFormatSymbols originalDfs = DecimalFormatSymbols.getInstance(Locale.GERMANY);
// Serialize...
ByteArrayOutputStream out = new ByteArrayOutputStream();
new ObjectOutputStream(out).writeObject(originalDfs);
byte[] bytes = out.toByteArray();
// Deserialize...
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes));
DecimalFormatSymbols deserializedDfs = (DecimalFormatSymbols) in.readObject();
assertEquals(-1, in.read());
// The two objects should claim to be equal.
assertEquals(originalDfs, deserializedDfs);
}
use of java.text.DecimalFormatSymbols in project robovm by robovm.
the class DecimalFormatTest method testSetZeroDigitForPattern.
public void testSetZeroDigitForPattern() {
DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols();
decimalFormatSymbols.setZeroDigit('a');
DecimalFormat formatter = new DecimalFormat();
formatter.setDecimalFormatSymbols(decimalFormatSymbols);
formatter.applyLocalizedPattern("#.aa");
assertEquals("e.fa", formatter.format(4.50));
}
use of java.text.DecimalFormatSymbols in project robovm by robovm.
the class DecimalFormatTest method testSetZeroDigitForFormatting.
public void testSetZeroDigitForFormatting() {
DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols();
decimalFormatSymbols.setZeroDigit('a');
DecimalFormat formatter = new DecimalFormat();
formatter.setDecimalFormatSymbols(decimalFormatSymbols);
formatter.applyLocalizedPattern("#");
assertEquals("eadacab", formatter.format(4030201));
}
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();
}
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));
}
Aggregations