TimestampsParser { public static TimestampSet parseTimestampSet(String input, DateTimeZone timeZone) throws IllegalArgumentException { if (input == null) { return null; } if (input.equalsIgnoreCase(EMPTY_VALUE)) { return new TimestampSet(); } ArrayList<String> values = new ArrayList<String>(); try { StringReader reader = new StringReader(input + ' '); int r; char c; while ((r = reader.read()) != -1) { c = (char) r; switch (c) { case DYNAMIC_TYPE_LEFT_BOUND: case DYNAMIC_TYPE_RIGHT_BOUND: case RIGHT_BOUND_SQUARE_BRACKET: case RIGHT_BOUND_BRACKET: case LEFT_BOUND_BRACKET: case LEFT_BOUND_SQUARE_BRACKET: case ' ': case '\t': case '\r': case '\n': case COMMA: break; case '"': case '\'': values.add(FormattingAndParsingUtils.parseLiteral(reader, c)); break; default: reader.skip(-1); values.add(FormattingAndParsingUtils.parseValue(reader)); } } } catch (IOException ex) { throw new RuntimeException("Unexpected expection while parsing timestamps", ex); } TimestampSet result = new TimestampSet(values.size()); for (String value : values) { result.add(FormattingAndParsingUtils.parseDateTimeOrTimestamp(value, timeZone)); } return result; }  static TimestampSet parseTimestampSet(String input, DateTimeZone timeZone); static TimestampSet parseTimestampSet(String input); static TimestampMap<T> parseTimestampMap(Class<T> typeClass, String input, DateTimeZone timeZone); static TimestampMap<T> parseTimestampMap(Class<T> typeClass, String input);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testParseTimestampSetBadDateFormat1() { TimestampsParser.parseTimestampSet("[2015-13-01, 2015-01-31]"); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testParseTimestampSetBadDateFormat2() { TimestampsParser.parseTimestampSet("[2015-01-35, 2015-01-31]"); }
@Test public void testParseTimestampSet() throws ParseException { assertNull(TimestampsParser.parseTimestampSet(null)); assertEquals(new TimestampSet(), TimestampsParser.parseTimestampSet("[]")); assertEquals(buildTimestampSet(1), TimestampsParser.parseTimestampSet("[1]")); assertEquals(buildTimestampSet(1, 2), TimestampsParser.parseTimestampSet("[1, 2]")); assertEquals(buildTimestampSet(1, 2, 3), TimestampsParser.parseTimestampSet("<[1, 2, 3]>")); assertEquals(buildTimestampSet(1, 2, 31), TimestampsParser.parseTimestampSet("<[1, 2,31.]>")); assertEquals(buildTimestampSet(1, 2, 31), TimestampsParser.parseTimestampSet("<[1,2,31.0)")); assertEquals(buildTimestampSet(-5000, -1, 0, 0.5), TimestampsParser.parseTimestampSet("(-5000,-1, 0, .5)")); assertEquals(buildTimestampSet(-5000, -1, 0, 0.5), TimestampsParser.parseTimestampSet("(-5e3, -1, 0, .5)")); assertEquals(buildTimestampSet(parseDateIntoTimestamp("2015-01-01"), parseDateIntoTimestamp("2015-01-31")), TimestampsParser .parseTimestampSet("[2015-01-01, 2015-01-31]")); assertEquals(buildTimestampSet(parseDateIntoTimestamp("2015-01-01"), parseDateIntoTimestamp("2015-01-31")), TimestampsParser .parseTimestampSet("[2015-01, 2015-01-31]")); assertEquals(buildTimestampSet(parseDateTimeIntoTimestamp("2015-01-01 21:12:05"), parseDateTimeIntoTimestamp("2015-01-02 00:00:00")), TimestampsParser .parseTimestampSet("[2015-01-01T21:12:05, 2015-01-02]")); assertEquals(buildTimestampSet(parseDateTimeMillisIntoTimestamp("2015-01-01 21:12:05.121"), parseDateTimeMillisIntoTimestamp("2015-01-02 00:00:01.999")), TimestampsParser .parseTimestampSet("[2015-01-01T21:12:05.121, 2015-01-02T00:00:01.999]")); }