Add DataNodeContainer.findDataChildByName(QName, QName...)
[yangtools.git] / yang / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / api / DataNodeContainer.java
index c6ad90375bfbd3266483ae571e05a0deff08ff6d..2658835321d1205ad9c3aa9ef0660325e098ec26 100644 (file)
@@ -82,6 +82,34 @@ public interface DataNodeContainer {
      */
     Optional<DataSchemaNode> findDataChildByName(QName name);
 
+    /**
+     * Returns the child node corresponding to the specified name.
+     *
+     * <p>
+     * Note that the nodes searched are <strong>NOT</strong> {@code data nodes}, but rather {@link DataSchemaNode}s,
+     * hence {@link ChoiceSchemaNode} and {@link CaseSchemaNode} are returned instead of their matching children.
+     *
+     * @param first QName of first child
+     * @param others QNames of subsequent children
+     * @return child node of this DataNodeContainer if child with given name is present, empty otherwise
+     * @throws NullPointerException if any argument is null
+     */
+    default Optional<DataSchemaNode> findDataChildByName(QName first, QName... others) {
+        Optional<DataSchemaNode> optCurrent = findDataChildByName(first);
+        for (QName qname : others) {
+            if (optCurrent.isPresent()) {
+                final DataSchemaNode current = optCurrent.get();
+                if (current instanceof DataNodeContainer) {
+                    optCurrent = ((DataNodeContainer) current).findDataChildByName(qname);
+                    continue;
+                }
+            }
+
+            return Optional.empty();
+        }
+        return optCurrent;
+    }
+
     /**
      * Returns grouping nodes used ny this container.
      *