import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
throw new IllegalArgumentException("Unhandled parser mode " + statementParserMode);
}
- for (final Entry<ValidationBundleType, Collection<?>> validationBundle : supportedValidation.entrySet()) {
- addToNs(ValidationBundlesNamespace.class, validationBundle.getKey(), validationBundle.getValue());
- }
+ addToNamespace(ValidationBundlesNamespace.class, supportedValidation);
this.supportedVersions = ImmutableSet.copyOf(supports.get(ModelProcessingPhase.INIT).getSupportedVersions());
}
}
void setSupportedFeatures(final Set<QName> supportedFeatures) {
- addToNs(SupportedFeaturesNamespace.class, SupportedFeatures.SUPPORTED_FEATURES,
+ addToNamespace(SupportedFeaturesNamespace.class, SupportedFeatures.SUPPORTED_FEATURES,
ImmutableSet.copyOf(supportedFeatures));
}
void setModulesDeviatedByModules(final SetMultimap<QNameModule, QNameModule> modulesDeviatedByModules) {
- addToNs(ModulesDeviatedByModules.class, SupportedModules.SUPPORTED_MODULES,
+ addToNamespace(ModulesDeviatedByModules.class, SupportedModules.SUPPORTED_MODULES,
ImmutableSetMultimap.copyOf(modulesDeviatedByModules));
}
import java.util.Map.Entry;
import java.util.Optional;
import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.NamespaceStorageNode;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.Registry;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceKeyCriterion;
// NOOP
}
- /**
- * Return a value associated with specified key within a namespace.
- *
- * @param type Namespace type
- * @param key Key
- * @param <K> namespace key type
- * @param <V> namespace value type
- * @param <N> namespace type
- * @param <T> key type
- * @return Value, or null if there is no element
- * @throws NamespaceNotAvailableException when the namespace is not available.
- */
- public final <K, V, T extends K, N extends IdentifierNamespace<K, V>> V getFromNamespace(final Class<N> type,
- final T key) {
- return getBehaviourRegistry().getNamespaceBehaviour(type).getFrom(this, key);
- }
-
public final <K, V, N extends IdentifierNamespace<K, V>> Optional<Entry<K, V>> getFromNamespace(
final Class<N> type, final NamespaceKeyCriterion<K> criterion) {
return getBehaviourRegistry().getNamespaceBehaviour(type).getFrom(this, criterion);
}
- public final <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromNamespace(final Class<N> type) {
+ public final <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getNamespace(final Class<N> type) {
return getBehaviourRegistry().getNamespaceBehaviour(type).getAllFrom(this);
}
@SuppressWarnings("unchecked")
- public final <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromCurrentStmtCtxNamespace(
- final Class<N> type) {
+ final <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getLocalNamespace(final Class<N> type) {
return (Map<K, V>) namespaces.get(type);
}
- /**
- * Associate a value with a key within a namespace.
- *
- * @param type Namespace type
- * @param key Key
- * @param value value
- * @param <K> namespace key type
- * @param <V> namespace value type
- * @param <N> namespace type
- * @param <T> key type
- * @param <U> value type
- * @throws NamespaceNotAvailableException when the namespace is not available.
- */
- public final <K, V, T extends K, U extends V, N extends IdentifierNamespace<K, V>> void addToNs(
+ final <K, V, T extends K, U extends V, N extends IdentifierNamespace<K, V>> void addToNamespace(
final Class<N> type, final T key, final U value) {
- getBehaviourRegistry().getNamespaceBehaviour(type).addTo(this,key,value);
+ getBehaviourRegistry().getNamespaceBehaviour(type).addTo(this, key, value);
+ }
+
+ final <K, V, T extends K, U extends V, N extends IdentifierNamespace<K, V>> void addToNamespace(
+ final Class<N> type, final Map<T, U> map) {
+ final NamespaceBehaviour<K, V, N> behavior = getBehaviourRegistry().getNamespaceBehaviour(type);
+ for (final Entry<T, U> validationBundle : map.entrySet()) {
+ behavior.addTo(this, validationBundle.getKey(), validationBundle.getValue());
+ }
}
/**
}
// We need to any and all extension statements which have been declared in the context
- final Map<QName, StatementSupport<?, ?, ?>> extensions = currentContext.getAllFromNamespace(
+ final Map<QName, StatementSupport<?, ?, ?>> extensions = currentContext.getNamespace(
StatementDefinitionNamespace.class);
if (extensions != null) {
extensions.forEach((qname, support) -> {
import java.util.EventListener;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.Registry;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceKeyCriterion;
+import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceNotAvailableException;
import org.opendaylight.yangtools.yang.parser.spi.meta.StatementNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
return getStatementSourceReference().getStatementSource();
}
+ @Override
+ public final <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromCurrentStmtCtxNamespace(
+ final Class<N> type) {
+ return getLocalNamespace(type);
+ }
+
+ @Override
+ public final <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromNamespace(final Class<N> type) {
+ return getNamespace(type);
+ }
+
+ /**
+ * Associate a value with a key within a namespace.
+ *
+ * @param type Namespace type
+ * @param key Key
+ * @param value value
+ * @param <K> namespace key type
+ * @param <V> namespace value type
+ * @param <N> namespace type
+ * @param <T> key type
+ * @param <U> value type
+ * @throws NamespaceNotAvailableException when the namespace is not available.
+ */
+ @Override
+ public final <K, V, T extends K, U extends V, N extends IdentifierNamespace<K, V>> void addToNs(
+ final Class<N> type, final T key, final U value) {
+ addToNamespace(type, key, value);
+ }
+
@Override
public abstract Collection<? extends StatementContextBase<?, ?, ?>> mutableDeclaredSubstatements();
+ /**
+ * Return a value associated with specified key within a namespace.
+ *
+ * @param type Namespace type
+ * @param key Key
+ * @param <K> namespace key type
+ * @param <V> namespace value type
+ * @param <N> namespace type
+ * @param <T> key type
+ * @return Value, or null if there is no element
+ * @throws NamespaceNotAvailableException when the namespace is not available.
+ */
+ @Override
+ public final <K, V, T extends K, N extends IdentifierNamespace<K, V>> V getFromNamespace(final Class<N> type,
+ final T key) {
+ return getBehaviourRegistry().getNamespaceBehaviour(type).getFrom(this, key);
+ }
+
@Override
public Collection<? extends Mutable<?, ?, ?>> mutableEffectiveSubstatements() {
if (effective instanceof ImmutableCollection) {