From: Robert Varga Date: Sat, 29 Feb 2020 10:30:28 +0000 (+0100) Subject: Add ListenerRegistry.clear() X-Git-Tag: v4.0.8~16 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=3ff7c30219041530941eceb69a7f1762ff9b982c;p=yangtools.git Add ListenerRegistry.clear() There are callers who mean to only clear the registry for which they are accessing the public view. Provide a method to do that and mark getRegistrations() as deprecated. Change-Id: I73b18443c505e7c7cea7efec627cc87196793d46 Signed-off-by: Robert Varga --- diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/ListenerRegistry.java b/common/util/src/main/java/org/opendaylight/yangtools/util/ListenerRegistry.java index 598b96d190..4c31cc5526 100644 --- a/common/util/src/main/java/org/opendaylight/yangtools/util/ListenerRegistry.java +++ b/common/util/src/main/java/org/opendaylight/yangtools/util/ListenerRegistry.java @@ -47,10 +47,15 @@ public final class ListenerRegistry implements Mutable return new ListenerRegistry<>(requireNonNull(name)); } + @Deprecated(forRemoval = true) public @NonNull Set> getRegistrations() { return unmodifiableView; } + public void clear() { + listeners.stream().forEach(ListenerRegistration::close); + } + public boolean isEmpty() { return listeners.isEmpty(); } @@ -59,7 +64,7 @@ public final class ListenerRegistry implements Mutable return listeners.stream().map(ListenerRegistration::getInstance); } - public @NonNull ListenerRegistration register(final L listener) { + public @NonNull ListenerRegistration register(final L listener) { final ListenerRegistration ret = new ListenerRegistrationImpl<>(listener, listeners::remove); listeners.add(ret); return ret; diff --git a/common/util/src/test/java/org/opendaylight/yangtools/util/ListenerRegistryTest.java b/common/util/src/test/java/org/opendaylight/yangtools/util/ListenerRegistryTest.java index d8b3f792de..6c156a1998 100644 --- a/common/util/src/test/java/org/opendaylight/yangtools/util/ListenerRegistryTest.java +++ b/common/util/src/test/java/org/opendaylight/yangtools/util/ListenerRegistryTest.java @@ -17,13 +17,11 @@ import org.junit.Test; import org.opendaylight.yangtools.concepts.ListenerRegistration; public class ListenerRegistryTest { - private TestEventListener testEventListener; private ExtendedTestEventListener extendedTestEventListener; private ListenerRegistry registry; @Before public void init() { - testEventListener = new TestEventListener() {}; extendedTestEventListener = new ExtendedTestEventListener() {}; registry = ListenerRegistry.create(); } @@ -34,7 +32,7 @@ public class ListenerRegistryTest { } @Test - public void tetGetListenersMethod() { + public void testGetListenersMethod() { assertEquals("Listener registry should have any listeners.", ImmutableSet.of(), registry.getRegistrations()); }