Refactor IdentifierNamespace 05/95805/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 19 Apr 2021 08:12:07 +0000 (10:12 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 19 Apr 2021 08:15:39 +0000 (10:15 +0200)
IdentifierNamespace.get() is not used anywhere, hence remove this
method. Furthermore this class is only used for specifying a key, hence
make sure it is an abstract class without the possibility of
instantiating.

JIRA: YANGTOOLS-1205
Change-Id: I56f22af2d4bb21caab5dd47da6dfa1b1753777cd
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/meta/IdentifierNamespace.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/EffectiveStatementNamespace.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/ModuleEffectiveStatement.java

index d6d0f78f86937a9f4991767cbc33a62e61cbb443..91da55e65a2eb0513d13b25aff7704dbcb539e01 100644 (file)
@@ -7,26 +7,17 @@
  */
 package org.opendaylight.yangtools.yang.model.api.meta;
 
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.jdt.annotation.NonNullByDefault;
 
 /**
- * Model specific namespace which allows access to specific
- *
- * {@link IdentifierNamespace} serves as common superclass for YANG model namespaces, which are type-captured
- * subclasses. This type capture of namespace allows for handy type-safe reading methods such as
- * {@link EffectiveStatement#get(Class, Object)} and still allows introduction of new namespaces without need to change
- * model APIs.
+ * Common base class for various YANG statement namespaces.
  *
  * @param <K> Identifier type
  * @param <V> Value type
  */
-public interface IdentifierNamespace<K, V> {
-    /**
-     * Returns value associated with supplied identifier.
-     *
-     * @param identifier Identifier of value
-     * @return value or null, if identifier is not present in namespace.
-     */
-    @Nullable V get(@NonNull K identifier);
+@NonNullByDefault
+public abstract class IdentifierNamespace<K, V> {
+    protected IdentifierNamespace() {
+        throw new UnsupportedOperationException(getClass() + " should never be instantiated");
+    }
 }
index 188034b1447e6eaa83c48dc467b617d973737f23..9d8a67447f763cac209c2590be9bbd8c9deb5281 100644 (file)
@@ -21,9 +21,8 @@ import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
  */
 @Beta
 public abstract class EffectiveStatementNamespace<E extends NamespacedEffectiveStatement<?>>
-    implements IdentifierNamespace<QName, E> {
-
+        extends IdentifierNamespace<QName, E> {
     protected EffectiveStatementNamespace() {
-        // Subclasses should guard against instantiation
+        // Hidden on purpose
     }
 }
index e6028a7ca4498bffa67b4470ed654d01143eadf4..7df36936d9dcf122e00019867db214111acc32f7 100644 (file)
@@ -27,7 +27,7 @@ public interface ModuleEffectiveStatement
      * in which it is instantiated.
      */
     abstract class PrefixToEffectiveModuleNamespace
-            implements IdentifierNamespace<String, @NonNull ModuleEffectiveStatement> {
+            extends IdentifierNamespace<String, @NonNull ModuleEffectiveStatement> {
         private PrefixToEffectiveModuleNamespace() {
             // This class should never be subclassed
         }
@@ -37,7 +37,7 @@ public interface ModuleEffectiveStatement
      * Namespace mapping all known {@link QNameModule}s to their encoding prefixes. This includes the declaration
      * from prefix/namespace/revision and all imports as they were resolved.
      */
-    abstract class QNameModuleToPrefixNamespace implements IdentifierNamespace<QNameModule, @NonNull String> {
+    abstract class QNameModuleToPrefixNamespace extends IdentifierNamespace<QNameModule, @NonNull String> {
         private QNameModuleToPrefixNamespace() {
             // This class should never be subclassed
         }
@@ -47,7 +47,7 @@ public interface ModuleEffectiveStatement
      * Namespace mapping all included submodules. The namespaces is keyed by submodule name.
      */
     abstract class NameToEffectiveSubmoduleNamespace
-            implements IdentifierNamespace<String, @NonNull SubmoduleEffectiveStatement> {
+            extends IdentifierNamespace<String, @NonNull SubmoduleEffectiveStatement> {
         private NameToEffectiveSubmoduleNamespace() {
             // This class should never be subclassed
         }