Migrate getDataChildByName() users
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / SchemaContextUtil.java
index 62e59cca60c2d74030cb5429d42dd0cb318610e0..73bd1765d1d0cc121702ee110b85075647bec6e5 100644 (file)
@@ -36,7 +36,7 @@ import org.opendaylight.yangtools.yang.common.UnqualifiedQName;
 import org.opendaylight.yangtools.yang.model.api.ActionNodeContainer;
 import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ContainerLike;
 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
@@ -335,7 +335,7 @@ public final class SchemaContextUtil {
      * @return Notification schema or null, if notification is not present in schema context.
      */
     @Beta
-    public static @Nullable ContainerSchemaNode getRpcDataSchema(final @NonNull SchemaContext schema,
+    public static @Nullable ContainerLike getRpcDataSchema(final @NonNull SchemaContext schema,
             final @NonNull SchemaPath path) {
         requireNonNull(schema, "Schema context must not be null.");
         requireNonNull(path, "Schema path must not be null.");
@@ -388,7 +388,7 @@ public final class SchemaContextUtil {
         SchemaNode foundNode = null;
         final Iterable<QName> nextPath = nextLevel(path);
 
-        foundNode = module.getDataChildByName(current);
+        foundNode = module.dataChildByName(current);
         if (foundNode != null && nextPath.iterator().hasNext()) {
             foundNode = findNodeIn(foundNode, nextPath);
         }
@@ -436,7 +436,7 @@ public final class SchemaContextUtil {
         if (parent instanceof DataNodeContainer) {
             final DataNodeContainer parentDataNodeContainer = (DataNodeContainer) parent;
 
-            foundNode = parentDataNodeContainer.getDataChildByName(current);
+            foundNode = parentDataNodeContainer.dataChildByName(current);
             if (foundNode != null && nextPath.iterator().hasNext()) {
                 foundNode = findNodeIn(foundNode, nextPath);
             }
@@ -450,10 +450,10 @@ public final class SchemaContextUtil {
         }
 
         if (foundNode == null && parent instanceof ActionNodeContainer) {
-            foundNode = ((ActionNodeContainer) parent).getActions().stream()
-                    .filter(act -> current.equals(act.getQName())).findFirst().orElse(null);
-            if (foundNode != null && nextPath.iterator().hasNext()) {
-                foundNode = findNodeIn(foundNode, nextPath);
+            final Optional<? extends SchemaNode> next = ((ActionNodeContainer) parent).getActions().stream()
+                .filter(act -> current.equals(act.getQName())).findFirst();
+            if (next.isPresent() && nextPath.iterator().hasNext()) {
+                foundNode = findNodeIn(next.orElseThrow(), nextPath);
             }
         }
 
@@ -500,7 +500,7 @@ public final class SchemaContextUtil {
             if (foundNode == null) {
                 // fallback that tries to map into one of the child cases
                 for (final CaseSchemaNode caseNode : ((ChoiceSchemaNode) parent).getCases()) {
-                    final DataSchemaNode maybeChild = caseNode.getDataChildByName(current);
+                    final DataSchemaNode maybeChild = caseNode.dataChildByName(current);
                     if (maybeChild != null) {
                         foundNode = findNodeIn(maybeChild, nextPath);
                         break;
@@ -611,7 +611,7 @@ public final class SchemaContextUtil {
             return QName.create(module.getQNameModule(), prefixedName.next());
         }
 
-        return QName.create(parentModule.getNamespace(), parentModule.getRevision(), prefixedPathPart);
+        return QName.create(parentModule.getQNameModule(), prefixedPathPart);
     }
 
     /**