From: Robert Varga Date: Wed, 10 Feb 2021 13:03:07 +0000 (+0100) Subject: Remove SchemaUtils.findParentSchemaNodesOnPath() X-Git-Tag: v7.0.0~159 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=1fcc24ec557499b683b036c9fed6840d1802ccf8;p=yangtools.git Remove SchemaUtils.findParentSchemaNodesOnPath() These methods are not used anywhere except tests, remove them now. JIRA: YANGTOOLS-1230 Change-Id: I3ca3d7bd7bf1e6f27fea634ee138d3f1769e5666 Signed-off-by: Robert Varga --- diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/SchemaUtils.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/SchemaUtils.java index 6385e83984..5182db1ecc 100644 --- a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/SchemaUtils.java +++ b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/SchemaUtils.java @@ -8,7 +8,6 @@ package org.opendaylight.yangtools.yang.data.impl.schema; import static com.google.common.base.Preconditions.checkState; -import static java.util.Objects.requireNonNull; import com.google.common.collect.Collections2; import com.google.common.collect.ImmutableList; @@ -39,7 +38,6 @@ import org.opendaylight.yangtools.yang.model.api.NotificationNodeContainer; import org.opendaylight.yangtools.yang.model.api.OperationDefinition; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.SchemaNode; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; public final class SchemaUtils { private SchemaUtils() { @@ -392,26 +390,6 @@ public final class SchemaUtils { return null; } - /** - * Finds schema node for given path in schema context. This method performs - * lookup in the namespace of all leafs, leaf-lists, lists, containers, - * choices, rpcs, actions, notifications, anydatas, and anyxmls according to - * Rfc6050/Rfc7950 section 6.2.1. - * - * @param schemaContext - * schema context - * @param path - * path - * @return schema node on path - */ - public static SchemaNode findDataParentSchemaOnPath(final SchemaContext schemaContext, final SchemaPath path) { - SchemaNode current = requireNonNull(schemaContext); - for (final QName qname : path.getPathFromRoot()) { - current = findDataChildSchemaByQName(current, qname); - } - return current; - } - /** * Find child data schema node identified by its QName within a provided schema node. This method performs lookup * in the namespace of all leafs, leaf-lists, lists, containers, choices, rpcs, actions, notifications, anydatas @@ -457,58 +435,6 @@ public final class SchemaUtils { throw new IllegalArgumentException(String.format("Schema node %s does not allow children.", node)); } - /** - * Finds schema node for given path in schema context. This method performs lookup in both the namespace - * of groupings and the namespace of all leafs, leaf-lists, lists, containers, choices, rpcs, actions, - * notifications, anydatas and anyxmls according to Rfc6050/Rfc7950 section 6.2.1. - * - *

- * This method returns collection of SchemaNodes, because name conflicts can occur between the namespace - * of groupings and namespace of data nodes. This method finds and collects all schema nodes that matches supplied - * SchemaPath and returns them all as collection of schema nodes. - * - * @param schemaContext - * schema context - * @param path - * path - * @return collection of schema nodes on path - */ - public static Collection findParentSchemaNodesOnPath(final SchemaContext schemaContext, - final SchemaPath path) { - return findParentSchemaNodesOnPath(schemaContext, path.getPathFromRoot()); - } - - /** - * Finds schema node for given path in schema context. This method performs lookup in both the namespace - * of groupings and the namespace of all leafs, leaf-lists, lists, containers, choices, rpcs, actions, - * notifications, anydatas and anyxmls according to Rfc6050/Rfc7950 section 6.2.1. - * - *

- * This method returns collection of SchemaNodes, because name conflicts can occur between the namespace - * of groupings and namespace of data nodes. This method finds and collects all schema nodes that matches supplied - * SchemaPath and returns them all as collection of schema nodes. - * - * @param schemaContext schema context - * @param path path - * @return collection of schema nodes on path - */ - public static Collection findParentSchemaNodesOnPath(final SchemaContext schemaContext, - final Iterable path) { - final Collection currentNodes = new ArrayList<>(); - final Collection childNodes = new ArrayList<>(); - currentNodes.add(requireNonNull(schemaContext)); - for (final QName qname : path) { - for (final SchemaNode current : currentNodes) { - childNodes.addAll(findChildSchemaNodesByQName(current, qname)); - } - currentNodes.clear(); - currentNodes.addAll(childNodes); - childNodes.clear(); - } - - return currentNodes; - } - /** * Find child schema node identified by its QName within a provided schema node. This method performs lookup in both * the namespace of groupings and the namespace of all leafs, leaf-lists, lists, containers, choices, rpcs, diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/SchemaUtilsTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/SchemaUtilsTest.java deleted file mode 100644 index b04b8310c2..0000000000 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/SchemaUtilsTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.yangtools.yang.data.impl.schema; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.util.Collection; -import org.junit.Test; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.ActionDefinition; -import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; -import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; -import org.opendaylight.yangtools.yang.model.api.NotificationDefinition; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.api.SchemaNode; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; -import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; - -public class SchemaUtilsTest { - private static final String NS = "my-namespace"; - - @Test - public void test() { - final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/schema-utils-test/foo.yang"); - assertTrue(SchemaUtils.findDataParentSchemaOnPath(schemaContext, - SchemaPath.create(true, qN("my-name"), qN("my-name-a"))) instanceof ContainerSchemaNode); - assertTrue(SchemaUtils.findDataParentSchemaOnPath(schemaContext, - SchemaPath.create(true, qN("my-name-2"), qN("my-name-b"))) instanceof NotificationDefinition); - assertTrue(SchemaUtils.findDataParentSchemaOnPath(schemaContext, - SchemaPath.create(true, qN("my-name-2"), qN("my-name-2-b"))) instanceof ActionDefinition); - } - - @Test - public void testNameConflicts() { - final SchemaContext schemaContext = YangParserTestUtils - .parseYangResource("/schema-utils-test/name-conflicts.yang"); - // test my-name conflicts - assertEquals(8, SchemaUtils.findParentSchemaNodesOnPath(schemaContext, - SchemaPath.create(true, qN("my-name"), qN("my-name-nested"), qN("my-name-nested2"))).size()); - - // test target container - final Collection target = SchemaUtils.findParentSchemaNodesOnPath(schemaContext, - SchemaPath.create(true, qN("my-name-2"), qN("my-name-nested"), qN("target"))); - assertEquals(1, target.size()); - assertTrue(target.iterator().next() instanceof ContainerSchemaNode); - - // test l schema nodes (i.e. container and two leafs) - Collection schema = SchemaUtils.findParentSchemaNodesOnPath(schemaContext, - SchemaPath.create(true, qN("my-name-3"), qN("input"), qN("con-3"), qN("l"))); - assertEquals(1, schema.size()); - assertTrue(schema.iterator().next() instanceof ContainerSchemaNode); - - schema = SchemaUtils.findParentSchemaNodesOnPath(schemaContext, - SchemaPath.create(true, qN("my-name-3"), qN("input"), qN("con-1"), qN("l"))); - assertEquals(1, schema.size()); - assertTrue(schema.iterator().next() instanceof LeafSchemaNode); - - schema = SchemaUtils.findParentSchemaNodesOnPath(schemaContext, - SchemaPath.create(true, qN("my-name-3"), qN("input"), qN("con-2"), qN("l"))); - assertTrue(schema.isEmpty()); - - schema = SchemaUtils.findParentSchemaNodesOnPath(schemaContext, - SchemaPath.create(true, qN("my-name-3"), qN("output"), qN("con-2"), qN("l"))); - assertEquals(1, schema.size()); - assertTrue(schema.iterator().next() instanceof LeafSchemaNode); - } - - private static QName qN(final String localName) { - return QName.create(NS, localName); - } -} diff --git a/yang/yang-data-impl/src/test/resources/schema-utils-test/foo.yang b/yang/yang-data-impl/src/test/resources/schema-utils-test/foo.yang deleted file mode 100644 index abd079b1a4..0000000000 --- a/yang/yang-data-impl/src/test/resources/schema-utils-test/foo.yang +++ /dev/null @@ -1,39 +0,0 @@ -module foo { - namespace my-namespace; - prefix p; - yang-version 1.1; - - feature my-name; - - identity my-name; - - extension my-name; - - typedef my-name { - type string; - } - - grouping my-name { - } - - grouping my-name-2 { - } - - notification my-name { - grouping my-name-a { - } - container my-name-a { - } - } - - container my-name-2 { - grouping my-name-b { - } - notification my-name-b { - } - grouping my-name-2-b { - } - action my-name-2-b { - } - } -} diff --git a/yang/yang-data-impl/src/test/resources/schema-utils-test/name-conflicts.yang b/yang/yang-data-impl/src/test/resources/schema-utils-test/name-conflicts.yang deleted file mode 100644 index bc51627301..0000000000 --- a/yang/yang-data-impl/src/test/resources/schema-utils-test/name-conflicts.yang +++ /dev/null @@ -1,90 +0,0 @@ -module name-conflicts { - namespace "my-namespace"; - prefix nc; - - grouping my-name { - grouping my-name-nested { - grouping my-name-nested2 { - } - container my-name-nested2 { - } - } - container my-name-nested { - grouping my-name-nested2 { - } - container my-name-nested2 { - } - } - } - - container my-name { - grouping my-name-nested { - grouping my-name-nested2 { - } - container my-name-nested2 { - } - } - container my-name-nested { - grouping my-name-nested2 { - } - container my-name-nested2 { - } - } - } - - grouping my-name-2 { - grouping my-name-nested { - grouping my-name-nested2 { - } - container my-name-nested2 { - } - } - container my-name-2 { - grouping my-name-nested2 { - } - container my-name-nested2 { - } - } - } - - container my-name-2 { - grouping my-name-nested { - grouping my-name-nested2 { - } - container target { - } - } - container my-name-nested { - grouping my-name-nested2 { - } - container my-name-nested2 { - } - } - } - - rpc my-name-3 { - input { - container con-1 { - leaf l { - type string; - } - } - } - output { - container con-2 { - leaf l { - type string; - } - } - } - } - - grouping my-name-3 { - container input { - container con-3 { - container l { - } - } - } - } -}