X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=concepts%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fconcepts%2Futil%2FListenerRegistry.java;h=e8f271c075360830e0fb3a5045ac0b47c0022956;hb=1d60202e38a86f14644a317e4dfaf0c01d8fda79;hp=458c54d806ce330c6116f3d75dd58d38b85f03bf;hpb=d8fd3315a670972425a89e5984e71678839c9749;p=yangtools.git diff --git a/concepts/src/main/java/org/opendaylight/yangtools/concepts/util/ListenerRegistry.java b/concepts/src/main/java/org/opendaylight/yangtools/concepts/util/ListenerRegistry.java index 458c54d806..e8f271c075 100644 --- a/concepts/src/main/java/org/opendaylight/yangtools/concepts/util/ListenerRegistry.java +++ b/concepts/src/main/java/org/opendaylight/yangtools/concepts/util/ListenerRegistry.java @@ -1,21 +1,33 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ package org.opendaylight.yangtools.concepts.util; + import java.util.Collections; import java.util.EventListener; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; - import org.opendaylight.yangtools.concepts.AbstractObjectRegistration; import org.opendaylight.yangtools.concepts.ListenerRegistration; + public class ListenerRegistry implements Iterable> { - final ConcurrentHashMap,ListenerRegistration> listeners; + private final ConcurrentHashMap,ListenerRegistration> listeners; final Set> unmodifiableView; + @SuppressWarnings("unchecked") public ListenerRegistry() { listeners = new ConcurrentHashMap<>(); - unmodifiableView = Collections.unmodifiableSet(listeners.keySet()); + // This conversion is known to be safe. + @SuppressWarnings("rawtypes") + final Set rawSet = Collections.unmodifiableSet(listeners.keySet()); + unmodifiableView = rawSet; } public Iterable> getListeners() { @@ -31,6 +43,12 @@ public class ListenerRegistry implements Iterable ListenerRegistration registerWithType(L listener) { + ListenerRegistrationImpl ret = new ListenerRegistrationImpl(listener); + listeners.put(ret,ret); + return ret; + } + @Override public java.util.Iterator> iterator() { return unmodifiableView.iterator(); @@ -54,4 +72,8 @@ public class ListenerRegistry implements Iterable ListenerRegistry create() { + return new ListenerRegistry<>(); + } }