Inline NamespaceStorageSupport.accessNamespaces() 64/104864/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 13 Mar 2023 18:26:21 +0000 (19:26 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 13 Mar 2023 22:27:44 +0000 (23:27 +0100)
We have multiple callers, but all of duplicate the functionality
of getLocalNamespace(). Inline accessNamespaces() into
getLocalNamespace() and adjust users to use that instead duplicating its
code.

This removes a the need for a number of warning suppressions and makes
it clearer as to what is going on.

Change-Id: Ia210c6275b64093063eaf58a67412e94c3a29419
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 131816618ba0dd44880b58092fc062375f8d7389)
(cherry picked from commit 8e0305de53d206d852245682a3c26a5024b59fca)

parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/NamespaceStorageSupport.java

index 2a521e1907b6cfeddfc5bc0e5de017467567f690..0ceb9650306b33e322c546a789bdad54c8510f99 100644 (file)
@@ -77,7 +77,8 @@ abstract class NamespaceStorageSupport implements NamespaceStorageNode {
 
     @SuppressWarnings("unchecked")
     final <K, V, N extends ParserNamespace<K, V>> Map<K, V> getLocalNamespace(final Class<N> type) {
-        return (Map<K, V>) accessNamespaces().get(type);
+        final var local = verifyNotNull(namespaces, "Attempted to access swept namespaces of %s", this);
+        return (Map<K, V>) local.get(type);
     }
 
     final <K, V, T extends K, U extends V, N extends ParserNamespace<K, V>> void addToNamespace(
@@ -109,18 +110,15 @@ abstract class NamespaceStorageSupport implements NamespaceStorageNode {
         getBehaviourRegistry().getNamespaceBehaviour((Class)type).addTo(this, key, value);
     }
 
-    @SuppressWarnings("unchecked")
     @Override
     public <K, V, N extends ParserNamespace<K, V>> V getFromLocalStorage(final Class<N> type, final K key) {
-        final Map<K, V> localNamespace = (Map<K, V>) accessNamespaces().get(type);
+        final var localNamespace = getLocalNamespace(type);
         return localNamespace == null ? null : localNamespace.get(key);
     }
 
     @Override
     public <K, V, N extends ParserNamespace<K, V>> Map<K, V> getAllFromLocalStorage(final Class<N> type) {
-        @SuppressWarnings("unchecked")
-        final Map<K, V> localNamespace = (Map<K, V>) accessNamespaces().get(type);
-        return localNamespace;
+        return getLocalNamespace(type);
     }
 
     @Override
@@ -162,13 +160,8 @@ abstract class NamespaceStorageSupport implements NamespaceStorageNode {
         LOG.trace("Trimmed namespace storages of {} to {}", this, namespaces.keySet());
     }
 
-    private Map<Class<?>, Map<?, ?>> accessNamespaces() {
-        return verifyNotNull(namespaces, "Attempted to access swept namespaces of %s", this);
-    }
-
     private <K, V, N extends ParserNamespace<K, V>> Map<K, V> ensureLocalNamespace(final Class<N> type) {
-        @SuppressWarnings("unchecked")
-        Map<K, V> ret = (Map<K,V>) accessNamespaces().get(type);
+        var ret = getLocalNamespace(type);
         if (ret == null) {
             checkLocalNamespaceAllowed(type);
             ret = new HashMap<>(1);