TagListParser implements Parser<List<Tag>>, Combiner<Collection<Tag>> { @Override public String combine(Collection<Tag> tags) { StringBuilder builder = new StringBuilder(); if (!tags.isEmpty()) { tags.forEach(p -> builder.append(tagParser.combine(p)).append(',')); builder.setLength(builder.length() - 1); } return builder.toString(); }  @Override List<Tag> parse(String t); @Override String combine(Collection<Tag> tags); String combine(Map<String, String> tags);  }
@Test public void testListCombine() { List<Tag> tags = new ArrayList<>(); tags.add(new Tag("tag1", "value1")); tags.add(new Tag("tag2", "value2")); String combined = new TagListParser().combine(tags); Assert.assertEquals("tag1=value1,tag2=value2", combined); }
@Test public void testListCombineMap() { Map<String, String> map = new TreeMap<>(); map.put("tag1", "value1"); map.put("tag2", "value2"); String combined = new TagListParser().combine(map); Assert.assertEquals("tag1=value1,tag2=value2", combined); }