From 6ff9751b02ef62fa16efd582e2a7f0311e6468cf Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Mon, 19 Jun 2023 23:36:17 +0200 Subject: [PATCH] Turn LinkedPathElement into a record LinkedPathArgument is a pure DTO, convert it to a record to reduce ceremony. Change-Id: I5bb59710f88fe4e8bdb2b3b00f8b539b44b521eb Signed-off-by: Robert Varga --- .../utils/parser/NetconfFieldsTranslator.java | 70 +++++++------------ 1 file changed, 27 insertions(+), 43 deletions(-) diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/NetconfFieldsTranslator.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/NetconfFieldsTranslator.java index fc9e566fe5..3a9333552b 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/NetconfFieldsTranslator.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/utils/parser/NetconfFieldsTranslator.java @@ -53,6 +53,28 @@ import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; * */ public final class NetconfFieldsTranslator { + /** + * {@link DataSchemaContextNode} of data element grouped with identifiers of leading mixin nodes and previous + * path element.
+ * - identifiers of mixin nodes on the path to the target node - required for construction of full valid + * DOM paths,
+ * - {@link LinkedPathElement} of the previous non-mixin node - required to successfully create a chain + * of {@link PathArgument}s + * + * @param parentPathElement parent path element + * @param mixinNodesToTarget identifiers of mixin nodes on the path to the target node + * @param targetNode target non-mixin node + */ + private record LinkedPathElement( + @Nullable LinkedPathElement parentPathElement, + @NonNull List mixinNodesToTarget, + @NonNull DataSchemaContextNode targetNode) { + LinkedPathElement { + requireNonNull(mixinNodesToTarget); + requireNonNull(targetNode); + } + } + private NetconfFieldsTranslator() { // Hidden on purpose } @@ -74,9 +96,7 @@ public final class NetconfFieldsTranslator { private static @NonNull Set parseFields(final @NonNull InstanceIdentifierContext identifier, final @NonNull FieldsParam input) { - final var startNode = DataSchemaContextNode.fromDataSchemaNode( - (DataSchemaNode) identifier.getSchemaNode()); - + final var startNode = DataSchemaContextNode.fromDataSchemaNode((DataSchemaNode) identifier.getSchemaNode()); if (startNode == null) { throw new RestconfDocumentedException( "Start node missing in " + input, ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE); @@ -84,7 +104,7 @@ public final class NetconfFieldsTranslator { final var parsed = new HashSet(); processSelectors(parsed, identifier.getSchemaContext(), identifier.getSchemaNode().getQName().getModule(), - new LinkedPathElement(startNode), input.nodeSelectors()); + new LinkedPathElement(null, List.of(), startNode), input.nodeSelectors()); return parsed; } @@ -158,7 +178,7 @@ public final class NetconfFieldsTranslator { LinkedPathElement pathElement = lastPathElement; final var path = new LinkedList(); do { - path.addFirst(pathElement.targetNodeIdentifier()); + path.addFirst(pathElement.targetNode.getIdentifier()); path.addAll(0, pathElement.mixinNodesToTarget); pathElement = pathElement.parentPathElement; } while (pathElement.parentPathElement != null); @@ -166,48 +186,12 @@ public final class NetconfFieldsTranslator { return YangInstanceIdentifier.create(path); } - private static DataSchemaContextNode resolveMixinNode( - final DataSchemaContextNode node, final @NonNull QName qualifiedName) { + private static DataSchemaContextNode resolveMixinNode(final DataSchemaContextNode node, + final @NonNull QName qualifiedName) { DataSchemaContextNode currentNode = node; while (currentNode != null && currentNode.isMixin()) { currentNode = currentNode.getChild(qualifiedName); } return currentNode; } - - /** - * {@link DataSchemaContextNode} of data element grouped with identifiers of leading mixin nodes and previous - * path element.
- * - identifiers of mixin nodes on the path to the target node - required for construction of full valid - * DOM paths,
- * - {@link LinkedPathElement} of the previous non-mixin node - required to successfully create a chain - * of {@link PathArgument}s - */ - private static final class LinkedPathElement { - private final @Nullable LinkedPathElement parentPathElement; - private final @NonNull List mixinNodesToTarget; - private final @NonNull DataSchemaContextNode targetNode; - - LinkedPathElement(final DataSchemaContextNode targetNode) { - this(null, List.of(), targetNode); - } - - /** - * Creation of new {@link LinkedPathElement}. - * - * @param parentPathElement parent path element - * @param mixinNodesToTarget identifiers of mixin nodes on the path to the target node - * @param targetNode target non-mixin node - */ - LinkedPathElement(@Nullable final LinkedPathElement parentPathElement, - final List mixinNodesToTarget, final DataSchemaContextNode targetNode) { - this.parentPathElement = parentPathElement; - this.mixinNodesToTarget = requireNonNull(mixinNodesToTarget); - this.targetNode = requireNonNull(targetNode); - } - - PathArgument targetNodeIdentifier() { - return targetNode.getIdentifier(); - } - } } -- 2.36.6