Add SchemaPath.of(SchemaNodeIdentifier) 59/98159/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 27 Oct 2021 00:20:07 +0000 (02:20 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 27 Oct 2021 10:58:52 +0000 (12:58 +0200)
SchemaNodeIdentifier depends on SchemaPath, which is a bad idea from
flexibility perspective. Since the methods are deprecated, add their
non-cached counterparts in SchemaPath.

JIRA: YANGTOOLS-1358
Change-Id: I8fc6897940a172b06cf309f1a40b56e4e00a6030
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 4cea93f6402296296b1a0551241eaa4e16ae6f03)

model/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaPath.java
model/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/SchemaNodeIdentifier.java

index f22dfe92a704fd2f4809e6250c02cd2e2c70d0a4..38e6f01b4ea1999cac5624aa8e7d9d55390ccd06 100644 (file)
@@ -118,6 +118,24 @@ public abstract class SchemaPath implements Immutable {
         hash = tmp;
     }
 
+    public static @NonNull SchemaPath of(final SchemaNodeIdentifier path) {
+        if (path instanceof Absolute) {
+            return of((Absolute) path);
+        } else if (path instanceof Descendant) {
+            return of((Descendant) path);
+        } else {
+            throw new IllegalStateException("Unexpected path " + requireNonNull(path));
+        }
+    }
+
+    public static @NonNull SchemaPath of(final Absolute path) {
+        return SchemaPath.ROOT.createChild(path.getNodeIdentifiers());
+    }
+
+    public static @NonNull SchemaPath of(final Descendant path) {
+        return SchemaPath.SAME.createChild(path.getNodeIdentifiers());
+    }
+
     /**
      * Constructs new instance of this class with the concrete path.
      *
index 029d963af1adea3684b91cc57d2e282e32f95bcc..5c74fdc9aebde7574ab5017505d0b9e6389d2e31 100644 (file)
@@ -292,7 +292,10 @@ public abstract class SchemaNodeIdentifier implements Immutable {
      * Create the {@link SchemaPath} equivalent of this identifier.
      *
      * @return SchemaPath equivalent.
-     * @deprecated This method is scheduled for removal along with {@link SchemaPath}.
+     * @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() {