@SuppressWarnings("unchecked") @Test public void copyOfListenerRegistry() { assertNotNull(listenerRegistry); Map<String, ListenerRegistry.RegisteredListener<String, String>> listeners = getListeners(); when(listenerRegistry.getRegisteredListeners()).thenReturn(listeners); ListenerRegistry<String, String> copy = ListenerRegistries.copyOf(listenerRegistry, map -> { ListenerRegistry<String, String> registry = mock(ListenerRegistry.class); when(registry.getRegisteredListeners()).thenReturn(map); return registry; }); listeners.clear(); assertEquals(3, copy.getRegisteredListeners().size()); }
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); }
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); } }
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); }  }
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); }  static ListenerRegistry<I, F> copyOf(ListenerRegistry<I, F> registry,
                                                       Function<Map<I, ListenerRegistry.RegisteredListener<I, F>>, ListenerRegistry<I, F>> registryFactory); static ListenerRegistry.RegisteredListener<I, F> newImmutableRegisteredListener(I identifier, F listener,
                                                                                                  ImmutableListenerProvider<I, F> immutableListenerProvider); static ListenerRegistry.RegisteredListener<I, F> newImmutableRegisteredListener(ListenerRegistry.RegisteredListener<I, F> listener,
                                                                                                  ImmutableListenerProvider<I, F> immutableListenerProvider); static ListenerRegistry.RegisteredListener<I, F> newRegisteredListener(I id, F listener); static ListenerRegistry<I, F> newImmutableRegistry(ListenerRegistry<I, F> registry); }
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); }  static ListenerRegistry<I, F> copyOf(ListenerRegistry<I, F> registry,
                                                       Function<Map<I, ListenerRegistry.RegisteredListener<I, F>>, ListenerRegistry<I, F>> registryFactory); static ListenerRegistry.RegisteredListener<I, F> newImmutableRegisteredListener(I identifier, F listener,
                                                                                                  ImmutableListenerProvider<I, F> immutableListenerProvider); static ListenerRegistry.RegisteredListener<I, F> newImmutableRegisteredListener(ListenerRegistry.RegisteredListener<I, F> listener,
                                                                                                  ImmutableListenerProvider<I, F> immutableListenerProvider); static ListenerRegistry.RegisteredListener<I, F> newRegisteredListener(I id, F listener); static ListenerRegistry<I, F> newImmutableRegistry(ListenerRegistry<I, F> registry);  }