use of java.text.FieldPosition in project robovm by robovm.
the class NumberFormatTest method test_small_BigInteger_gets_longValue.
// NumberFormat.format(Object, StringBuffer, FieldPosition) guarantees it calls longValue for
// any BigInteger with a bitLength strictly less than 64.
public void test_small_BigInteger_gets_longValue() throws Exception {
class MyNumberFormat extends NumberFormat {
public StringBuffer format(double value, StringBuffer b, FieldPosition f) {
b.append("double");
return b;
}
public StringBuffer format(long value, StringBuffer b, FieldPosition f) {
b.append("long");
return b;
}
public Number parse(String string, ParsePosition p) {
throw new UnsupportedOperationException();
}
}
NumberFormat nf = new MyNumberFormat();
assertEquals("long", nf.format(BigInteger.valueOf(Long.MAX_VALUE)));
assertEquals("double", nf.format(BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE)));
assertEquals("long", nf.format(BigInteger.valueOf(Long.MIN_VALUE)));
assertEquals("double", nf.format(BigInteger.valueOf(Long.MIN_VALUE).subtract(BigInteger.ONE)));
}
use of java.text.FieldPosition in project dbeaver by serge-rider.
the class NumberDataFormatter method init.
@Override
public void init(Locale locale, Map<Object, Object> properties) {
numberFormat = (DecimalFormat) NumberFormat.getNumberInstance(locale);
Object useGrouping = properties.get(NumberFormatSample.PROP_USE_GROUPING);
if (useGrouping != null) {
numberFormat.setGroupingUsed(CommonUtils.toBoolean(useGrouping));
}
Object maxIntDigits = properties.get(NumberFormatSample.PROP_MAX_INT_DIGITS);
if (maxIntDigits != null) {
numberFormat.setMaximumIntegerDigits(CommonUtils.toInt(maxIntDigits));
}
Object minIntDigits = properties.get(NumberFormatSample.PROP_MIN_INT_DIGITS);
if (minIntDigits != null) {
numberFormat.setMinimumIntegerDigits(CommonUtils.toInt(minIntDigits));
}
Object maxFractDigits = properties.get(NumberFormatSample.PROP_MAX_FRACT_DIGITS);
if (maxFractDigits != null) {
numberFormat.setMaximumFractionDigits(CommonUtils.toInt(maxFractDigits));
}
Object minFractDigits = properties.get(NumberFormatSample.PROP_MIN_FRACT_DIGITS);
if (minFractDigits != null) {
numberFormat.setMinimumFractionDigits(CommonUtils.toInt(minFractDigits));
}
String roundingMode = CommonUtils.toString(properties.get(NumberFormatSample.PROP_ROUNDING_MODE));
if (!CommonUtils.isEmpty(roundingMode)) {
try {
numberFormat.setRoundingMode(RoundingMode.valueOf(roundingMode));
} catch (Exception e) {
// just skip it
}
}
buffer = new StringBuffer();
position = new FieldPosition(0);
}
use of java.text.FieldPosition in project j2objc by google.
the class NumberFormatTest method test_small_BigInteger_gets_longValue.
// NumberFormat.format(Object, StringBuffer, FieldPosition) guarantees it calls longValue for
// any BigInteger with a bitLength strictly less than 64.
public void test_small_BigInteger_gets_longValue() throws Exception {
class MyNumberFormat extends NumberFormat {
public StringBuffer format(double value, StringBuffer b, FieldPosition f) {
b.append("double");
return b;
}
public StringBuffer format(long value, StringBuffer b, FieldPosition f) {
b.append("long");
return b;
}
public Number parse(String string, ParsePosition p) {
throw new UnsupportedOperationException();
}
}
NumberFormat nf = new MyNumberFormat();
assertEquals("long", nf.format(BigInteger.valueOf(Long.MAX_VALUE)));
assertEquals("double", nf.format(BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE)));
assertEquals("long", nf.format(BigInteger.valueOf(Long.MIN_VALUE)));
assertEquals("double", nf.format(BigInteger.valueOf(Long.MIN_VALUE).subtract(BigInteger.ONE)));
}
use of java.text.FieldPosition in project j2objc by google.
the class DecimalFormatTest method testBug15081434.
// Check we don't crash on null inputs.
public void testBug15081434() throws Exception {
DecimalFormat df = (DecimalFormat) NumberFormat.getCurrencyInstance(Locale.US);
try {
df.parse(null);
fail();
} catch (NullPointerException expected) {
}
try {
df.applyLocalizedPattern(null);
fail();
} catch (NullPointerException expected) {
}
try {
df.applyPattern(null);
fail();
} catch (NullPointerException expected) {
}
try {
df.applyPattern(null);
fail();
} catch (NullPointerException expected) {
}
try {
df.format(null, new StringBuffer(), new FieldPosition(0));
fail();
// J2ObjC: Java docs actually specify that IAE is thrown for null input, not NPE.
} catch (IllegalArgumentException expected) {
}
try {
df.parse(null, new ParsePosition(0));
fail();
} catch (NullPointerException expected) {
}
// This just ignores null.
df.setDecimalFormatSymbols(null);
try {
df.setCurrency(null);
fail();
} catch (NullPointerException expected) {
}
// These just ignore null.
df.setNegativePrefix(null);
df.setNegativeSuffix(null);
df.setPositivePrefix(null);
df.setPositiveSuffix(null);
try {
df.setRoundingMode(null);
fail();
} catch (NullPointerException expected) {
}
}
use of java.text.FieldPosition in project j2objc by google.
the class Support_Format method t_FormatWithField.
protected void t_FormatWithField(int count, Format format, Object object, String text, Format.Field field, int begin, int end) {
StringBuffer buffer = new StringBuffer();
FieldPosition pos = new FieldPosition(field);
format.format(object, buffer, pos);
if (text == null) {
assertEquals("Test " + count + ": incorrect formatted text", this.text, buffer.toString());
} else {
assertEquals(text, buffer.toString());
}
if (begin != pos.getBeginIndex() || end != pos.getEndIndex()) {
assertEquals(field + " " + begin + ".." + end, pos.getFieldAttribute() + " " + pos.getBeginIndex() + ".." + pos.getEndIndex());
}
}
Aggregations