Migrate RFC references to rfc-editor.org
[yangtools.git] / model / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / api / stmt / SchemaNodeIdentifier.java
index 5c74fdc9aebde7574ab5017505d0b9e6389d2e31..7439f4c50aba6434cf7cf5d1e3ecdf5ec3cc6a6f 100644 (file)
@@ -14,32 +14,25 @@ import com.google.common.base.MoreObjects;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Interner;
 import com.google.common.collect.Interners;
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
-import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.concepts.Immutable;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 
 /**
  * Represents unique path to every schema node inside the schema node identifier namespace. This concept is defined
- * in <a href="https://tools.ietf.org/html/rfc7950#section-6.5">RFC7950</a>.
+ * in <a href="https://www.rfc-editor.org/rfc/rfc7950#section-6.5">RFC7950</a>.
  */
-public abstract class SchemaNodeIdentifier implements Immutable {
+public abstract sealed class SchemaNodeIdentifier implements Immutable {
     /**
      * An absolute schema node identifier.
      */
-    public abstract static class Absolute extends SchemaNodeIdentifier {
-        private static final Interner<Absolute> INTERNER = Interners.newWeakInterner();
-
-        Absolute() {
-            // Hidden on purpose
-        }
+    public abstract static sealed class Absolute extends SchemaNodeIdentifier {
+        private static final Interner<@NonNull Absolute> INTERNER = Interners.newWeakInterner();
 
         /**
          * Create an absolute schema node identifier composed of a single node identifier.
@@ -73,7 +66,7 @@ public abstract class SchemaNodeIdentifier implements Immutable {
          * @throws IllegalArgumentException if {@code nodeIdentifiers} is empty
          */
         public static @NonNull Absolute of(final Collection<QName> nodeIdentifiers) {
-            final ImmutableList<QName> qnames = checkQNames(nodeIdentifiers);
+            final var qnames = checkQNames(nodeIdentifiers);
             return qnames.size() == 1 ? of(qnames.get(0)) : new AbsoluteMultiple(qnames);
         }
 
@@ -86,12 +79,6 @@ public abstract class SchemaNodeIdentifier implements Immutable {
             return INTERNER.intern(this);
         }
 
-        @Override
-        @Deprecated(since = "7.0.9", forRemoval = true)
-        final SchemaPath implicitSchemaPathParent() {
-            return SchemaPath.ROOT;
-        }
-
         @Override
         final String className() {
             return "Absolute";
@@ -101,11 +88,7 @@ public abstract class SchemaNodeIdentifier implements Immutable {
     /**
      * A descendant schema node identifier.
      */
-    public abstract static class Descendant extends SchemaNodeIdentifier {
-        Descendant() {
-            // Hidden on purpose
-        }
-
+    public abstract static sealed class Descendant extends SchemaNodeIdentifier {
         /**
          * Create a descendant schema node identifier composed of a single node identifier.
          *
@@ -138,16 +121,10 @@ public abstract class SchemaNodeIdentifier implements Immutable {
          * @throws IllegalArgumentException if {@code nodeIdentifiers} is empty
          */
         public static @NonNull Descendant of(final Collection<QName> nodeIdentifiers) {
-            final ImmutableList<QName> qnames = checkQNames(nodeIdentifiers);
+            final var qnames = checkQNames(nodeIdentifiers);
             return qnames.size() == 1 ? of(qnames.get(0)) : new DescandantMultiple(qnames);
         }
 
-        @Override
-        @Deprecated(since = "7.0.9", forRemoval = true)
-        final SchemaPath implicitSchemaPathParent() {
-            return SchemaPath.SAME;
-        }
-
         @Override
         final String className() {
             return "Descendant";
@@ -246,20 +223,9 @@ public abstract class SchemaNodeIdentifier implements Immutable {
         }
     }
 
-    @Deprecated(since = "7.0.9", forRemoval = true)
-    private static final AtomicReferenceFieldUpdater<SchemaNodeIdentifier, SchemaPath> SCHEMAPATH_UPDATER =
-            AtomicReferenceFieldUpdater.newUpdater(SchemaNodeIdentifier.class, SchemaPath.class, "schemaPath");
-
-    // Cached SchemaPath.
-    @Deprecated(since = "7.0.9", forRemoval = true)
-    private volatile SchemaPath schemaPath;
     // Cached hashCode
     private volatile int hash;
 
-    SchemaNodeIdentifier() {
-        // Hidden on purpose
-    }
-
     /**
      * Return the non-empty sequence of node identifiers which constitute this schema node identifier.
      *
@@ -284,25 +250,10 @@ public abstract class SchemaNodeIdentifier implements Immutable {
      * @return The last node identifier
      */
     public @NonNull QName lastNodeIdentifier() {
-        final List<QName> local = getNodeIdentifiers();
+        final var local = getNodeIdentifiers();
         return local.get(local.size() - 1);
     }
 
-    /**
-     * Create the {@link SchemaPath} equivalent of this identifier.
-     *
-     * @return SchemaPath equivalent.
-     * @deprecated This method is scheduled for removal along with {@link SchemaPath}. This method performs memoization,
-     *             which should not be needed most of the time. If you need memoization, you probably can do better, as
-     *             you probably want to attach more state. If you just need a SchemaPath, use
-     *             {@link SchemaPath#of(SchemaNodeIdentifier)} instead.
-     */
-    @Deprecated(since = "7.0.9", forRemoval = true)
-    public final @NonNull SchemaPath asSchemaPath() {
-        final SchemaPath ret = schemaPath;
-        return ret != null ? ret : loadSchemaPath();
-    }
-
     @Override
     public final int hashCode() {
         final int local;
@@ -320,38 +271,27 @@ public abstract class SchemaNodeIdentifier implements Immutable {
         return MoreObjects.toStringHelper(className()).add("qnames", toStringQNames()).toString();
     }
 
-    @Deprecated(since = "7.0.9", forRemoval = true)
-    abstract @NonNull SchemaPath implicitSchemaPathParent();
-
     abstract @NonNull Object pathObject();
 
     abstract @NonNull String className();
 
-    @Deprecated(since = "7.0.9", forRemoval = true)
-    private @NonNull SchemaPath loadSchemaPath() {
-        final SchemaPath newPath = implicitSchemaPathParent().createChild(getNodeIdentifiers());
-        return SCHEMAPATH_UPDATER.compareAndSet(this, null, newPath) ? newPath : schemaPath;
-    }
-
     private List<?> toStringQNames() {
-        final List<QName> ids = getNodeIdentifiers();
+        final var ids = getNodeIdentifiers();
         return ids.size() < 2 ? ids : simplifyQNames(ids);
     }
 
-    @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
-            justification = "https://github.com/spotbugs/spotbugs/issues/811")
     private static ImmutableList<QName> checkQNames(final Collection<QName> qnames) {
-        final ImmutableList<QName> ret = ImmutableList.copyOf(qnames);
+        final var ret = ImmutableList.copyOf(qnames);
         checkArgument(!ret.isEmpty(), "SchemaNodeIdentifier has to have at least one node identifier");
         return ret;
     }
 
     private static List<?> simplifyQNames(final List<QName> qnames) {
-        final List<Object> ret = new ArrayList<>(qnames.size());
+        final var ret = new ArrayList<>(qnames.size());
 
         QNameModule prev = null;
-        for (QName qname : qnames) {
-            final QNameModule module = qname.getModule();
+        for (var qname : qnames) {
+            final var module = qname.getModule();
             ret.add(module.equals(prev) ? qname.getLocalName() : qname);
             prev = module;
         }