X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-model-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fmodel%2Fapi%2FDataNodeContainer.java;h=2658835321d1205ad9c3aa9ef0660325e098ec26;hb=d0dbb419174786ae930c5a6838d032f0975add38;hp=c6ad90375bfbd3266483ae571e05a0deff08ff6d;hpb=f4212253d03d6917ce6317d99c4d47a1e5028905;p=yangtools.git diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/DataNodeContainer.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/DataNodeContainer.java index c6ad90375b..2658835321 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/DataNodeContainer.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/DataNodeContainer.java @@ -82,6 +82,34 @@ public interface DataNodeContainer { */ Optional findDataChildByName(QName name); + /** + * Returns the child node corresponding to the specified name. + * + *

+ * Note that the nodes searched are NOT {@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 findDataChildByName(QName first, QName... others) { + Optional 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. *