Inline NamespaceStorageSupport.accessNamespaces() 56/104856/3
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 13 Mar 2023 18:26:21 +0000 (19:26 +0100)
committerRobert Varga <nite@hq.sk>
Mon, 13 Mar 2023 19:06:09 +0000 (19:06 +0000)
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>
parser/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/NamespaceStorageSupport.java

index 7d21fbf7c941c612f7fcc1c201a06d4f8d1803ab..caea2691819939982abccf37f12bd0da036d426e 100644 (file)
@@ -75,7 +75,8 @@ abstract class NamespaceStorageSupport implements NamespaceStorageNode {
 
     @SuppressWarnings("unchecked")
     final <K, V> Map<K, V> getLocalNamespace(final ParserNamespace<K, V> 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> void addToNamespace(final ParserNamespace<K, V> type, final T key,
@@ -105,18 +106,15 @@ abstract class NamespaceStorageSupport implements NamespaceStorageNode {
         getBehaviourRegistry().getNamespaceBehaviour(type).addTo(this, key, value);
     }
 
-    @SuppressWarnings("unchecked")
     @Override
     public <K, V> V getFromLocalStorage(final ParserNamespace<K, V> 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> Map<K, V> getAllFromLocalStorage(final ParserNamespace<K, V> type) {
-        @SuppressWarnings("unchecked")
-        final Map<K, V> localNamespace = (Map<K, V>) accessNamespaces().get(type);
-        return localNamespace;
+        return getLocalNamespace(type);
     }
 
     @Override
@@ -156,13 +154,8 @@ abstract class NamespaceStorageSupport implements NamespaceStorageNode {
         LOG.trace("Trimmed namespace storages of {} to {}", this, namespaces.keySet());
     }
 
-    private Map<ParserNamespace<?, ?>, Map<?, ?>> accessNamespaces() {
-        return verifyNotNull(namespaces, "Attempted to access swept namespaces of %s", this);
-    }
-
     private <K, V> Map<K, V> ensureLocalNamespace(final ParserNamespace<K, V> 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);