IntervalsParser { public static IntervalSet parseIntervalSet(String input, DateTimeZone timeZone) throws IllegalArgumentException { if (input == null) { return null; } if (input.equalsIgnoreCase(EMPTY_VALUE)) { return new IntervalSet(); } List<IntervalWithValue<Object>> intervals; try { intervals = parseIntervals(null, input, timeZone); } catch (IOException ex) { throw new RuntimeException("Unexpected expection while parsing intervals", ex); } IntervalSet result = new IntervalSet(intervals.size()); for (IntervalWithValue<Object> interval : intervals) { result.add(interval.getInterval()); } return result; }  static IntervalSet parseIntervalSet(String input, DateTimeZone timeZone); static IntervalSet parseIntervalSet(String input); static IntervalMap<T> parseIntervalMap(Class<T> typeClass, String input, DateTimeZone timeZone); static IntervalMap<T> parseIntervalMap(Class<T> typeClass, String input);  }
@Test public void testParseIntervalSet() throws ParseException { assertNull(IntervalsParser.parseIntervalSet(null)); assertEquals(buildIntervalSet(new Interval(1, 2)), IntervalsParser.parseIntervalSet("[1, 2]")); assertEquals(buildIntervalSet(new Interval(1, 2), new Interval(2, 3)), IntervalsParser.parseIntervalSet("<[1, 2]; [2,3]>")); assertEquals(buildIntervalSet(new Interval(1, 2), new Interval(2, 31)), IntervalsParser.parseIntervalSet("<[1, 2]; [2,31.]>")); assertEquals(buildIntervalSet(new Interval(1, 2), new Interval(2, 31)), IntervalsParser.parseIntervalSet("<[1, 2]; [2,31.0)")); assertEquals(buildIntervalSet(new Interval(-5000, -1), new Interval(0, 0.5)), IntervalsParser.parseIntervalSet("(-5000,-1][0, .5)")); assertEquals(buildIntervalSet(new Interval(-5000, -1), new Interval(0, 0.5)), IntervalsParser.parseIntervalSet("(-5e3,-1)(0, .5)")); assertEquals(buildIntervalSet(new Interval(parseDateIntoTimestamp("2015-01-01"), parseDateIntoTimestamp("2015-01-31"))), IntervalsParser.parseIntervalSet("[2015-01-01, 2015-01-31]")); assertEquals(buildIntervalSet(new Interval(parseDateIntoTimestamp("2015-01-01"), parseDateIntoTimestamp("2015-01-31"))), IntervalsParser.parseIntervalSet("[2015-01, 2015-01-31]")); assertEquals(buildIntervalSet(new Interval(parseDateTimeIntoTimestamp("2015-01-01 21:12:05"), parseDateTimeIntoTimestamp("2015-01-02 00:00:00"))), IntervalsParser.parseIntervalSet("[2015-01-01T21:12:05, 2015-01-02]")); assertEquals(buildIntervalSet(new Interval(parseDateTimeMillisIntoTimestamp("2015-01-01 21:12:05.121"), parseDateTimeMillisIntoTimestamp("2015-01-02 00:00:01.999"))), IntervalsParser.parseIntervalSet("[2015-01-01T21:12:05.121, 2015-01-02T00:00:01.999]")); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testParseIntervalSetBadEmpty1() { IntervalsParser.parseIntervalSet("[]"); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testParseIntervalSetBadEmpty2() { IntervalsParser.parseIntervalSet("[1]"); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testParseIntervalSetBadEmpty3() { IntervalsParser.parseIntervalSet("[1,]"); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testParseIntervalSetBadEmpty4() { IntervalsParser.parseIntervalSet(""); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testParseIntervalSetBadEmpty5() { IntervalsParser.parseIntervalSet("<>"); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testParseIntervalSetBadDateFormat1() { IntervalsParser.parseIntervalSet("[2015-13-01, 2015-01-31]"); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testParseIntervalSetBadDateFormat2() { IntervalsParser.parseIntervalSet("[2015-01-35, 2015-01-31]"); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testParseInfinityBadIntervalsOverlapping() { IntervalsParser.parseIntervalSet("[-Infinity, 0.0]; [-3.0, 1.0]"); }