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=748d004895d56663443d0cb558b6329d1f845f77;hb=5d7c036b41a4b63ee510e834aca135c9ca183625;hp=60e076d22c6146675b2858c1642648792f17328d;hpb=1636eaae9a133d79301b7ebb02ae8d6a5fc38117;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 60e076d22c..748d004895 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 @@ -16,8 +16,7 @@ import java.util.Collection; import java.util.Iterator; import java.util.NoSuchElementException; 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; /** @@ -29,7 +28,7 @@ public interface DataNodeContainer { * * @return typedef statements in lexicographical order */ - Set> getTypeDefinitions(); + Collection> getTypeDefinitions(); /** * Returns set of all child nodes defined within this DataNodeContainer. Although the return type is a collection, @@ -42,14 +41,14 @@ public interface DataNodeContainer { * * @return child nodes in lexicographical order */ - Collection getChildNodes(); + Collection getChildNodes(); /** * Returns set of all groupings defined within this DataNodeContainer. * * @return grouping statements in lexicographical order */ - Set getGroupings(); + Collection getGroupings(); /** * Returns the child node corresponding to the specified name. @@ -61,14 +60,31 @@ public interface DataNodeContainer { * * @param name QName of child * @return child node of this DataNodeContainer if child with given name is present, null otherwise - * @deprecated Use {@link #findDataChildByName(QName)} instead. * @throws NullPointerException if {@code name} is null */ - @Deprecated - @Nullable default DataSchemaNode getDataChildByName(final QName name) { + default @Nullable DataSchemaNode dataChildByName(final QName name) { return findDataChildByName(name).orElse(null); } + /** + * 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. This + * is consistent with {@code schema tree}. + * + * @param name QName of child + * @return child node of this DataNodeContainer if child with given name is present, null otherwise + * @deprecated Use {@link #dataChildByName(QName)} or {@link #findDataChildByName(QName)} instead. This method will + * be repurposed to assert existence in the next major release. + * @throws NullPointerException if {@code name} is null + */ + @Deprecated(forRemoval = true) + default @Nullable DataSchemaNode getDataChildByName(final QName name) { + return dataChildByName(name); + } + /** * Returns the child node corresponding to the specified name. * @@ -82,12 +98,40 @@ 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(final QName first, final 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. * * @return Set of all uses nodes defined within this DataNodeContainer */ - Set getUses(); + Collection getUses(); /** * Returns a {@code data node} identified by a QName. This method is distinct from @@ -110,7 +154,7 @@ public interface DataNodeContainer { // hence we have to resort to a full search. for (DataSchemaNode child : getChildNodes()) { if (child instanceof ChoiceSchemaNode) { - for (CaseSchemaNode choiceCase : ((ChoiceSchemaNode) child).getCases().values()) { + for (CaseSchemaNode choiceCase : ((ChoiceSchemaNode) child).getCases()) { final Optional caseChild = choiceCase.findDataTreeChild(name); if (caseChild.isPresent()) { return caseChild; @@ -153,7 +197,7 @@ public interface DataNodeContainer { DataNodeContainer parent = this; do { final Optional optChild = parent.findDataTreeChild(requireNonNull(it.next())); - if (!optChild.isPresent() || !it.hasNext()) { + if (optChild.isEmpty() || !it.hasNext()) { return optChild; }