CounterGroup implements Iterable<Counter> { @Override public Iterator<Counter> iterator() { return counters.values().iterator(); } CounterGroup(String name); String getName(); CounterGroup addCounter(Counter counter); Counter getCounter(String name); @Override Iterator<Counter> iterator();  }
@Test public void testIterator() { CounterGroup cg = new CounterGroup("sqoop"); Counter c1 = new Counter("counter1"); Counter c2 = new Counter("counter2"); cg.addCounter(c1); cg.addCounter(c2); int count = 0; for (Counter c : cg) { count++; } Assert.assertEquals(2, count); Counter c3 = new Counter("counter3"); cg.addCounter(c3); count = 0; for (Counter c : cg) { count++; } Assert.assertEquals(3, count); }