@Override public Object parseObject(String text) throws ParseException { Objects.requireNonNull(text, "text"); try { if (parseType != null) { return formatter.parse(text, parseType); } return formatter.parseToBuilder(text); } catch (DateTimeParseException ex) { throw new ParseException(ex.getMessage(), ex.getErrorIndex()); } catch (RuntimeException ex) { throw (ParseException) new ParseException(ex.getMessage(), 0).initCause(ex); } }
@Override public Object parseObject(String text, ParsePosition pos) { Objects.requireNonNull(text, "text"); DateTimeBuilder builder; try { builder = formatter.parseToBuilder(text, pos); } catch (IndexOutOfBoundsException ex) { if (pos.getErrorIndex() < 0) { pos.setErrorIndex(0); } return null; } if (builder == null) { if (pos.getErrorIndex() < 0) { pos.setErrorIndex(0); } return null; } if (parseType == null) { return builder; } try { return builder.resolve().build(parseType); } catch (RuntimeException ex) { pos.setErrorIndex(0); return null; } }
@Override public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) { Objects.requireNonNull(obj, "obj"); Objects.requireNonNull(toAppendTo, "toAppendTo"); Objects.requireNonNull(pos, "pos"); if (obj instanceof DateTimeAccessor == false) { throw new IllegalArgumentException("Format target must implement DateTimeAccessor"); } pos.setBeginIndex(0); pos.setEndIndex(0); try { formatter.printTo((DateTimeAccessor) obj, toAppendTo); } catch (RuntimeException ex) { throw new IllegalArgumentException(ex.getMessage(), ex); } return toAppendTo; }