2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.parser.stmt.reactor;
10 import java.util.ArrayList;
11 import java.util.Collection;
12 import java.util.Iterator;
13 import java.util.List;
14 import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
15 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
17 final class SimpleNamespaceContext<K, V, N extends IdentifierNamespace<K, V>>
18 extends NamespaceBehaviourWithListeners<K, V, N> {
20 // FIXME: Change this to Multimap, once issue with modules is resolved.
21 private final List<KeyedValueAddedListener<K>> listeners = new ArrayList<>();
23 private final Collection<PredicateValueAddedListener<K, V>> predicateListeners = new ArrayList<>();
25 SimpleNamespaceContext(final NamespaceBehaviour<K, V, N> delegate) {
30 void addListener(final KeyedValueAddedListener<K> listener) {
31 listeners.add(listener);
35 void addListener(final PredicateValueAddedListener<K, V> listener) {
36 predicateListeners.add(listener);
40 public void addTo(final NamespaceStorageNode storage, final K key, final V value) {
41 delegate.addTo(storage, key, value);
42 notifyListeners(storage, listeners.iterator(), value);
44 final Iterator<PredicateValueAddedListener<K, V>> it = predicateListeners.iterator();
45 while (it.hasNext()) {
46 if (it.next().onValueAdded(key, value)) {
51 notifyDerivedNamespaces(storage, key, value);