TagListParser implements Parser<List<Tag>>, Combiner<Collection<Tag>> { @Override public List<Tag> parse(String t) { ArrayList<Tag> tags = new ArrayList<>(); String[] parts = t.split("(?<!\\\\),"); for (String p : parts) { if (!p.isEmpty()) { Tag tag = tagParser.parse(p); tag.setKey(tag.getKey().replaceAll("\\\\,", ",")); tag.setValue(tag.getValue().replaceAll("\\\\,", ",")); tags.add(tag); } } return tags; }  @Override List<Tag> parse(String t); @Override String combine(Collection<Tag> tags); String combine(Map<String, String> tags);  }
@Test public void testListParse() { String value = "tag1=value1,tag2=value2"; List<Tag> tags = new TagListParser().parse(value); Assert.assertEquals(2, tags.size()); Assert.assertEquals(new Tag("tag1", "value1"), tags.get(0)); Assert.assertEquals(new Tag("tag2", "value2"), tags.get(1)); }
@Test public void testParseTagsWithCommas() { try { String s = "tag1=value1,tag2=3.4.3_(default\\,_Date\\,_Time)_"; new TagListParser().parse(s); } catch (Exception e) { Assert.fail(e.getMessage()); } }