Migrate getDataChildByName() users
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / SchemaUtils.java
index 9ab9cf672d6ac28bf53ba56c6c952d11e9337d85..a93ff38ebdd7754b1b162aed00d6046112fb284f 100644 (file)
@@ -7,15 +7,14 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.schema;
 
-import com.google.common.base.Preconditions;
-import com.google.common.base.Predicate;
+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;
 import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
@@ -23,27 +22,28 @@ import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 import java.util.Set;
-import javax.annotation.Nullable;
+import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
 import org.opendaylight.yangtools.yang.model.api.ActionNodeContainer;
-import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
+import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.AugmentationTarget;
-import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
+import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.NotificationNodeContainer;
-import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
+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() {
-        throw new UnsupportedOperationException();
+        // Hidden on purpose
     }
 
     /**
@@ -54,20 +54,20 @@ public final class SchemaUtils {
      * @return schema node with newest revision or absent if no schema node with matching qname is found
      */
     public static Optional<DataSchemaNode> findFirstSchema(final QName qname,
-            final Iterable<DataSchemaNode> dataSchemaNode) {
+            final Iterable<? extends DataSchemaNode> dataSchemaNode) {
         DataSchemaNode schema = null;
         if (dataSchemaNode != null && qname != null) {
             for (final DataSchemaNode dsn : dataSchemaNode) {
                 if (qname.isEqualWithoutRevision(dsn.getQName())) {
-                    if (schema == null || schema.getQName().getRevision().compareTo(dsn.getQName().getRevision()) < 0) {
+                    if (schema == null || Revision.compare(schema.getQName().getRevision(),
+                        dsn.getQName().getRevision()) < 0) {
                         schema = dsn;
                     }
                 } else if (dsn instanceof ChoiceSchemaNode) {
-                    for (final ChoiceCaseNode choiceCase : ((ChoiceSchemaNode) dsn).getCases()) {
-
-                        final DataSchemaNode dataChildByName = choiceCase.getDataChildByName(qname);
-                        if (dataChildByName != null) {
-                            return Optional.of(dataChildByName);
+                    for (final CaseSchemaNode choiceCase : ((ChoiceSchemaNode) dsn).getCases()) {
+                        final Optional<DataSchemaNode> dataChildByName = choiceCase.findDataChildByName(qname);
+                        if (dataChildByName.isPresent()) {
+                            return dataChildByName;
                         }
                         final Optional<DataSchemaNode> foundDsn = findFirstSchema(qname, choiceCase.getChildNodes());
                         if (foundDsn.isPresent()) {
@@ -91,12 +91,12 @@ public final class SchemaUtils {
     public static DataSchemaNode findSchemaForChild(final DataNodeContainer schema, final QName qname) {
         // Try to find child schema node directly, but use a fallback that compares QNames without revisions
         // and auto-expands choices
-        final DataSchemaNode dataChildByName = schema.getDataChildByName(qname);
-        return dataChildByName == null ? findSchemaForChild(schema, qname, schema.getChildNodes()) : dataChildByName;
+        final Optional<DataSchemaNode> dataChildByName = schema.findDataChildByName(qname);
+        return dataChildByName.isPresent() ? dataChildByName.get()
+                : findSchemaForChild(schema, qname, schema.getChildNodes());
     }
 
-    @Nullable
-    public static DataSchemaNode findSchemaForChild(final DataNodeContainer schema, final QName qname,
+    public static @Nullable DataSchemaNode findSchemaForChild(final DataNodeContainer schema, final QName qname,
             final boolean strictMode) {
         if (strictMode) {
             return findSchemaForChild(schema, qname);
@@ -110,15 +110,15 @@ public final class SchemaUtils {
     }
 
     public static DataSchemaNode findSchemaForChild(final DataNodeContainer schema, final QName qname,
-            final Iterable<DataSchemaNode> childNodes) {
+            final Iterable<? extends DataSchemaNode> childNodes) {
         final Optional<DataSchemaNode> childSchema = findFirstSchema(qname, childNodes);
-        Preconditions.checkState(childSchema.isPresent(),
-                "Unknown child(ren) node(s) detected, identified by: %s, in: %s", qname, schema);
+        checkState(childSchema.isPresent(), "Unknown child(ren) node(s) detected, identified by: %s, in: %s", qname,
+            schema);
         return childSchema.get();
     }
 
     public static DataSchemaNode findSchemaForChild(final ChoiceSchemaNode schema, final QName childPartialQName) {
-        for (final ChoiceCaseNode choiceCaseNode : schema.getCases()) {
+        for (final CaseSchemaNode choiceCaseNode : schema.getCases()) {
             final Optional<DataSchemaNode> childSchema = findFirstSchema(childPartialQName,
                 choiceCaseNode.getChildNodes());
             if (childSchema.isPresent()) {
@@ -131,34 +131,32 @@ public final class SchemaUtils {
                 childPartialQName, schema));
     }
 
-    public static AugmentationSchema findSchemaForAugment(final AugmentationTarget schema, final Set<QName> qnames) {
-        final Optional<AugmentationSchema> schemaForAugment = findAugment(schema, qnames);
-        Preconditions.checkState(schemaForAugment.isPresent(),
-            "Unknown augmentation node detected, identified by: %s, in: %s", qnames, schema);
+    public static AugmentationSchemaNode findSchemaForAugment(final AugmentationTarget schema,
+            final Set<QName> qnames) {
+        final Optional<AugmentationSchemaNode> schemaForAugment = findAugment(schema, qnames);
+        checkState(schemaForAugment.isPresent(), "Unknown augmentation node detected, identified by: %s, in: %s",
+            qnames, schema);
         return schemaForAugment.get();
     }
 
-    public static AugmentationSchema findSchemaForAugment(final ChoiceSchemaNode schema, final Set<QName> qnames) {
-        Optional<AugmentationSchema> schemaForAugment = Optional.empty();
-
-        for (final ChoiceCaseNode choiceCaseNode : schema.getCases()) {
-            schemaForAugment = findAugment(choiceCaseNode, qnames);
+    public static AugmentationSchemaNode findSchemaForAugment(final ChoiceSchemaNode schema, final Set<QName> qnames) {
+        for (final CaseSchemaNode choiceCaseNode : schema.getCases()) {
+            final Optional<AugmentationSchemaNode> schemaForAugment = findAugment(choiceCaseNode, qnames);
             if (schemaForAugment.isPresent()) {
-                break;
+                return schemaForAugment.get();
             }
         }
 
-        Preconditions.checkState(schemaForAugment.isPresent(),
-            "Unknown augmentation node detected, identified by: %s, in: %s", qnames, schema);
-        return schemaForAugment.get();
+        throw new IllegalStateException(String.format("Unknown augmentation node detected, identified by: %s, in: %s",
+            qnames, schema));
     }
 
-    private static Optional<AugmentationSchema> findAugment(final AugmentationTarget schema, final Set<QName> qnames) {
-        for (final AugmentationSchema augment : schema.getAvailableAugmentations()) {
+    private static Optional<AugmentationSchemaNode> findAugment(final AugmentationTarget schema,
+            final Set<QName> qnames) {
+        for (final AugmentationSchemaNode augment : schema.getAvailableAugmentations()) {
             final Set<QName> qNamesFromAugment = ImmutableSet.copyOf(Collections2.transform(augment.getChildNodes(),
-                DataSchemaNode::getQName));
-
-            if (qNamesFromAugment.equals(qnames)) {
+                        DataSchemaNode::getQName));
+            if (qnames.equals(qNamesFromAugment)) {
                 return Optional.of(augment);
             }
         }
@@ -177,7 +175,7 @@ public final class SchemaUtils {
     }
 
     private static Map<QName, ChoiceSchemaNode> mapChildElementsFromChoices(final DataNodeContainer schema,
-            final Iterable<DataSchemaNode> childNodes) {
+            final Iterable<? extends DataSchemaNode> childNodes) {
         final Map<QName, ChoiceSchemaNode> mappedChoices = new LinkedHashMap<>();
 
         for (final DataSchemaNode childSchema : childNodes) {
@@ -187,7 +185,7 @@ public final class SchemaUtils {
                     continue;
                 }
 
-                for (final ChoiceCaseNode choiceCaseNode : ((ChoiceSchemaNode) childSchema).getCases()) {
+                for (final CaseSchemaNode choiceCaseNode : ((ChoiceSchemaNode) childSchema).getCases()) {
                     for (final QName qname : getChildNodesRecursive(choiceCaseNode)) {
                         mappedChoices.put(qname, (ChoiceSchemaNode) childSchema);
                     }
@@ -203,8 +201,8 @@ public final class SchemaUtils {
             return false;
         }
 
-        for (final AugmentationSchema augmentationSchema : ((AugmentationTarget) schema).getAvailableAugmentations()) {
-            if (augmentationSchema.getDataChildByName(childSchema.getQName()) != null) {
+        for (final AugmentationSchemaNode augmentation : ((AugmentationTarget) schema).getAvailableAugmentations()) {
+            if (augmentation.findDataChildByName(childSchema.getQName()).isPresent()) {
                 return true;
             }
         }
@@ -218,13 +216,13 @@ public final class SchemaUtils {
      * @param schema schema
      * @return Map with all child nodes, to their most top augmentation
      */
-    public static Map<QName, AugmentationSchema> mapChildElementsFromAugments(final AugmentationTarget schema) {
+    public static Map<QName, AugmentationSchemaNode> mapChildElementsFromAugments(final AugmentationTarget schema) {
 
-        final Map<QName, AugmentationSchema> childNodesToAugmentation = new LinkedHashMap<>();
+        final Map<QName, AugmentationSchemaNode> childNodesToAugmentation = new LinkedHashMap<>();
 
         // Find QNames of augmented child nodes
-        final Map<QName, AugmentationSchema> augments = new HashMap<>();
-        for (final AugmentationSchema augmentationSchema : schema.getAvailableAugmentations()) {
+        final Map<QName, AugmentationSchemaNode> augments = new HashMap<>();
+        for (final AugmentationSchemaNode augmentationSchema : schema.getAvailableAugmentations()) {
             for (final DataSchemaNode dataSchemaNode : augmentationSchema.getChildNodes()) {
                 augments.put(dataSchemaNode.getQName(), augmentationSchema);
             }
@@ -240,15 +238,15 @@ public final class SchemaUtils {
                     continue;
                 }
 
-                final AugmentationSchema mostTopAugmentation = augments.get(child.getQName());
+                final AugmentationSchemaNode mostTopAugmentation = augments.get(child.getQName());
 
                 // recursively add all child nodes in case of augment, case and choice
-                if (child instanceof AugmentationSchema || child instanceof ChoiceCaseNode) {
+                if (child instanceof AugmentationSchemaNode || child instanceof CaseSchemaNode) {
                     for (final QName qname : getChildNodesRecursive((DataNodeContainer) child)) {
                         childNodesToAugmentation.put(qname, mostTopAugmentation);
                     }
                 } else if (child instanceof ChoiceSchemaNode) {
-                    for (final ChoiceCaseNode choiceCaseNode : ((ChoiceSchemaNode) child).getCases()) {
+                    for (final CaseSchemaNode choiceCaseNode : ((ChoiceSchemaNode) child).getCases()) {
                         for (final QName qname : getChildNodesRecursive(choiceCaseNode)) {
                             childNodesToAugmentation.put(qname, mostTopAugmentation);
                         }
@@ -261,7 +259,7 @@ public final class SchemaUtils {
 
         // Choice Node has to map child nodes from all its cases
         if (schema instanceof ChoiceSchemaNode) {
-            for (final ChoiceCaseNode choiceCaseNode : ((ChoiceSchemaNode) schema).getCases()) {
+            for (final CaseSchemaNode choiceCaseNode : ((ChoiceSchemaNode) schema).getCases()) {
                 if (!augments.containsKey(choiceCaseNode.getQName())) {
                     continue;
                 }
@@ -286,10 +284,10 @@ public final class SchemaUtils {
 
         for (final DataSchemaNode childSchema : nodeContainer.getChildNodes()) {
             if (childSchema instanceof ChoiceSchemaNode) {
-                for (final ChoiceCaseNode choiceCaseNode : ((ChoiceSchemaNode) childSchema).getCases()) {
+                for (final CaseSchemaNode choiceCaseNode : ((ChoiceSchemaNode) childSchema).getCases()) {
                     allChildNodes.addAll(getChildNodesRecursive(choiceCaseNode));
                 }
-            } else if (childSchema instanceof AugmentationSchema || childSchema instanceof ChoiceCaseNode) {
+            } else if (childSchema instanceof AugmentationSchemaNode || childSchema instanceof CaseSchemaNode) {
                 allChildNodes.addAll(getChildNodesRecursive((DataNodeContainer) childSchema));
             } else {
                 allChildNodes.add(childSchema.getQName());
@@ -311,9 +309,9 @@ public final class SchemaUtils {
      * @return set of nodes
      */
     public static Set<DataSchemaNode> getRealSchemasForAugment(final AugmentationTarget targetSchema,
-            final AugmentationSchema augmentSchema) {
+            final AugmentationSchemaNode augmentSchema) {
         if (!targetSchema.getAvailableAugmentations().contains(augmentSchema)) {
-            return Collections.emptySet();
+            return ImmutableSet.of();
         }
         if (targetSchema instanceof DataNodeContainer) {
             return getRealSchemasForAugment((DataNodeContainer)targetSchema, augmentSchema);
@@ -321,7 +319,7 @@ public final class SchemaUtils {
         final Set<DataSchemaNode> realChildNodes = new HashSet<>();
         if (targetSchema instanceof ChoiceSchemaNode) {
             for (final DataSchemaNode dataSchemaNode : augmentSchema.getChildNodes()) {
-                for (final ChoiceCaseNode choiceCaseNode : ((ChoiceSchemaNode) targetSchema).getCases()) {
+                for (final CaseSchemaNode choiceCaseNode : ((ChoiceSchemaNode) targetSchema).getCases()) {
                     if (getChildNodesRecursive(choiceCaseNode).contains(dataSchemaNode.getQName())) {
                         realChildNodes.add(choiceCaseNode.getDataChildByName(dataSchemaNode.getQName()));
                     }
@@ -333,7 +331,7 @@ public final class SchemaUtils {
     }
 
     public static Set<DataSchemaNode> getRealSchemasForAugment(final DataNodeContainer targetSchema,
-            final AugmentationSchema augmentSchema) {
+            final AugmentationSchemaNode augmentSchema) {
         final Set<DataSchemaNode> realChildNodes = new HashSet<>();
         for (final DataSchemaNode dataSchemaNode : augmentSchema.getChildNodes()) {
             final DataSchemaNode realChild = targetSchema.getDataChildByName(dataSchemaNode.getQName());
@@ -342,13 +340,13 @@ public final class SchemaUtils {
         return realChildNodes;
     }
 
-    public static Optional<ChoiceCaseNode> detectCase(final ChoiceSchemaNode schema,
+    public static Optional<CaseSchemaNode> detectCase(final ChoiceSchemaNode schema,
             final DataContainerChild<?, ?> child) {
-        for (final ChoiceCaseNode choiceCaseNode : schema.getCases()) {
+        for (final CaseSchemaNode choiceCaseNode : schema.getCases()) {
             if (child instanceof AugmentationNode
                     && belongsToCaseAugment(choiceCaseNode, (AugmentationIdentifier) child.getIdentifier())) {
                 return Optional.of(choiceCaseNode);
-            } else if (choiceCaseNode.getDataChildByName(child.getNodeType()) != null) {
+            } else if (choiceCaseNode.findDataChildByName(child.getNodeType()).isPresent()) {
                 return Optional.of(choiceCaseNode);
             }
         }
@@ -356,9 +354,9 @@ public final class SchemaUtils {
         return Optional.empty();
     }
 
-    public static boolean belongsToCaseAugment(final ChoiceCaseNode caseNode,
+    public static boolean belongsToCaseAugment(final CaseSchemaNode caseNode,
             final AugmentationIdentifier childToProcess) {
-        for (final AugmentationSchema augmentationSchema : caseNode.getAvailableAugmentations()) {
+        for (final AugmentationSchemaNode augmentationSchema : caseNode.getAvailableAugmentations()) {
 
             final Set<QName> currentAugmentChildNodes = new HashSet<>();
             for (final DataSchemaNode dataSchemaNode : augmentationSchema.getChildNodes()) {
@@ -381,23 +379,21 @@ public final class SchemaUtils {
      * @param child child node
      * @return augmentation schema
      */
-    public static AugmentationSchema findCorrespondingAugment(final DataSchemaNode parent, final DataSchemaNode child) {
-        if (parent instanceof AugmentationTarget && !(parent instanceof ChoiceSchemaNode)) {
-            for (final AugmentationSchema augmentation : ((AugmentationTarget) parent).getAvailableAugmentations()) {
-                final DataSchemaNode childInAugmentation = augmentation.getDataChildByName(child.getQName());
-                if (childInAugmentation != null) {
-                    return augmentation;
-                }
+    public static AugmentationSchemaNode findCorrespondingAugment(final DataSchemaNode parent,
+            final DataSchemaNode child) {
+        if (!(parent instanceof AugmentationTarget) || parent instanceof ChoiceSchemaNode) {
+            return null;
+        }
+
+        for (final AugmentationSchemaNode augmentation : ((AugmentationTarget) parent).getAvailableAugmentations()) {
+            final Optional<DataSchemaNode> childInAugmentation = augmentation.findDataChildByName(child.getQName());
+            if (childInAugmentation.isPresent()) {
+                return augmentation;
             }
         }
         return null;
     }
 
-    public static AugmentationIdentifier getNodeIdentifierForAugmentation(final AugmentationSchema schema) {
-        final Collection<QName> qnames = Collections2.transform(schema.getChildNodes(), DataSchemaNode::getQName);
-        return new AugmentationIdentifier(ImmutableSet.copyOf(qnames));
-    }
-
     /**
      * Finds schema node for given path in schema context. This method performs
      * lookup in the namespace of all leafs, leaf-lists, lists, containers,
@@ -411,43 +407,17 @@ public final class SchemaUtils {
      * @return schema node on path
      */
     public static SchemaNode findDataParentSchemaOnPath(final SchemaContext schemaContext, final SchemaPath path) {
-        SchemaNode current = Preconditions.checkNotNull(schemaContext);
+        SchemaNode current = requireNonNull(schemaContext);
         for (final QName qname : path.getPathFromRoot()) {
             current = findDataChildSchemaByQName(current, qname);
         }
         return current;
     }
 
-    /**
-     * 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.
-     *
-     * <p>
-     * This method is deprecated, because name conflicts can occur between the namespace of groupings and namespace
-     * of data nodes and in consequence lookup could be ambiguous.
-     *
-     * @param schemaContext
-     *            schema context
-     * @param path
-     *            path
-     * @return schema node on path
-     *
-     * @deprecated Use {@link #findParentSchemaNodesOnPath(SchemaContext, SchemaPath)} instead.
-     */
-    @Deprecated
-    public static SchemaNode findParentSchemaOnPath(final SchemaContext schemaContext, final SchemaPath path) {
-        SchemaNode current = Preconditions.checkNotNull(schemaContext);
-        for (final QName qname : path.getPathFromRoot()) {
-            current = findChildSchemaByQName(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
-     * and anyxmls according to Rfc6050/Rfc7950 section 6.2.1.
+     * and anyxmls according to RFC6050/RFC7950 section 6.2.1.
      *
      * @param node
      *            schema node
@@ -457,68 +427,57 @@ public final class SchemaUtils {
      * @throws IllegalArgumentException
      *             if the schema node does not allow children
      */
-    @Nullable
-    public static SchemaNode findDataChildSchemaByQName(final SchemaNode node, final QName qname) {
-        SchemaNode child = null;
+    public static @Nullable SchemaNode findDataChildSchemaByQName(final SchemaNode node, final QName qname) {
         if (node instanceof DataNodeContainer) {
-            child = ((DataNodeContainer) node).getDataChildByName(qname);
+            SchemaNode child = ((DataNodeContainer) node).dataChildByName(qname);
             if (child == null && node instanceof SchemaContext) {
-                child = tryFindRpc((SchemaContext) node, qname).orElse(null);
+                child = tryFind(((SchemaContext) node).getOperations(), qname).orElse(null);
             }
             if (child == null && node instanceof NotificationNodeContainer) {
-                child = tryFindNotification((NotificationNodeContainer) node, qname).orElse(null);
+                child = tryFind(((NotificationNodeContainer) node).getNotifications(), qname).orElse(null);
             }
             if (child == null && node instanceof ActionNodeContainer) {
-                child = tryFindAction((ActionNodeContainer) node, qname).orElse(null);
+                child = tryFind(((ActionNodeContainer) node).getActions(), qname).orElse(null);
             }
-        } else if (node instanceof ChoiceSchemaNode) {
-            child = ((ChoiceSchemaNode) node).getCaseNodeByName(qname);
-        } else if (node instanceof RpcDefinition) {
+
+            return child;
+        }
+        if (node instanceof ChoiceSchemaNode) {
+            return ((ChoiceSchemaNode) node).findCase(qname).orElse(null);
+        }
+        if (node instanceof OperationDefinition) {
             switch (qname.getLocalName()) {
                 case "input":
-                    child = ((RpcDefinition) node).getInput();
-                    break;
+                    return ((OperationDefinition) node).getInput();
                 case "output":
-                    child = ((RpcDefinition) node).getOutput();
-                    break;
+                    return ((OperationDefinition) node).getOutput();
                 default:
-                    child = null;
-                    break;
+                    return null;
             }
-        } else {
-            throw new IllegalArgumentException(String.format("Schema node %s does not allow children.", node));
         }
 
-        return child;
+        throw new IllegalArgumentException(String.format("Schema node %s does not allow children.", node));
     }
 
     /**
-     * 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,
-     * actions, notifications, anydatas and anyxmls according to RFC6050/RFC7950 section 6.2.1.
+     * 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.
      *
      * <p>
-     * This method is deprecated, because name conflicts can occur between the namespace of groupings and namespace
-     * of data nodes and in consequence lookup could be ambiguous.
-     *
-     * @param node
-     *            schema node
-     * @param qname
-     *            QName
-     * @return child schema node
-     * @throws IllegalArgumentException
-     *             if the schema node does not allow children
+     * 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.
      *
-     * @deprecated Use {@link #findChildSchemaNodesByQName(SchemaNode, QName)} instead.
+     * @param schemaContext
+     *            schema context
+     * @param path
+     *            path
+     * @return collection of schema nodes on path
      */
-    @Deprecated
-    public static SchemaNode findChildSchemaByQName(final SchemaNode node, final QName qname) {
-        SchemaNode child = findDataChildSchemaByQName(node, qname);
-        if (child == null && node instanceof DataNodeContainer) {
-            child = tryFindGroupings((DataNodeContainer) node, qname).orElse(null);
-        }
-
-        return child;
+    public static Collection<SchemaNode> findParentSchemaNodesOnPath(final SchemaContext schemaContext,
+            final SchemaPath path) {
+        return findParentSchemaNodesOnPath(schemaContext, path.getPathFromRoot());
     }
 
     /**
@@ -531,18 +490,16 @@ public final class SchemaUtils {
      * 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
+     * @param schemaContext schema context
+     * @param path path
      * @return collection of schema nodes on path
      */
     public static Collection<SchemaNode> findParentSchemaNodesOnPath(final SchemaContext schemaContext,
-            final SchemaPath path) {
+            final Iterable<QName> path) {
         final Collection<SchemaNode> currentNodes = new ArrayList<>();
         final Collection<SchemaNode> childNodes = new ArrayList<>();
-        currentNodes.add(Preconditions.checkNotNull(schemaContext));
-        for (final QName qname : path.getPathFromRoot()) {
+        currentNodes.add(requireNonNull(schemaContext));
+        for (final QName qname : path) {
             for (final SchemaNode current : currentNodes) {
                 childNodes.addAll(findChildSchemaNodesByQName(current, qname));
             }
@@ -579,40 +536,12 @@ public final class SchemaUtils {
             childNodes.add(dataNode);
         }
         if (node instanceof DataNodeContainer) {
-            tryFindGroupings((DataNodeContainer) node, qname).ifPresent(childNodes::add);
+            tryFind(((DataNodeContainer) node).getGroupings(), qname).ifPresent(childNodes::add);
         }
-        return childNodes.isEmpty() ? Collections.emptyList() : ImmutableList.copyOf(childNodes);
-    }
-
-    private static Optional<SchemaNode> tryFindGroupings(final DataNodeContainer dataNodeContainer, final QName qname) {
-        return Optional
-                .ofNullable(Iterables.find(dataNodeContainer.getGroupings(), new SchemaNodePredicate(qname), null));
-    }
-
-    private static Optional<SchemaNode> tryFindRpc(final SchemaContext ctx, final QName qname) {
-        return Optional.ofNullable(Iterables.find(ctx.getOperations(), new SchemaNodePredicate(qname), null));
-    }
-
-    private static Optional<SchemaNode> tryFindNotification(final NotificationNodeContainer notificationContanier,
-            final QName qname) {
-        return Optional.ofNullable(
-                Iterables.find(notificationContanier.getNotifications(), new SchemaNodePredicate(qname), null));
-    }
-
-    private static Optional<SchemaNode> tryFindAction(final ActionNodeContainer actionContanier, final QName qname) {
-        return Optional.ofNullable(Iterables.find(actionContanier.getActions(), new SchemaNodePredicate(qname), null));
+        return childNodes.isEmpty() ? ImmutableList.of() : ImmutableList.copyOf(childNodes);
     }
 
-    private static final class SchemaNodePredicate implements Predicate<SchemaNode> {
-        private final QName qname;
-
-        SchemaNodePredicate(final QName qname) {
-            this.qname = qname;
-        }
-
-        @Override
-        public boolean apply(final SchemaNode input) {
-            return input.getQName().equals(qname);
-        }
+    private static <T extends SchemaNode> Optional<T> tryFind(final Collection<T> nodes, final QName qname) {
+        return nodes.stream().filter(node -> qname.equals(node.getQName())).findFirst();
     }
 }