BucketMessageGroups implements MessageGroups<C> { @Override public boolean removeIf(Predicate<? super C> filter) { if (buckets != null && size > 0) { boolean removed = false; for (int bucket = 0; bucket < buckets.length; bucket++) { if (filter.test(buckets[bucket])) { remove(bucket); removed = true; } } return removed; } else { return false; } } BucketMessageGroups(int bucketCount); @Override void put(SimpleString key, C consumer); @Override C get(SimpleString key); @Override C remove(SimpleString key); @Override boolean removeIf(Predicate<? super C> filter); @Override void removeAll(); @Override int size(); @Override Map<SimpleString, C> toMap();  }
@Test public void testRemoveIf() { MessageGroups<String> messageGroups = new BucketMessageGroups<>(10); messageGroups.put(toGroupBucketIntKey(1), "world1"); messageGroups.put(toGroupBucketIntKey(2), "world2"); messageGroups.put(toGroupBucketIntKey(3), "world1"); messageGroups.put(toGroupBucketIntKey(4), "world2"); messageGroups.put(toGroupBucketIntKey(5), "world1"); messageGroups.put(toGroupBucketIntKey(6), "world2"); messageGroups.put(toGroupBucketIntKey(7), "world1"); messageGroups.put(toGroupBucketIntKey(8), "world2"); messageGroups.put(toGroupBucketIntKey(9), "world3"); messageGroups.put(toGroupBucketIntKey(10), "world4"); assertEquals(10, messageGroups.size()); messageGroups.removeIf("world1"::equals); assertEquals(6, messageGroups.size()); messageGroups.removeIf("world4"::equals); assertEquals(5, messageGroups.size()); messageGroups.removeIf("world3"::equals); assertEquals(4, messageGroups.size()); messageGroups.removeIf("world2"::equals); assertEquals(0, messageGroups.size()); }