Clean up NamespaceStorageSupport 59/105259/4
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 5 Apr 2023 15:54:35 +0000 (17:54 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 5 Apr 2023 20:48:41 +0000 (22:48 +0200)
We have:
- needlessly public methods
- missing explicit final marker
- single-caller methods

Clean all that up.

Change-Id: If0a9bb8fb60a39fc4520cb110188596771272141
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/BuildGlobalContext.java
parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/NamespaceStorageSupport.java
parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/ReactorStmtCtx.java
parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java

index 711917a55bba149f2e08cd8968d3f0a607e41d7a..d66cc0c31301beb791875bed39ffadf944fabea1 100644 (file)
@@ -93,7 +93,10 @@ final class BuildGlobalContext extends NamespaceStorageSupport implements Regist
             final ImmutableMap<ValidationBundleType, Collection<?>> supportedValidation) {
         this.supports = requireNonNull(supports, "BuildGlobalContext#supports cannot be null");
 
-        addToNamespace(ValidationBundles.NAMESPACE, supportedValidation);
+        final var behavior = getNamespaceBehaviour(ValidationBundles.NAMESPACE);
+        for (var validationBundle : supportedValidation.entrySet()) {
+            behavior.addTo(this, validationBundle.getKey(), validationBundle.getValue());
+        }
 
         supportedVersions = ImmutableSet.copyOf(
             verifyNotNull(supports.get(ModelProcessingPhase.INIT)).getSupportedVersions());
@@ -137,7 +140,7 @@ final class BuildGlobalContext extends NamespaceStorageSupport implements Regist
     }
 
     @Override
-    public NamespaceBehaviour.Registry getBehaviourRegistry() {
+    Registry getBehaviourRegistry() {
         return this;
     }
 
index caea2691819939982abccf37f12bd0da036d426e..acc2b05cbad842c227abe0c9b3176aa0cfabd3b2 100644 (file)
@@ -13,15 +13,10 @@ import com.google.common.collect.ImmutableMap;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Map.Entry;
-import java.util.Optional;
 import org.eclipse.jdt.annotation.NonNull;
-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;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceNotAvailableException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ParserNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -47,7 +42,7 @@ abstract class NamespaceStorageSupport implements NamespaceStorageNode {
      *
      * @return registry of source context
      */
-    public abstract @NonNull Registry getBehaviourRegistry();
+    abstract @NonNull Registry getBehaviourRegistry();
 
     // FIXME: 8.0.0: do we really need this method?
     final void checkLocalNamespaceAllowed(final ParserNamespace<?, ?> type) {
@@ -60,16 +55,11 @@ abstract class NamespaceStorageSupport implements NamespaceStorageNode {
      *
      * @throws SourceException instance of SourceException
      */
-    protected <K, V> void onNamespaceElementAdded(final ParserNamespace<K, V> type, final K key, final V value) {
+    <K, V> void onNamespaceElementAdded(final ParserNamespace<K, V> type, final K key, final V value) {
         // NOOP
     }
 
-    public final <K, V> Optional<Entry<K, V>> getFromNamespace(final ParserNamespace<K, V> type,
-            final NamespaceKeyCriterion<K> criterion) {
-        return getBehaviourRegistry().getNamespaceBehaviour(type).getFrom(this, criterion);
-    }
-
-    public final <K, V> Map<K, V> getNamespace(final ParserNamespace<K, V> type) {
+    final <K, V> Map<K, V> getNamespace(final ParserNamespace<K, V> type) {
         return getBehaviourRegistry().getNamespaceBehaviour(type).getAllFrom(this);
     }
 
@@ -84,28 +74,6 @@ abstract class NamespaceStorageSupport implements NamespaceStorageNode {
         getBehaviourRegistry().getNamespaceBehaviour(type).addTo(this, key, value);
     }
 
-    final <K, V, T extends K, U extends V> void addToNamespace(final ParserNamespace<K, V> type, final Map<T, U> map) {
-        final NamespaceBehaviour<K, V> behavior = getBehaviourRegistry().getNamespaceBehaviour(type);
-        for (final Entry<T, U> validationBundle : map.entrySet()) {
-            behavior.addTo(this, validationBundle.getKey(), validationBundle.getValue());
-        }
-    }
-
-    /**
-     * Associate a context with a key within a namespace.
-     *
-     * @param type Namespace type
-     * @param key Key
-     * @param value Context value
-     * @param <K> namespace key type
-     * @param <C> context type
-     * @throws NamespaceNotAvailableException when the namespace is not available.
-     */
-    public final <K, C extends StmtContext<?, ?, ?>> void addContextToNamespace(
-            final ParserNamespace<K, ? super C> type, final K key, final C value) {
-        getBehaviourRegistry().getNamespaceBehaviour(type).addTo(this, key, value);
-    }
-
     @Override
     public <K, V> V getFromLocalStorage(final ParserNamespace<K, V> type, final K key) {
         final var localNamespace = getLocalNamespace(type);
@@ -125,7 +93,7 @@ abstract class NamespaceStorageSupport implements NamespaceStorageNode {
     }
 
     @Override
-    public <K, V> V putToLocalStorageIfAbsent(final ParserNamespace<K, V> type, final K key, final V value) {
+    public final <K, V> V putToLocalStorageIfAbsent(final ParserNamespace<K, V> type, final K key, final V value) {
         final V ret = ensureLocalNamespace(type).putIfAbsent(key, value);
         if (ret == null) {
             onNamespaceElementAdded(type, key, value);
index 3140658a40fc4dab2cd5f2736327adcd195dbcb6..f4aaf31bc9d37cd19847d67bd5a6a7900133da0e 100644 (file)
@@ -188,7 +188,7 @@ abstract class ReactorStmtCtx<A, D extends DeclaredStatement<A>, E extends Effec
     public abstract Collection<? extends @NonNull StatementContextBase<?, ?, ?>> mutableDeclaredSubstatements();
 
     @Override
-    public final Registry getBehaviourRegistry() {
+    final Registry getBehaviourRegistry() {
         return getRoot().getBehaviourRegistryImpl();
     }
 
index b9aaaf70577634f9e79a7e1881966a40248576d8..3c350cd095e48e422e25e793bd4d0387db24a26c 100644 (file)
@@ -645,6 +645,11 @@ abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E extends
         listener.namespaceItemAdded(StatementContextBase.this, type, match.getKey(), match.getValue());
     }
 
+    private <K, V> Optional<Entry<K, V>> getFromNamespace(final ParserNamespace<K, V> type,
+            final NamespaceKeyCriterion<K> criterion) {
+        return getBehaviourRegistry().getNamespaceBehaviour(type).getFrom(this, criterion);
+    }
+
     final <K, V> void waitForPhase(final Object value, final ParserNamespace<K, V> type,
             final ModelProcessingPhase phase, final NamespaceKeyCriterion<K> criterion,
             final OnNamespaceItemAdded listener) {
@@ -719,7 +724,7 @@ abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E extends
     @Override
     public final <K, KT extends K, C extends StmtContext<?, ?, ?>> void addContext(
             final ParserNamespace<K, ? super C> namespace, final KT key, final C stmt) {
-        addContextToNamespace(namespace, key, stmt);
+        getBehaviourRegistry().getNamespaceBehaviour(namespace).addTo(this, key, stmt);
     }
 
     @Override