class ListenerRegistries {

    public static <I, F> ListenerRegistry<I, F> copyOf(ListenerRegistry<I, F> registry,
                                                       Function<Map<I, ListenerRegistry.RegisteredListener<I, F>>, ListenerRegistry<I, F>> registryFactory) {
        Map<I, ListenerRegistry.RegisteredListener<I, F>> registeredListeners = registry.getRegisteredListeners();
        Map<I, ListenerRegistry.RegisteredListener<I, F>> copy = new HashMap<>();
        registeredListeners.forEach((name, register) -> copy.put(name, new SimpleRegisteredListener<>(register.getIdentifier(), register.getListener())));
        return registryFactory.apply(copy);

    }

}