List of usage examples for javax.swing.text MaskFormatter stringToValue
public Object stringToValue(String value) throws ParseException
value
. From source file:com.docdoku.core.util.Tools.java
public static String increaseId(String id, String mask) throws ParseException { LOGGER.info("#### Tools.increaseId id = " + id + " , mask = " + mask); MaskFormatter formatter = new MaskFormatter(mask); formatter.setValueContainsLiteralCharacters(false); String value = formatter.stringToValue(id).toString(); StringBuilder newValue = new StringBuilder(); boolean increase = true; for (int i = value.length() - 1; i >= 0; i--) { char c = value.charAt(i); switch (c) { case '9': newValue.append((increase) ? '0' : '9'); break; case '8': newValue.append((increase) ? '9' : '8'); increase = false;//from w w w. j ava 2s .com break; case '7': newValue.append((increase) ? '8' : '7'); increase = false; break; case '6': newValue.append((increase) ? '7' : '6'); increase = false; break; case '5': newValue.append((increase) ? '6' : '5'); increase = false; break; case '4': newValue.append((increase) ? '5' : '4'); increase = false; break; case '3': newValue.append((increase) ? '4' : '3'); increase = false; break; case '2': newValue.append((increase) ? '3' : '2'); increase = false; break; case '1': newValue.append((increase) ? '2' : '1'); increase = false; break; case '0': newValue.append((increase) ? '1' : '0'); increase = false; break; default: newValue.append(c); break; } } return formatter.valueToString(newValue.reverse().toString()); }