/** * 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. 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 #findDataChildByName(QName)} instead. * @throws NullPointerException if {@code name} is null */ @Deprecated default @Nullable DataSchemaNode getDataChildByName(final QName name) { return findDataChildByName(name).orElse(null); }
/** * 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. 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 #findDataChildByName(QName)} instead. * @throws NullPointerException if {@code name} is null */ @Deprecated default @Nullable DataSchemaNode getDataChildByName(final QName name) { return findDataChildByName(name).orElse(null); }
/** * Returns a {@code data node} identified by a QName. This method is distinct from * {@link #findDataChildByName(QName)} in that it skips over {@link ChoiceSchemaNode}s and {@link CaseSchemaNode}s, * hence mirroring layout of the {@code data tree}, not {@code schema tree}. * * @param name QName identifier of the data node * @return Direct or indirect child of this DataNodeContainer which is a {@code data node}, empty otherwise * @throws NullPointerException if {@code name} is null */ @Beta default Optional<DataSchemaNode> findDataTreeChild(final QName name) { // First we try to find a direct child and check if it is a data node (as per RFC7950) final Optional<DataSchemaNode> optDataChild = findDataChildByName(name); if (HelperMethods.isDataNode(optDataChild)) { return optDataChild; } // There either is no such node present, or there are Choice/CaseSchemaNodes with the same name involved, // hence we have to resort to a full search. for (DataSchemaNode child : getChildNodes()) { if (child instanceof ChoiceSchemaNode) { for (CaseSchemaNode choiceCase : ((ChoiceSchemaNode) child).getCases().values()) { final Optional<DataSchemaNode> caseChild = choiceCase.findDataTreeChild(name); if (caseChild.isPresent()) { return caseChild; } } } } return Optional.empty(); }
/** * Returns a {@code data node} identified by a QName. This method is distinct from * {@link #findDataChildByName(QName)} in that it skips over {@link ChoiceSchemaNode}s and {@link CaseSchemaNode}s, * hence mirroring layout of the {@code data tree}, not {@code schema tree}. * * @param name QName identifier of the data node * @return Direct or indirect child of this DataNodeContainer which is a {@code data node}, empty otherwise * @throws NullPointerException if {@code name} is null */ @Beta default Optional<DataSchemaNode> findDataTreeChild(final QName name) { // First we try to find a direct child and check if it is a data node (as per RFC7950) final Optional<DataSchemaNode> optDataChild = findDataChildByName(name); if (HelperMethods.isDataNode(optDataChild)) { return optDataChild; } // There either is no such node present, or there are Choice/CaseSchemaNodes with the same name involved, // hence we have to resort to a full search. for (DataSchemaNode child : getChildNodes()) { if (child instanceof ChoiceSchemaNode) { for (CaseSchemaNode choiceCase : ((ChoiceSchemaNode) child).getCases().values()) { final Optional<DataSchemaNode> caseChild = choiceCase.findDataTreeChild(name); if (caseChild.isPresent()) { return caseChild; } } } } return Optional.empty(); }