List of usage examples for java.text NumberFormat formatToCharacterIterator
public AttributedCharacterIterator formatToCharacterIterator(Object obj)
AttributedCharacterIterator
. From source file:Main.java
private static Format createFormat() { NumberFormat format = NumberFormat.getInstance(); format.setParseIntegerOnly(true);//from w w w . j a v a 2 s.co m return new Format() { @Override public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) { return format.format(obj, toAppendTo, pos); } @Override public AttributedCharacterIterator formatToCharacterIterator(Object obj) { return format.formatToCharacterIterator(obj); } @Override public Object parseObject(String source, ParsePosition pos) { int initialIndex = pos.getIndex(); Object result = format.parseObject(source, pos); if (result != null && pos.getIndex() > initialIndex + 1) { int errorIndex = initialIndex + 1; pos.setIndex(initialIndex); pos.setErrorIndex(errorIndex); return null; } return result; } }; }