TimestampsParser { public static <T> TimestampMap<T> parseTimestampMap(Class<T> typeClass, String input, DateTimeZone timeZone) throws IllegalArgumentException { if (typeClass == null) { throw new IllegalArgumentException("typeClass required"); } if (input == null) { return null; } TimestampMap result; typeClass = AttributeUtils.getStandardizedType(typeClass); if (typeClass.equals(String.class)) { result = new TimestampStringMap(); } else if (typeClass.equals(Byte.class)) { result = new TimestampByteMap(); } else if (typeClass.equals(Short.class)) { result = new TimestampShortMap(); } else if (typeClass.equals(Integer.class)) { result = new TimestampIntegerMap(); } else if (typeClass.equals(Long.class)) { result = new TimestampLongMap(); } else if (typeClass.equals(Float.class)) { result = new TimestampFloatMap(); } else if (typeClass.equals(Double.class)) { result = new TimestampDoubleMap(); } else if (typeClass.equals(Boolean.class)) { result = new TimestampBooleanMap(); } else if (typeClass.equals(Character.class)) { result = new TimestampCharMap(); } else { throw new IllegalArgumentException("Unsupported type " + typeClass.getClass().getCanonicalName()); } if (input.equalsIgnoreCase(EMPTY_VALUE)) { return result; } StringReader reader = new StringReader(input + ' '); try { int r; char c; while ((r = reader.read()) != -1) { c = (char) r; switch (c) { case LEFT_BOUND_SQUARE_BRACKET: case LEFT_BOUND_BRACKET: parseTimestampAndValue(typeClass, reader, result, timeZone); break; default: } } } catch (IOException ex) { throw new RuntimeException("Unexpected expection while parsing timestamps", ex); } 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 public void testParseTimestampMapString() { TimestampStringMap expected = new TimestampStringMap(); expected.put(1.0, "Value1"); expected.put(3.0, "Value2"); expected.put(5.0, "Value 3"); expected.put(6.0, " Value 4 "); assertEqualTimestampMaps(expected, TimestampsParser.parseTimestampMap(String.class, "[1, Value1]; [3, 'Value2']; [5, Value 3]; [6, \" Value 4 \"]")); }
@Test public void testParseTimestampMapByte() { TimestampByteMap expected = new TimestampByteMap(); expected.put(1.0, (byte) 1); expected.put(3.0, (byte) 2); expected.put(6.0, (byte) 3); expected.put(7.0, (byte) 4); assertEqualTimestampMaps(expected, TimestampsParser.parseTimestampMap(Byte.class, "[1, 1]; [3, 2]; [6, '3']; [7, \"4\"]")); assertEqualTimestampMaps(expected, TimestampsParser.parseTimestampMap(byte.class, "[1, 1]; [3, 2]; [6, '3']; [7, \"4\"]")); }
@Test public void testParseTimestampMapShort() { TimestampShortMap expected = new TimestampShortMap(); expected.put(1.0, (short) 1); expected.put(3.0, (short) 2); expected.put(5.0, (short) 3); expected.put(6.0, (short) 4); assertEqualTimestampMaps(expected, TimestampsParser.parseTimestampMap(Short.class, "[1, 1]; [3, 2]; [5, '3']; [6, \"4\"]")); assertEqualTimestampMaps(expected, TimestampsParser.parseTimestampMap(short.class, "[1, 1]; [3, 2]; [5, '3']; [6, \"4\"]")); }
@Test public void testParseTimestampMapInteger() { TimestampIntegerMap expected = new TimestampIntegerMap(); expected.put(1.0, 1); expected.put(3.0, 2); expected.put(5.0, 3); expected.put(6.0, 4); assertEqualTimestampMaps(expected, TimestampsParser.parseTimestampMap(Integer.class, "[1, 1]; [3, 2]; [5, '3']; [6, \"4\"]")); assertEqualTimestampMaps(expected, TimestampsParser.parseTimestampMap(int.class, "[1, 1]; [3, 2]; [5, '3']; [6, \"4\"]")); }
@Test public void testParseTimestampMapLong() { TimestampLongMap expected = new TimestampLongMap(); expected.put(1.0, 1l); expected.put(3.0, 2l); expected.put(5.0, 3l); expected.put(6.0, 4l); assertEqualTimestampMaps(expected, TimestampsParser.parseTimestampMap(Long.class, "[1, 1]; [3, 2]; [5, '3']; [6, \"4\"]")); assertEqualTimestampMaps(expected, TimestampsParser.parseTimestampMap(long.class, "[1, 1]; [3, 2]; [5, '3']; [6, \"4\"]")); }
@Test public void testParseTimestampMapFloat() { TimestampFloatMap expected = new TimestampFloatMap(); expected.put(1.0, 1f); expected.put(3.0, 2f); expected.put(5.0, 3f); expected.put(6.0, 4f); assertEqualTimestampMaps(expected, TimestampsParser.parseTimestampMap(Float.class, "[1, 1]; [3, 2]; [5, '3']; [6, \"4\"]")); assertEqualTimestampMaps(expected, TimestampsParser.parseTimestampMap(float.class, "[1, 1]; [3, 2]; [5, '3']; [6, \"4\"]")); }
@Test public void testParseTimestampMapDouble() { TimestampDoubleMap expected = new TimestampDoubleMap(); expected.put(1.0, 1d); expected.put(3.0, 2d); expected.put(5.0, 3d); expected.put(6.0, 4d); assertEqualTimestampMaps(expected, TimestampsParser.parseTimestampMap(Double.class, "[1, 1]; [3, 2]; [5, '3']; [6, \"4\"]")); assertEqualTimestampMaps(expected, TimestampsParser.parseTimestampMap(double.class, "[1, 1]; [3, 2]; [5, '3']; [6, \"4\"]")); }
@Test public void testParseTimestampMapBoolean() { TimestampBooleanMap expected = new TimestampBooleanMap(); expected.put(1.0, true); expected.put(3.0, false); expected.put(5.0, false); expected.put(6.0, true); assertEqualTimestampMaps(expected, TimestampsParser.parseTimestampMap(Boolean.class, "[1, true]; [3, false]; [5, '0']; [6, \"1\"]")); assertEqualTimestampMaps(expected, TimestampsParser.parseTimestampMap(boolean.class, "[1, true]; [3, false]; [5, '0']; [6, \"1\"]")); }
@Test public void testParseTimestampMapChar() { TimestampCharMap expected = new TimestampCharMap(); expected.put(1.0, 'a'); expected.put(3.0, 'b'); expected.put(5.0, 'c'); expected.put(6.0, 'd'); assertEqualTimestampMaps(expected, TimestampsParser.parseTimestampMap(Character.class, "[1, a]; [3, b]; [5, 'c']; [6, \"d\"]")); assertEqualTimestampMaps(expected, TimestampsParser.parseTimestampMap(char.class, "[1, a]; [3, b]; [5, 'c']; [6, \"d\"]")); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testParseTimestampMapByteBadFormat() { TimestampsParser.parseTimestampMap(Byte.class, "[1, a]"); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testParseTimestampMapShortBadFormat() { TimestampsParser.parseTimestampMap(Short.class, "[1, a]"); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testParseTimestampMapIntegerBadFormat() { TimestampsParser.parseTimestampMap(Integer.class, "[1, a]"); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testParseTimestampMapLongBadFormat() { TimestampsParser.parseTimestampMap(Long.class, "[1, a]"); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testParseTimestampMapFloatBadFormat() { TimestampsParser.parseTimestampMap(Float.class, "[1, 1..4]"); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testParseTimestampMapDoubleBadFormat() { TimestampsParser.parseTimestampMap(Double.class, "[1, 4oe]"); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testParseTimestampMapCharBadFormat() { TimestampsParser.parseTimestampMap(Character.class, "[1, abc]"); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testParseTimestampUnsupportedType() { TimestampsParser.parseTimestampMap(Date.class, "[1, 1]; [3, 2]; [5, '3']; [6, \"4\"]"); }