public static <T> Collection<ServiceNamespace> getAllNamespaces(Map<?, T> containers,
                                                                    Predicate<T> containerFilter,
                                                                    Function<T, ObjectNamespace> toNamespace) {
        if (MapUtil.isNullOrEmpty(containers)) {
            return Collections.emptySet();
        }

        Collection<ServiceNamespace> collection = Collections.emptySet();
        for (T container : containers.values()) {
            if (!containerFilter.test(container)) {
                continue;
            }

            ObjectNamespace namespace = toNamespace.apply(container);

            if (collection.isEmpty()) {
                collection = new HashSet<>(collection);
            }

            collection.add(namespace);
        }

        return collection;
    }
@Test
    public void testGetAllNamespaces_whenAllMatch() {
        Collection<ServiceNamespace> namespaces = NameSpaceUtil.getAllNamespaces(containers, container -> true,
                container -> new DistributedObjectNamespace(SERVICE_NAME, Integer.toString(container)));
        assertEquals(containers.size(), namespaces.size());
    }