From e8b788e0ccc8e0a0499dedb5cb85d642cf5c9c22 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Wed, 27 Oct 2021 02:20:07 +0200 Subject: [PATCH] Add SchemaPath.of(SchemaNodeIdentifier) 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 (cherry picked from commit 4cea93f6402296296b1a0551241eaa4e16ae6f03) --- .../yangtools/yang/model/api/SchemaPath.java | 18 ++++++++++++++++++ .../model/api/stmt/SchemaNodeIdentifier.java | 5 ++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/model/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaPath.java b/model/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaPath.java index f22dfe92a7..38e6f01b4e 100644 --- a/model/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaPath.java +++ b/model/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaPath.java @@ -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. * diff --git a/model/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/SchemaNodeIdentifier.java b/model/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/SchemaNodeIdentifier.java index 029d963af1..5c74fdc9ae 100644 --- a/model/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/SchemaNodeIdentifier.java +++ b/model/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/SchemaNodeIdentifier.java @@ -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() { -- 2.36.6