TagSet implements Iterable<Tag> { TagSet addAll(Iterable<Tag> ts) { if (ts instanceof TagSet) { TagSet data = (TagSet) ts; return addAll(data.tags.values()); } Iterator<Tag> it = ts.iterator(); TreeMap<String, Tag> newTags = new TreeMap<String, Tag>(tags); while (it.hasNext()) { BasicTag tag = BasicTag.of(it.next()); newTags.put(tag.key(), tag); } return new TagSet(newTags); } TagSet(TreeMap<String, Tag> tags); @Override Iterator<Tag> iterator(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }
@Test public void testAddAll() { TagSet raw = new TagSet(new TreeMap<String, Tag>()); TagSet ts1 = raw.add(new BasicTag("k1", "k1")).addAll(new Tag[] {}) .addAll(new ArrayList<Tag>()).addAll(new HashMap<String, String>()); System.out.println(ts1); Assert.assertEquals("[k1=k1]", ts1.toString()); Tag tag1 = new BasicTag("k1", "v1"); Tag tag2 = new BasicTag("k2", "v2"); Tag tag3 = new BasicTag("k3", "v3"); Map<String, String> map = Maps.newTreeMap(); map.put("k3", "v33"); map.put("k4", "v4"); TagSet ts2 = raw.addAll(new Tag[] { tag1, tag2 }) .addAll(Lists.<Tag> newArrayList(tag2, tag3)).addAll(map); System.out.println(ts2.toString()); Assert.assertEquals("[k1=v1, k2=v2, k3=v33, k4=v4]", ts2.toString()); }