RegexCollector extends AbstractCollector<String> { @Override public boolean add(String item) { if (!super.add(item)) return false; String itemKey = keyFor(item); if (itemKey == null) return false; Integer count = countsPerItem.get(itemKey); if (count == null) count = 0; countsPerItem.put(itemKey, count+1); return true; } RegexCollector(Predicate<String> aPredicate); void register(String id, String regex); @Override boolean add(String item); @Override Collection<String> all(); @Override int countsOf(String item); @Override void clear();  }
@Test public void add() { RegexCollector collector = new RegexCollector(null); collector.register("emails", RegexDescriptor.EMailAddress.regex); collector.add("brian@test.com"); collector.add("not an email.com"); collector.add("brian @test.com"); assertEquals(1, collector.countsOf("emails")); collector.clear(); assertEquals(0, collector.countsOf("emails")); }