Add DataNodeContainer.dataChildByName()
[yangtools.git] / yang / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / api / ChoiceSchemaNode.java
index 0e472fec97d561ad1df5de89245a294d82b85e77..6d7a0bd1d96682b61a480c7e2a59254691b5da72 100644 (file)
@@ -11,16 +11,18 @@ import static java.util.Objects.requireNonNull;
 
 import com.google.common.annotations.Beta;
 import com.google.common.collect.ImmutableList;
+import java.util.Collection;
 import java.util.List;
 import java.util.Optional;
-import java.util.SortedMap;
 import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.stmt.ChoiceEffectiveStatement;
 
 /**
  * A ChoiceSchemaNode defines a set of alternatives. It consists of a number of branches defined as
  * ChoiceCaseSchemaNode objects.
  */
-public interface ChoiceSchemaNode extends DataSchemaNode, AugmentationTarget, MandatoryAware {
+public interface ChoiceSchemaNode extends DataSchemaNode, AugmentationTarget, MandatoryAware,
+        EffectiveStatementEquivalent<ChoiceEffectiveStatement> {
     /**
      * Returns cases of choice, keyed by their {@link SchemaNode#getQName()}. Returned map does not contain null keys
      * nor values.
@@ -28,7 +30,7 @@ public interface ChoiceSchemaNode extends DataSchemaNode, AugmentationTarget, Ma
      * @return set of ChoiceCaseNode objects defined in this node which represents set of arguments of the YANG
      *         <code>case</code> substatement of the <code>choice</code> statement.
      */
-    SortedMap<QName, CaseSchemaNode> getCases();
+    Collection<? extends CaseSchemaNode> getCases();
 
     /**
      * Returns the concrete case according to specified Q name.
@@ -38,8 +40,9 @@ public interface ChoiceSchemaNode extends DataSchemaNode, AugmentationTarget, Ma
      * @return child case node of this Choice if child with given name is present, empty otherwise.
      * @throws NullPointerException if qname is null
      */
-    default Optional<CaseSchemaNode> findCase(final QName qname) {
-        return Optional.ofNullable(getCases().get(requireNonNull(qname)));
+    default Optional<? extends CaseSchemaNode> findCase(final QName qname) {
+        requireNonNull(qname);
+        return getCases().stream().filter(node -> qname.equals(node.getQName())).findFirst();
     }
 
     /**
@@ -51,8 +54,8 @@ public interface ChoiceSchemaNode extends DataSchemaNode, AugmentationTarget, Ma
      * @throws NullPointerException if localname is null
      */
     @Beta
-    default List<CaseSchemaNode> findCaseNodes(final String localname) {
-        return getCases().values().stream().filter(node -> localname.equals(node.getQName().getLocalName()))
+    default List<? extends CaseSchemaNode> findCaseNodes(final String localname) {
+        return getCases().stream().filter(node -> localname.equals(node.getQName().getLocalName()))
                 .collect(ImmutableList.toImmutableList());
     }
 
@@ -68,7 +71,7 @@ public interface ChoiceSchemaNode extends DataSchemaNode, AugmentationTarget, Ma
     @Beta
     default Optional<DataSchemaNode> findDataSchemaChild(final QName qname) {
         requireNonNull(qname);
-        for (CaseSchemaNode caseNode : getCases().values()) {
+        for (CaseSchemaNode caseNode : getCases()) {
             final Optional<DataSchemaNode> child = caseNode.findDataChildByName(qname);
             if (child.isPresent()) {
                 return child;
@@ -78,20 +81,6 @@ public interface ChoiceSchemaNode extends DataSchemaNode, AugmentationTarget, Ma
         return Optional.empty();
     }
 
-    /**
-     * Returns the concrete case according to specified QName.
-     *
-     * @param qname
-     *            QName of sought Choice Case Node
-     * @return child case node of this Choice if child with given name is present, <code>null</code> otherwise.
-     *
-     * @deprecated Use either {@code getCases().get(name)} or #findCase(QName)
-     */
-    @Deprecated
-    default CaseSchemaNode getCaseNodeByName(final QName qname) {
-        return getCases().get(qname);
-    }
-
     /**
      * Returns name of case which is in the choice specified as default.
      *