@Override public Object stringToValue(String text) throws ParseException { if (text != null) text = text.trim(); if ((text == null) || text.isEmpty()) { if (nullable) { return null; } else { throw new ParseException("Empty/null value is not allowed.", 0); } } long value; try { value = Long.parseLong(text); } catch (Exception e) { throw new ParseException("Parsing \"" + text + "\" to an integer value failed.", 0); } if ((value < minValue) || (value > maxValue)) { throw new ParseException( "Parsing \"" + text + "\" to an integer value in the range [" + minValue + ", " + maxValue + "] failed.", 0); } return value; }
@Override public Object convertAssignableToValidValue(Object value) { if (value == null) { return null; } try { if (value instanceof Number) { return ((Number) value).longValue(); } else { return Long.valueOf(value.toString()); } } catch (Exception e) { throw new RuntimeException("Invalid value"); } }
@Override public boolean isAssignableValue(Object value) { if (value == null) { return nullable; } try { long longValue; if (value instanceof Number) { longValue = ((Number) value).longValue(); } else { longValue = Long.valueOf(value.toString()); } return (minValue <= longValue) && (longValue <= maxValue); } catch (Exception e) { return false; } }