ListenerRegistries { public static <I, F> ListenerRegistry.RegisteredListener<I, F> newImmutableRegisteredListener(I identifier, F listener, ImmutableListenerProvider<I, F> immutableListenerProvider) { return new ImmutableRegisteredListener<>(identifier, listener, immutableListenerProvider); }  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);  }
@Test public void newImmutableListener() { MutableClass id = new MutableClass("id"); MutableClass listener = new MutableClass("listener"); ListenerRegistry.RegisteredListener<MutableClass, MutableClass> registeredListener = ListenerRegistries.newImmutableRegisteredListener(id, listener, new ListenerRegistries.ImmutableListenerProvider<MutableClass, MutableClass>() { @Override public MutableClass toImmutableIdentifier(MutableClass mutableClass) { return new MutableClass(mutableClass.a); } @Override public MutableClass toImmutableListener(MutableClass mutableClass) { return new MutableClass(mutableClass.a); } }); assertEquals("id", registeredListener.getIdentifier().a); assertEquals("listener", registeredListener.getListener().a); id.a = "changed"; listener.a = "changed"; assertEquals("id", registeredListener.getIdentifier().a); assertEquals("listener", registeredListener.getListener().a); }