Remove ListenerRegistry.getRegistrations() 53/88153/1
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 29 Feb 2020 10:44:17 +0000 (11:44 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sat, 29 Feb 2020 10:44:17 +0000 (11:44 +0100)
Disconnect the class from Collection API, so that its footprint
is reduced. It also makes it clear that registrations are just
a pass-through API.

Change-Id: I7a301dfa636376fba464b396680e2600bbf3951b
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
common/util/src/main/java/org/opendaylight/yangtools/util/ListenerRegistry.java
common/util/src/test/java/org/opendaylight/yangtools/util/ListenerRegistryTest.java

index 4c31cc55268959ce8f4e4e5646cd3c0f46724a8b..f6a3800c990bcd2b34cc13bd98ef340628d358f5 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.yangtools.util;
 import static java.util.Objects.requireNonNull;
 
 import com.google.common.base.MoreObjects;
-import java.util.Collections;
 import java.util.EventListener;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
@@ -27,12 +26,7 @@ import org.opendaylight.yangtools.concepts.Mutable;
  * @param <T> Type of listeners this registry handles
  */
 public final class ListenerRegistry<T extends EventListener> implements Mutable {
-
     private final Set<ListenerRegistration<? extends T>> listeners = ConcurrentHashMap.newKeySet();
-    // This conversion is known to be safe.
-    @SuppressWarnings({ "rawtypes", "unchecked" })
-    private final Set<ListenerRegistration<T>> unmodifiableView = (Set) Collections.unmodifiableSet(listeners);
-
     private final String name;
 
     private ListenerRegistry(final String name) {
@@ -47,11 +41,6 @@ public final class ListenerRegistry<T extends EventListener> implements Mutable
         return new ListenerRegistry<>(requireNonNull(name));
     }
 
-    @Deprecated(forRemoval = true)
-    public @NonNull Set<? extends ListenerRegistration<? extends T>> getRegistrations() {
-        return unmodifiableView;
-    }
-
     public void clear() {
         listeners.stream().forEach(ListenerRegistration::close);
     }
index 6c156a1998a59bc50a4545e69bf13e4a4d9fceb7..91a9b261bc7e06978f11f07168eb86183f1ea013 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.yangtools.util;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
-import com.google.common.collect.ImmutableSet;
 import java.util.EventListener;
 import org.junit.Before;
 import org.junit.Test;
@@ -33,7 +32,7 @@ public class ListenerRegistryTest {
 
     @Test
     public void testGetListenersMethod() {
-        assertEquals("Listener registry should have any listeners.", ImmutableSet.of(), registry.getRegistrations());
+        assertEquals("Listener registry should not have any listeners.", 0, registry.streamListeners().count());
     }
 
     @Test