Update ChoiceSchemaNode design 52/64852/12
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 28 Oct 2017 14:54:46 +0000 (16:54 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 3 Nov 2017 10:56:32 +0000 (11:56 +0100)
ChoiceCaseSchemaNodes have unique QName, which how the only implementation
keeps track of them, hence they should be exposed as a SortedMap keyed by
QName.

This renders getCaseNodeByName() obsolete, as there are better ways of
getting the same result.

Change-Id: Ia52b6d22b3df66546a3ead7addcfd1aba9b0b6a5
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
33 files changed:
yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/JsonParserStream.java
yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/NormalizedNodeXmlTranslationTest.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/SchemaTracker.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/leafref/LeafRefContextTreeBuilder.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToCompositeNodes.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToNodes.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/SchemaOrderedNormalizedNodeWriter.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/SchemaUtils.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ChoiceModificationStrategy.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/NormalizedDataBuilderTest.java
yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/ChoiceNodeContextNode.java
yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/DataSchemaContextNode.java
yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/ParserStreamUtils.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/ChoiceSchemaNode.java
yang/yang-model-export/src/main/java/org/opendaylight/yangtools/yang/model/export/SchemaContextEmitter.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/DataNodeIterator.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtil.java
yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/DataNodeIteratorTest.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ChoiceEffectiveStatementImpl.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/util/SchemaContextUtilTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentProcessTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/CaseStmtTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ChoiceStmtTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ControllerStmtParserTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/DeviationResolutionTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/GroupingTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/TestUtils.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileChoiceStmtTest.java
yang/yang-parser-impl/src/test/resources/model/subfoo.yang
yang/yang-parser-impl/src/test/resources/rfc7950/model/subfoo.yang
yang/yang-parser-impl/src/test/resources/semantic-statement-parser/model/subfoo.yang

index 8c42de6c8884882dd872b10e1aa687fe0366b4a2..c9251e59c1476e105a899413d2a60dc78042dfa2 100644 (file)
@@ -353,7 +353,7 @@ public final class JsonParserStream implements Closeable, Flushable {
             }
 
             for (final ChoiceSchemaNode choiceNode : choices) {
-                for (final ChoiceCaseNode concreteCase : choiceNode.getCases()) {
+                for (final ChoiceCaseNode concreteCase : choiceNode.getCases().values()) {
                     potentialUris.addAll(resolveAllPotentialNamespaces(elementName, concreteCase));
                 }
             }
index d070482441aa56db26ef1623f017da71355bc222..e3040bcb71dfe5d8dcf95ddde0cc68b6aa1f728d 100644 (file)
@@ -21,12 +21,10 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.StringWriter;
 import java.net.URI;
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import javax.xml.stream.XMLInputFactory;
@@ -70,6 +68,7 @@ import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNo
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeBuilder;
+import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
@@ -352,7 +351,7 @@ public class NormalizedNodeXmlTranslationTest {
                                                final String childNodeName) {
         for (Module module : context.getModules()) {
             if (module.getName().equals(moduleName)) {
-                DataSchemaNode found = findChildNode(module.getChildNodes(), childNodeName);
+                DataSchemaNode found = findChildNode(module, childNodeName);
                 checkState(found != null, "Unable to find %s", childNodeName);
                 return found;
             }
@@ -360,27 +359,26 @@ public class NormalizedNodeXmlTranslationTest {
         throw new IllegalStateException("Unable to find child node " + childNodeName);
     }
 
-    private static DataSchemaNode findChildNode(final Iterable<DataSchemaNode> children, final String name) {
-        List<DataNodeContainer> containers = new ArrayList<>();
-
-        for (DataSchemaNode dataSchemaNode : children) {
+    // FIXME: duplicate of NormalizedDataBuilderTest.findChildNode()
+    private static DataSchemaNode findChildNode(final DataNodeContainer container, final String name) {
+        for (DataSchemaNode dataSchemaNode : container.getChildNodes()) {
             if (dataSchemaNode.getQName().getLocalName().equals(name)) {
                 return dataSchemaNode;
             }
             if (dataSchemaNode instanceof DataNodeContainer) {
-                containers.add((DataNodeContainer) dataSchemaNode);
+                DataSchemaNode retVal = findChildNode((DataNodeContainer) dataSchemaNode, name);
+                if (retVal != null) {
+                    return retVal;
+                }
             } else if (dataSchemaNode instanceof ChoiceSchemaNode) {
-                containers.addAll(((ChoiceSchemaNode) dataSchemaNode).getCases());
+                for (ChoiceCaseNode caseNode : ((ChoiceSchemaNode) dataSchemaNode).getCases().values()) {
+                    DataSchemaNode retVal = findChildNode(caseNode, name);
+                    if (retVal != null) {
+                        return retVal;
+                    }
+                }
             }
         }
-
-        for (DataNodeContainer container : containers) {
-            DataSchemaNode retVal = findChildNode(container.getChildNodes(), name);
-            if (retVal != null) {
-                return retVal;
-            }
-        }
-
         return null;
     }
 
index 4fb46dcd3e558449abe86f4627c06a28b9b58a5e..24ec5b99483db627bb501e193e939fa9babf620a 100644 (file)
@@ -121,7 +121,7 @@ public final class SchemaTracker {
 
     private static SchemaNode findChildInCases(final ChoiceSchemaNode parent, final QName qname) {
         DataSchemaNode schema = null;
-        for (final ChoiceCaseNode caze : parent.getCases()) {
+        for (final ChoiceCaseNode caze : parent.getCases().values()) {
             final DataSchemaNode potential = caze.getDataChildByName(qname);
             if (potential != null) {
                 schema = potential;
@@ -133,7 +133,7 @@ public final class SchemaTracker {
 
     private static SchemaNode findCaseByChild(final ChoiceSchemaNode parent, final QName qname) {
         DataSchemaNode schema = null;
-        for (final ChoiceCaseNode caze : parent.getCases()) {
+        for (final ChoiceCaseNode caze : parent.getCases().values()) {
             final DataSchemaNode potential = caze.getDataChildByName(qname);
             if (potential != null) {
                 schema = caze;
index f8265bed56cbd4df1bb011b9e785c146922c54bb..ddda315c076b02e991ae311b29bdaf761929ac99 100644 (file)
@@ -102,10 +102,8 @@ class LeafRefContextTreeBuilder {
         } else if (node instanceof ChoiceSchemaNode) {
 
             final ChoiceSchemaNode choice = (ChoiceSchemaNode) node;
-            final Set<ChoiceCaseNode> cases = choice.getCases();
             // :FIXME choice without case
-
-            for (final ChoiceCaseNode caseNode : cases) {
+            for (final ChoiceCaseNode caseNode : choice.getCases().values()) {
                 final LeafRefContext childLeafRefContext = buildLeafRefContextReferencingTree(
                         caseNode, currentModule);
 
@@ -182,32 +180,21 @@ class LeafRefContextTreeBuilder {
                 }
             }
         } else if (node instanceof ChoiceSchemaNode) {
+            for (final ChoiceCaseNode caseNode : ((ChoiceSchemaNode) node).getCases().values()) {
+                final LeafRefContext childLeafRefContext = buildLeafRefContextReferencedByTree(caseNode, currentModule);
 
-            final ChoiceSchemaNode choice = (ChoiceSchemaNode) node;
-            final Set<ChoiceCaseNode> cases = choice.getCases();
-
-            for (final ChoiceCaseNode caseNode : cases) {
-                final LeafRefContext childLeafRefContext = buildLeafRefContextReferencedByTree(
-                        caseNode, currentModule);
-
-                if (childLeafRefContext.hasReferencedChild()
-                        || childLeafRefContext.isReferenced()) {
-                    currentLeafRefContextBuilder.addReferencedByChild(
-                            childLeafRefContext,
-                            childLeafRefContext.getNodeName());
+                if (childLeafRefContext.hasReferencedChild() || childLeafRefContext.isReferenced()) {
+                    currentLeafRefContextBuilder.addReferencedByChild(childLeafRefContext,
+                        childLeafRefContext.getNodeName());
                 }
             }
 
-        } else if (node instanceof LeafSchemaNode
-                || node instanceof LeafListSchemaNode) {
-
-            final List<LeafRefContext> foundLeafRefs = getLeafRefsFor(node,
-                    currentModule);
+        } else if (node instanceof LeafSchemaNode || node instanceof LeafListSchemaNode) {
+            final List<LeafRefContext> foundLeafRefs = getLeafRefsFor(node, currentModule);
             if (!foundLeafRefs.isEmpty()) {
                 currentLeafRefContextBuilder.setReferencedBy(true);
                 for (final LeafRefContext leafRef : foundLeafRefs) {
-                    currentLeafRefContextBuilder.addReferencedByLeafRefCtx(
-                            leafRef.getNodeName(), leafRef);
+                    currentLeafRefContextBuilder.addReferencedByLeafRefCtx(leafRef.getNodeName(), leafRef);
                 }
             }
         }
index cf5e2a16d023fe9220eb350bc154ad95857837a3..f891cda0b7d24a7ab3830f0d4f88959f385c5ff5 100644 (file)
@@ -330,7 +330,7 @@ abstract class InstanceIdToCompositeNodes<T extends PathArgument> extends Instan
             super(NodeIdentifier.create(schema.getQName()));
             final ImmutableMap.Builder<PathArgument, InstanceIdToNodes<?>> byArgBuilder = ImmutableMap.builder();
 
-            for (final ChoiceCaseNode caze : schema.getCases()) {
+            for (final ChoiceCaseNode caze : schema.getCases().values()) {
                 for (final DataSchemaNode cazeChild : caze.getChildNodes()) {
                     final InstanceIdToNodes<?> childOp = fromDataSchemaNode(cazeChild);
                     byArgBuilder.put(childOp.getIdentifier(), childOp);
index a4ddcc41a9efc753dba3e93f3cf7520a1da2ae96..471d8b07e482c296fcd4504d961a8f98ebdd2164 100644 (file)
@@ -179,7 +179,7 @@ abstract class InstanceIdToNodes<T extends PathArgument> implements Identifiable
         ChoiceSchemaNode foundChoice = null;
         choiceLoop:
         for (final ChoiceSchemaNode choice : choices) {
-            for (final ChoiceCaseNode caze : choice.getCases()) {
+            for (final ChoiceCaseNode caze : choice.getCases().values()) {
                 if (findChildSchemaNode(caze, child).isPresent()) {
                     foundChoice = choice;
                     break choiceLoop;
index 186d88c55dcbb9b1f5cff5840b4e364e057b152b..fb4033140dc61aa173586f8e24c0f9d1ec824b1b 100644 (file)
@@ -146,7 +146,7 @@ public class SchemaOrderedNormalizedNodeWriter extends NormalizedNodeWriter {
                 }
             }
         } else if (parentSchemaNode instanceof ChoiceSchemaNode) {
-            for (final ChoiceCaseNode ccNode : ((ChoiceSchemaNode) parentSchemaNode).getCases()) {
+            for (final ChoiceCaseNode ccNode : ((ChoiceSchemaNode) parentSchemaNode).getCases().values()) {
                 for (final DataSchemaNode dsn : ccNode.getChildNodes()) {
                     if (qNameToNodes.containsKey(dsn.getQName())) {
                         write(qNameToNodes.get(dsn.getQName()), dsn);
index 5e9546c02a3301674f38e02634846fe17a8e43b5..b1bd57459d768e84de4a5906d0c45ff733317392 100644 (file)
@@ -65,7 +65,7 @@ public final class SchemaUtils {
                         schema = dsn;
                     }
                 } else if (dsn instanceof ChoiceSchemaNode) {
-                    for (final ChoiceCaseNode choiceCase : ((ChoiceSchemaNode) dsn).getCases()) {
+                    for (final ChoiceCaseNode choiceCase : ((ChoiceSchemaNode) dsn).getCases().values()) {
 
                         final DataSchemaNode dataChildByName = choiceCase.getDataChildByName(qname);
                         if (dataChildByName != null) {
@@ -120,7 +120,7 @@ public final class SchemaUtils {
     }
 
     public static DataSchemaNode findSchemaForChild(final ChoiceSchemaNode schema, final QName childPartialQName) {
-        for (final ChoiceCaseNode choiceCaseNode : schema.getCases()) {
+        for (final ChoiceCaseNode choiceCaseNode : schema.getCases().values()) {
             final Optional<DataSchemaNode> childSchema = findFirstSchema(childPartialQName,
                 choiceCaseNode.getChildNodes());
             if (childSchema.isPresent()) {
@@ -142,7 +142,7 @@ public final class SchemaUtils {
     }
 
     public static AugmentationSchemaNode findSchemaForAugment(final ChoiceSchemaNode schema, final Set<QName> qnames) {
-        for (final ChoiceCaseNode choiceCaseNode : schema.getCases()) {
+        for (final ChoiceCaseNode choiceCaseNode : schema.getCases().values()) {
             final Optional<AugmentationSchemaNode> schemaForAugment = findAugment(choiceCaseNode, qnames);
             if (schemaForAugment.isPresent()) {
                 return schemaForAugment.get();
@@ -188,7 +188,7 @@ public final class SchemaUtils {
                     continue;
                 }
 
-                for (final ChoiceCaseNode choiceCaseNode : ((ChoiceSchemaNode) childSchema).getCases()) {
+                for (final ChoiceCaseNode choiceCaseNode : ((ChoiceSchemaNode) childSchema).getCases().values()) {
                     for (final QName qname : getChildNodesRecursive(choiceCaseNode)) {
                         mappedChoices.put(qname, (ChoiceSchemaNode) childSchema);
                     }
@@ -249,7 +249,7 @@ public final class SchemaUtils {
                         childNodesToAugmentation.put(qname, mostTopAugmentation);
                     }
                 } else if (child instanceof ChoiceSchemaNode) {
-                    for (final ChoiceCaseNode choiceCaseNode : ((ChoiceSchemaNode) child).getCases()) {
+                    for (final ChoiceCaseNode choiceCaseNode : ((ChoiceSchemaNode) child).getCases().values()) {
                         for (final QName qname : getChildNodesRecursive(choiceCaseNode)) {
                             childNodesToAugmentation.put(qname, mostTopAugmentation);
                         }
@@ -262,7 +262,7 @@ public final class SchemaUtils {
 
         // Choice Node has to map child nodes from all its cases
         if (schema instanceof ChoiceSchemaNode) {
-            for (final ChoiceCaseNode choiceCaseNode : ((ChoiceSchemaNode) schema).getCases()) {
+            for (final ChoiceCaseNode choiceCaseNode : ((ChoiceSchemaNode) schema).getCases().values()) {
                 if (!augments.containsKey(choiceCaseNode.getQName())) {
                     continue;
                 }
@@ -287,7 +287,7 @@ public final class SchemaUtils {
 
         for (final DataSchemaNode childSchema : nodeContainer.getChildNodes()) {
             if (childSchema instanceof ChoiceSchemaNode) {
-                for (final ChoiceCaseNode choiceCaseNode : ((ChoiceSchemaNode) childSchema).getCases()) {
+                for (final ChoiceCaseNode choiceCaseNode : ((ChoiceSchemaNode) childSchema).getCases().values()) {
                     allChildNodes.addAll(getChildNodesRecursive(choiceCaseNode));
                 }
             } else if (childSchema instanceof AugmentationSchemaNode || childSchema instanceof ChoiceCaseNode) {
@@ -322,7 +322,7 @@ public final class SchemaUtils {
         final Set<DataSchemaNode> realChildNodes = new HashSet<>();
         if (targetSchema instanceof ChoiceSchemaNode) {
             for (final DataSchemaNode dataSchemaNode : augmentSchema.getChildNodes()) {
-                for (final ChoiceCaseNode choiceCaseNode : ((ChoiceSchemaNode) targetSchema).getCases()) {
+                for (final ChoiceCaseNode choiceCaseNode : ((ChoiceSchemaNode) targetSchema).getCases().values()) {
                     if (getChildNodesRecursive(choiceCaseNode).contains(dataSchemaNode.getQName())) {
                         realChildNodes.add(choiceCaseNode.getDataChildByName(dataSchemaNode.getQName()));
                     }
@@ -345,7 +345,7 @@ public final class SchemaUtils {
 
     public static Optional<ChoiceCaseNode> detectCase(final ChoiceSchemaNode schema,
             final DataContainerChild<?, ?> child) {
-        for (final ChoiceCaseNode choiceCaseNode : schema.getCases()) {
+        for (final ChoiceCaseNode choiceCaseNode : schema.getCases().values()) {
             if (child instanceof AugmentationNode
                     && belongsToCaseAugment(choiceCaseNode, (AugmentationIdentifier) child.getIdentifier())) {
                 return Optional.of(choiceCaseNode);
index 338b93eb0e18eb1273075f6574e934309db0a77d..bc03a63eed18ae087c6b6f82ea609ee867e63d03 100644 (file)
@@ -49,7 +49,7 @@ final class ChoiceModificationStrategy extends AbstractNodeContainerModification
 
         final Builder<PathArgument, ModificationApplyOperation> childBuilder = ImmutableMap.builder();
         final Builder<PathArgument, CaseEnforcer> enforcerBuilder = ImmutableMap.builder();
-        for (final ChoiceCaseNode caze : schemaNode.getCases()) {
+        for (final ChoiceCaseNode caze : schemaNode.getCases().values()) {
             final CaseEnforcer enforcer = CaseEnforcer.forTree(caze, treeConfig);
             if (enforcer != null) {
                 for (final Entry<NodeIdentifier, DataSchemaNode> e : enforcer.getChildEntries()) {
index f81f5954659985bd93423c8fca36f9aa416911d6..ca57bc31fd778b4ea6e5bd25dce3520de51ee571 100644 (file)
@@ -13,9 +13,7 @@ import java.io.File;
 import java.io.FileNotFoundException;
 import java.net.URI;
 import java.net.URISyntaxException;
-import java.util.ArrayList;
 import java.util.Collections;
-import java.util.List;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -34,6 +32,7 @@ import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContaine
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableChoiceNodeSchemaAwareBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapNodeSchemaAwareBuilder;
 import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
@@ -194,7 +193,7 @@ public class NormalizedDataBuilderTest {
             final String childNodeName) {
         for (Module module : context.getModules()) {
             if (module.getName().equals(moduleName)) {
-                DataSchemaNode found = findChildNode(module.getChildNodes(), childNodeName);
+                DataSchemaNode found = findChildNode(module, childNodeName);
                 checkState(found != null, "Unable to find %s", childNodeName);
                 return found;
             }
@@ -202,27 +201,25 @@ public class NormalizedDataBuilderTest {
         throw new IllegalStateException("Unable to find child node " + childNodeName);
     }
 
-    private static DataSchemaNode findChildNode(final Iterable<DataSchemaNode> children, final String name) {
-        List<DataNodeContainer> containers = new ArrayList<>();
-
-        for (DataSchemaNode dataSchemaNode : children) {
+    private static DataSchemaNode findChildNode(final DataNodeContainer container, final String name) {
+        for (DataSchemaNode dataSchemaNode : container.getChildNodes()) {
             if (dataSchemaNode.getQName().getLocalName().equals(name)) {
                 return dataSchemaNode;
             }
             if (dataSchemaNode instanceof DataNodeContainer) {
-                containers.add((DataNodeContainer) dataSchemaNode);
+                DataSchemaNode retVal = findChildNode((DataNodeContainer) dataSchemaNode, name);
+                if (retVal != null) {
+                    return retVal;
+                }
             } else if (dataSchemaNode instanceof ChoiceSchemaNode) {
-                containers.addAll(((ChoiceSchemaNode) dataSchemaNode).getCases());
+                for (ChoiceCaseNode caseNode : ((ChoiceSchemaNode) dataSchemaNode).getCases().values()) {
+                    DataSchemaNode retVal = findChildNode(caseNode, name);
+                    if (retVal != null) {
+                        return retVal;
+                    }
+                }
             }
         }
-
-        for (DataNodeContainer container : containers) {
-            DataSchemaNode retVal = findChildNode(container.getChildNodes(), name);
-            if (retVal != null) {
-                return retVal;
-            }
-        }
-
         return null;
     }
 }
index e21265581907a593d4c9639a288809e67e314653..27bacac5299206fef5670881a455e3062af6d9e1 100644 (file)
@@ -25,7 +25,7 @@ class ChoiceNodeContextNode extends AbstractMixinContextNode<NodeIdentifier> {
         ImmutableMap.Builder<QName, DataSchemaContextNode<?>> byQNameBuilder = ImmutableMap.builder();
         ImmutableMap.Builder<PathArgument, DataSchemaContextNode<?>> byArgBuilder = ImmutableMap.builder();
 
-        for (ChoiceCaseNode caze : schema.getCases()) {
+        for (ChoiceCaseNode caze : schema.getCases().values()) {
             for (DataSchemaNode cazeChild : caze.getChildNodes()) {
                 DataSchemaContextNode<?> childOp = fromDataSchemaNode(cazeChild);
                 byArgBuilder.put(childOp.getIdentifier(), childOp);
index 07ce69fff6a509f3ee4c51edd726fc70bfe33ef5..336ab56e942aa3857dd8a36267d0244f449def52 100644 (file)
@@ -97,23 +97,23 @@ public abstract class DataSchemaContextNode<T extends PathArgument> implements I
     static DataSchemaContextNode<?> fromSchemaAndQNameChecked(final DataNodeContainer schema, final QName child) {
         DataSchemaNode result = findChildSchemaNode(schema, child);
         // We try to look up if this node was added by augmentation
-        if (result != null && (schema instanceof DataSchemaNode) && result.isAugmenting()) {
+        if (result != null && schema instanceof DataSchemaNode && result.isAugmenting()) {
             return fromAugmentation(schema, (AugmentationTarget) schema, result);
         }
         return fromDataSchemaNode(result);
     }
 
+    // FIXME: this looks like it should be a Predicate on a stream with findFirst()
     private static ChoiceSchemaNode findChoice(final Iterable<ChoiceSchemaNode> choices, final QName child) {
-        ChoiceSchemaNode foundChoice = null;
-        choiceLoop: for (ChoiceSchemaNode choice : choices) {
-            for (ChoiceCaseNode caze : choice.getCases()) {
+        for (ChoiceSchemaNode choice : choices) {
+            // FIXME: this looks weird: what are we looking for again?
+            for (ChoiceCaseNode caze : choice.getCases().values()) {
                 if (findChildSchemaNode(caze, child) != null) {
-                    foundChoice = choice;
-                    break choiceLoop;
+                    return choice;
                 }
             }
         }
-        return foundChoice;
+        return null;
     }
 
     public static AugmentationIdentifier augmentationIdentifierFrom(final AugmentationSchemaNode augmentation) {
index e2372c2f1a40745d1cec3ad55b65b5ef5afd450a..b9c17416fc7c403dbde167e156eb19a5c807e8e1 100644 (file)
@@ -62,7 +62,7 @@ public final class ParserStreamUtils {
 
         // try to find data schema node in choice (looking for first match)
         for (final ChoiceSchemaNode choiceNode : childChoices) {
-            for (final ChoiceCaseNode concreteCase : choiceNode.getCases()) {
+            for (final ChoiceCaseNode concreteCase : choiceNode.getCases().values()) {
                 final Deque<DataSchemaNode> resultFromRecursion = findSchemaNodeByNameAndNamespace(concreteCase,
                         childName, namespace);
                 if (!resultFromRecursion.isEmpty()) {
index 0da6676886132a9ba0bcc91a0b39b37fa8f16ab4..073b25c6c7d515efd5efcf2b29ea249cf56ff7e7 100644 (file)
@@ -7,50 +7,96 @@
  */
 package org.opendaylight.yangtools.yang.model.api;
 
-import java.util.Set;
+import static java.util.Objects.requireNonNull;
+
+import com.google.common.annotations.Beta;
+import com.google.common.collect.ImmutableList;
+import java.util.List;
+import java.util.Optional;
+import java.util.SortedMap;
 import org.opendaylight.yangtools.yang.common.QName;
 
 /**
- * A ChoiceSchemaNode defines a set of alternatives. It consists of a number of
- * branches defined as ChoiceCaseSchemaNode objects.
+ * A ChoiceSchemaNode defines a set of alternatives. It consists of a number of branches defined as
+ * ChoiceCaseSchemaNode objects.
  */
 public interface ChoiceSchemaNode extends DataSchemaNode, AugmentationTarget {
     /**
-     * Returns cases of choice.
+     * Returns cases of choice, keyed by their {@link SchemaNode#getQName()}. Returned map does not contain null keys
+     * nor values.
      *
-     * @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
+     * @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.
      */
-    Set<ChoiceCaseNode> getCases();
+    SortedMap<QName, ChoiceCaseNode> getCases();
 
     /**
      * Returns the concrete case according to specified Q name.
      *
-     * @param name
-     *            QName of seeked Choice Case Node
-     * @return child case node of this Choice if child with given name is
-     *         present, <code>null</code> otherwise
+     * @param qname
+     *            QName of sought Choice Case Node
+     * @return child case node of this Choice if child with given name is present, empty otherwise.
+     * @throws NullPointerException if qname is null
      */
-    ChoiceCaseNode getCaseNodeByName(QName name);
+    default Optional<ChoiceCaseNode> findCase(final QName qname) {
+        return Optional.ofNullable(getCases().get(requireNonNull(qname)));
+    }
 
     /**
-     * Returns the concrete case according to specified name.
+     * Returns the concrete cases according to specified name, disregarding their namespace.
      *
-     * @param name
-     *            name of seeked child as String
-     * @return child case node (or local name of case node) of this Choice if
-     *         child with given name is present, <code>null</code> otherwise
+     * @param localname
+     *            local name of sought child as String
+     * @return child case nodes matching specified local name, empty list if no match is found.
+     * @throws NullPointerException if localname is null
      */
-    ChoiceCaseNode getCaseNodeByName(String name);
+    @Beta
+    default List<ChoiceCaseNode> findCaseNodes(final String localname) {
+        return getCases().values().stream().filter(node -> localname.equals(node.getQName().getLocalName()))
+                .collect(ImmutableList.toImmutableList());
+    }
 
     /**
-     * Returns name of case which is in the choice specified as default.
+     * Find a specific data schema child, if present. This method searches among its {@link ChoiceCaseNode}s,
+     * potentially recursing to nested choices.
+     *
+     * @param qname
+     *            QName of sought data schema node
+     * @return Matching node, or empty if no match is found
+     * @throws NullPointerException if qname is null
+     */
+    @Beta
+    default Optional<DataSchemaNode> findDataSchemaChild(final QName qname) {
+        requireNonNull(qname);
+        for (ChoiceCaseNode caseNode : getCases().values()) {
+            final Optional<DataSchemaNode> child = caseNode.findDataChildByName(qname);
+            if (child.isPresent()) {
+                return child;
+            }
+        }
+
+        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.
      *
-     * @return string with the name of case which is specified in the argument
-     *         of the YANG <code>default</code> substatement of
-     *         <code>choice</code> statement.
+     * @deprecated Use either {@code getCases().get(name)} or #findCase(QName)
      */
-    String getDefaultCase();
+    @Deprecated
+    default ChoiceCaseNode getCaseNodeByName(final QName qname) {
+        return getCases().get(qname);
+    }
 
+    /**
+     * Returns name of case which is in the choice specified as default.
+     *
+     * @return string with the name of case which is specified in the argument of the YANG <code>default</code>
+     *         substatement of <code>choice</code> statement.
+     */
+    Optional<ChoiceCaseNode> getDefaultCase();
 }
index efd936bf1622301293014d4583d85f25a49c4718..7f8172df969b268e4c55d7979a8732a43be6a047 100644 (file)
@@ -1875,7 +1875,7 @@ abstract class SchemaContextEmitter {
             emitConfigNode(choice.isConfiguration());
             emitMandatoryNode(choice.getConstraints().isMandatory());
             emitDocumentedNode(choice);
-            for (final ChoiceCaseNode caze : choice.getCases()) {
+            for (final ChoiceCaseNode caze : choice.getCases().values()) {
                 // TODO: emit short case?
                 emitCaseNode(caze);
             }
index 1c7543cf322d7e286cd00828b635ca54180d4334..55433e2ba95b0cb6c54f336e4c558a6767f6e78d 100644 (file)
@@ -125,11 +125,8 @@ public class DataNodeIterator implements Iterator<DataSchemaNode> {
                 } else if (childNode instanceof ChoiceSchemaNode) {
                     final ChoiceSchemaNode choiceNode = (ChoiceSchemaNode) childNode;
                     allChoices.add(choiceNode);
-                    final Set<ChoiceCaseNode> cases = choiceNode.getCases();
-                    if (cases != null) {
-                        for (final ChoiceCaseNode caseNode : cases) {
-                            traverse(caseNode);
-                        }
+                    for (final ChoiceCaseNode caseNode : choiceNode.getCases().values()) {
+                        traverse(caseNode);
                     }
                 }
             }
@@ -183,7 +180,7 @@ public class DataNodeIterator implements Iterator<DataSchemaNode> {
         if (container.getChildNodes() != null) {
             final Collection<DataSchemaNode> childNodes = container.getChildNodes();
 
-            if ((childNodes != null) && !childNodes.isEmpty()) {
+            if (childNodes != null && !childNodes.isEmpty()) {
                 return childNodes.iterator().hasNext();
             }
         }
index 650ab65e6342004d1a8105522af25b1143965a2c..06ae0d090faf05c41b0a53e9deb303af5bdfd622 100644 (file)
@@ -424,7 +424,7 @@ public final class SchemaContextUtil {
 
             if (foundNode == null) {
                 // fallback that tries to map into one of the child cases
-                for (final ChoiceCaseNode caseNode : ((ChoiceSchemaNode) parent).getCases()) {
+                for (final ChoiceCaseNode caseNode : ((ChoiceSchemaNode) parent).getCases().values()) {
                     final DataSchemaNode maybeChild = caseNode.getDataChildByName(current);
                     if (maybeChild != null) {
                         foundNode = findNodeIn(maybeChild, nextPath);
index 8bcc5345a359a5663b86cf13eaa90097107f113c..65321570fde1e1e0c001f74fc65915bf275649db 100644 (file)
@@ -14,11 +14,14 @@ import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 
 import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableSortedMap;
 import java.util.Collections;
 import java.util.NoSuchElementException;
 import java.util.Set;
+import java.util.SortedMap;
 import org.junit.Before;
 import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
@@ -78,8 +81,11 @@ public class DataNodeIteratorTest {
 
         final ChoiceSchemaNode mockedChoice = mock(ChoiceSchemaNode.class);
         final ChoiceCaseNode mockedCase1 = mock(ChoiceCaseNode.class);
+        final QName mockedCase1QName = QName.create("", "case1");
         final ChoiceCaseNode mockedCase2 = mock(ChoiceCaseNode.class);
-        final Set<ChoiceCaseNode> cases = ImmutableSet.of(mockedCase1, mockedCase2);
+        final QName mockedCase2QName = QName.create("", "case2");
+        final SortedMap<QName, ChoiceCaseNode> cases = ImmutableSortedMap.of(mockedCase1QName, mockedCase1,
+            mockedCase2QName, mockedCase2);
         doReturn(cases).when(mockedChoice).getCases();
 
         final Set<DataSchemaNode> childNodes = ImmutableSet.of(mockedAugmentingContainer, mockedContainer, mockedList,
@@ -114,8 +120,8 @@ public class DataNodeIteratorTest {
         assertTrue(dataNodeIterator.allContainers().contains(mockedContainer));
         assertTrue(dataNodeIterator.allLists().contains(mockedList));
         assertTrue(dataNodeIterator.allChoices().contains(mockedChoice));
-        assertTrue(dataNodeIterator.allChoices().get(0).getCases().contains(mockedCase1));
-        assertTrue(dataNodeIterator.allChoices().get(0).getCases().contains(mockedCase2));
+        assertTrue(dataNodeIterator.allChoices().get(0).getCases().values().contains(mockedCase1));
+        assertTrue(dataNodeIterator.allChoices().get(0).getCases().values().contains(mockedCase2));
         assertTrue(dataNodeIterator.allContainers().contains(mockedContainerInNotification));
         assertTrue(dataNodeIterator.allLists().contains(mockedListInRpcInputContainer));
         assertTrue(dataNodeIterator.allGroupings().contains(mockedGrouping));
index a9360a61340009aeebbf838191f6913e014b6448..f76df175a8753cdd8c463783e02fd55dc8754e31 100644 (file)
@@ -7,14 +7,14 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
-import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableSortedMap;
 import java.util.LinkedHashSet;
 import java.util.Objects;
 import java.util.Optional;
 import java.util.Set;
-import java.util.SortedSet;
-import java.util.TreeSet;
+import java.util.SortedMap;
+import java.util.TreeMap;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
@@ -23,28 +23,27 @@ import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.ChoiceStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangValidationBundles;
 
 public final class ChoiceEffectiveStatementImpl extends AbstractEffectiveDataSchemaNode<ChoiceStatement> implements
         ChoiceSchemaNode, DerivableSchemaNode {
-    private final ChoiceSchemaNode original;
-    private final String defaultCase;
 
-    private final Set<ChoiceCaseNode> cases;
     private final Set<AugmentationSchemaNode> augmentations;
+    private final SortedMap<QName, ChoiceCaseNode> cases;
+    private final ChoiceCaseNode defaultCase;
+    private final ChoiceSchemaNode original;
 
     public ChoiceEffectiveStatementImpl(
             final StmtContext<QName, ChoiceStatement, EffectiveStatement<QName, ChoiceStatement>> ctx) {
         super(ctx);
         this.original = (ChoiceSchemaNode) ctx.getOriginalCtx().map(StmtContext::buildEffective).orElse(null);
 
-        final DefaultEffectiveStatementImpl defaultStmt = firstEffective(DefaultEffectiveStatementImpl.class);
-        this.defaultCase = defaultStmt == null ? null : defaultStmt.argument();
-
         // initSubstatementCollectionsAndFields
         final Set<AugmentationSchemaNode> augmentationsInit = new LinkedHashSet<>();
-        final SortedSet<ChoiceCaseNode> casesInit = new TreeSet<>((o1, o2) -> o1.getQName().compareTo(o2.getQName()));
+        final SortedMap<QName, ChoiceCaseNode> casesInit = new TreeMap<>();
 
         for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
             if (effectiveStatement instanceof AugmentationSchemaNode) {
@@ -53,12 +52,14 @@ public final class ChoiceEffectiveStatementImpl extends AbstractEffectiveDataSch
             }
             if (effectiveStatement instanceof ChoiceCaseNode) {
                 final ChoiceCaseNode choiceCaseNode = (ChoiceCaseNode) effectiveStatement;
-                casesInit.add(choiceCaseNode);
+                // FIXME: we may be overwriting a previous entry, is that really okay?
+                casesInit.put(choiceCaseNode.getQName(), choiceCaseNode);
             }
             if (YangValidationBundles.SUPPORTED_CASE_SHORTHANDS.contains(effectiveStatement.statementDefinition())) {
                 final DataSchemaNode dataSchemaNode = (DataSchemaNode) effectiveStatement;
                 final ChoiceCaseNode shorthandCase = new CaseShorthandImpl(dataSchemaNode);
-                casesInit.add(shorthandCase);
+                // FIXME: we may be overwriting a previous entry, is that really okay?
+                casesInit.put(shorthandCase.getQName(), shorthandCase);
                 if (dataSchemaNode.isAugmenting() && !this.augmenting) {
                     resetAugmenting(dataSchemaNode);
                 }
@@ -66,7 +67,24 @@ public final class ChoiceEffectiveStatementImpl extends AbstractEffectiveDataSch
         }
 
         this.augmentations = ImmutableSet.copyOf(augmentationsInit);
-        this.cases = ImmutableSet.copyOf(casesInit);
+        this.cases = ImmutableSortedMap.copyOfSorted(casesInit);
+
+        final DefaultEffectiveStatementImpl defaultStmt = firstEffective(DefaultEffectiveStatementImpl.class);
+        if (defaultStmt != null) {
+            final QName qname;
+            try {
+                qname = QName.create(getQName(), defaultStmt.argument());
+            } catch (IllegalArgumentException e) {
+                throw new SourceException(ctx.getStatementSourceReference(), "Default statement has invalid name '%s'",
+                    defaultStmt.argument(), e);
+            }
+
+            // FIXME: this does not work with submodules, as they are
+            defaultCase = InferenceException.throwIfNull(cases.get(qname), ctx.getStatementSourceReference(),
+                "Default statement refers to missing case %s", qname);
+        } else {
+            defaultCase = null;
+        }
     }
 
     private static void resetAugmenting(final DataSchemaNode dataSchemaNode) {
@@ -99,37 +117,13 @@ public final class ChoiceEffectiveStatementImpl extends AbstractEffectiveDataSch
     }
 
     @Override
-    public Set<ChoiceCaseNode> getCases() {
+    public SortedMap<QName, ChoiceCaseNode> getCases() {
         return cases;
     }
 
     @Override
-    public ChoiceCaseNode getCaseNodeByName(final QName name) {
-        Preconditions.checkArgument(name != null, "Choice Case QName cannot be NULL!");
-
-        for (final ChoiceCaseNode caseNode : cases) {
-            if (caseNode != null && name.equals(caseNode.getQName())) {
-                return caseNode;
-            }
-        }
-        return null;
-    }
-
-    @Override
-    public ChoiceCaseNode getCaseNodeByName(final String name) {
-        Preconditions.checkArgument(name != null, "Choice Case string Name cannot be NULL!");
-
-        for (final ChoiceCaseNode caseNode : cases) {
-            if (caseNode != null && caseNode.getQName() != null && name.equals(caseNode.getQName().getLocalName())) {
-                return caseNode;
-            }
-        }
-        return null;
-    }
-
-    @Override
-    public String getDefaultCase() {
-        return defaultCase;
+    public Optional<ChoiceCaseNode> getDefaultCase() {
+        return Optional.ofNullable(defaultCase);
     }
 
     @Override
index 51e4d9e50ecaff2af3fe972a3ae1609bd7d5119f..dcb9f2bdd30d9cd39e0c16dee13af6e810daa834 100644 (file)
@@ -153,7 +153,8 @@ public class SchemaContextUtilTest {
         assertEquals(testNode, foundNode);
 
         testNode = ((ChoiceSchemaNode) myModule
-                .getDataChildByName(QName.create(myModule.getQNameModule(), "my-choice"))).getCaseNodeByName("one")
+                .getDataChildByName(QName.create(myModule.getQNameModule(), "my-choice")))
+                .findCaseNodes("one").iterator().next()
                 .getDataChildByName(QName.create(myModule.getQNameModule(), "my-choice-leaf-one"));
 
         path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-choice"),
@@ -254,7 +255,8 @@ public class SchemaContextUtilTest {
         assertNull(foundNode);
 
         testNode = ((ChoiceSchemaNode) myModule
-                .getDataChildByName(QName.create(myModule.getQNameModule(), "my-choice"))).getCaseNodeByName("one")
+                .getDataChildByName(QName.create(myModule.getQNameModule(), "my-choice")))
+                .findCaseNodes("one").iterator().next()
                 .getDataChildByName(QName.create(myModule.getQNameModule(), "no-choice-leaf"));
 
         path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-choice"),
@@ -701,9 +703,10 @@ public class SchemaContextUtilTest {
         assertEquals(testNode, foundNode);
 
         // find grouping in case
-        dataContainer = (DataNodeContainer) ((ChoiceSchemaNode) myModule.getDataChildByName(QName.create(
-                myModule.getQNameModule(), "my-choice"))).getCaseNodeByName("one").getDataChildByName(
-                QName.create(myModule.getQNameModule(), "my-container-in-case"));
+        dataContainer = (DataNodeContainer) ((ChoiceSchemaNode) myModule.getDataChildByName(
+            QName.create(myModule.getQNameModule(), "my-choice")))
+                .findCaseNodes("one").iterator().next()
+                .getDataChildByName(QName.create(myModule.getQNameModule(), "my-container-in-case"));
         testNode = getGroupingByName(dataContainer, "my-grouping-in-case");
 
         path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-choice"),
@@ -824,9 +827,10 @@ public class SchemaContextUtilTest {
         assertNull(foundNode);
 
         // find grouping in case
-        dataContainer = (DataNodeContainer) ((ChoiceSchemaNode) myModule.getDataChildByName(QName.create(
-                myModule.getQNameModule(), "my-choice"))).getCaseNodeByName("one").getDataChildByName(
-                QName.create(myModule.getQNameModule(), "my-container-in-case"));
+        dataContainer = (DataNodeContainer) ((ChoiceSchemaNode) myModule.getDataChildByName(
+            QName.create(myModule.getQNameModule(), "my-choice")))
+                .findCaseNodes("one").iterator().next()
+                .getDataChildByName(QName.create(myModule.getQNameModule(), "my-container-in-case"));
         testNode = getGroupingByName(dataContainer, "my-grouping-in-case2");
 
         path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-choice"),
@@ -876,8 +880,8 @@ public class SchemaContextUtilTest {
         final Module myModule = context.findModule(new URI("uri:my-module"), Revision.of("2014-10-07")).get();
         final ChoiceSchemaNode choice = (ChoiceSchemaNode) getRpcByName(myModule, "my-name").getInput()
                 .getDataChildByName(QName.create(myModule.getQNameModule(), "my-choice"));
-        final SchemaNode testNode = choice.getCaseNodeByName("case-two").getDataChildByName(
-                QName.create(myModule.getQNameModule(), "two"));
+        final SchemaNode testNode = choice.findCaseNodes("case-two").iterator().next()
+                .getDataChildByName(QName.create(myModule.getQNameModule(), "two"));
 
         final SchemaPath path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-name"),
                 QName.create(myModule.getQNameModule(), "input"), QName.create(myModule.getQNameModule(), "my-choice"),
index 7f66b542349296c3cad85560362420e06f776d24..9f96a0f26c50839879d380dc092b2a41a26d6e87 100644 (file)
@@ -200,7 +200,7 @@ public class AugmentProcessTest {
         final ChoiceSchemaNode lockType = (ChoiceSchemaNode) locks.getDataChildByName(QName
                 .create(ns, rev, "lock-type"));
 
-        final ChoiceCaseNode leafAugCase = lockType.getCaseNodeByName("leaf-aug-case");
+        final ChoiceCaseNode leafAugCase = lockType.findCaseNodes("leaf-aug-case").iterator().next();
         assertTrue(leafAugCase.isAugmenting());
         final DataSchemaNode leafAug = leafAugCase.getDataChildByName(QName.create(nsAug, rev, "leaf-aug-case"));
         assertFalse(leafAug.isAugmenting());
index 300111b7a879241c66df7344f1dba28e5f3f78a3..30160c075c28e1a8cf5fc6dfaff955e28393b9ac 100644 (file)
@@ -18,6 +18,7 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 import java.util.Set;
+import java.util.SortedMap;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
@@ -241,7 +242,7 @@ public class AugmentTest {
         // augment "/br:interfaces/br:ifEntry/bz:augment-holder"
         final ChoiceSchemaNode odl = (ChoiceSchemaNode) augmentedHolder.getDataChildByName(QName.create(FOO, "odl"));
         assertNotNull(odl);
-        final Set<ChoiceCaseNode> cases = odl.getCases();
+        final SortedMap<QName, ChoiceCaseNode> cases = odl.getCases();
         assertEquals(4, cases.size());
 
         ChoiceCaseNode id = null;
@@ -249,7 +250,7 @@ public class AugmentTest {
         ChoiceCaseNode node2 = null;
         ChoiceCaseNode node3 = null;
 
-        for (final ChoiceCaseNode ccn : cases) {
+        for (final ChoiceCaseNode ccn : cases.values()) {
             if ("id".equals(ccn.getQName().getLocalName())) {
                 id = ccn;
             } else if ("node1".equals(ccn.getQName().getLocalName())) {
@@ -355,13 +356,13 @@ public class AugmentTest {
         final QName argumentsQName = QName.create(NS_BAR, revision, "arguments");
         assertEquals(argumentsQName, arguments.getQName());
         assertFalse(arguments.isAugmenting());
-        final Set<ChoiceCaseNode> cases = arguments.getCases();
+        final SortedMap<QName, ChoiceCaseNode> cases = arguments.getCases();
         assertEquals(3, cases.size());
 
         ChoiceCaseNode attach = null;
         ChoiceCaseNode create = null;
         ChoiceCaseNode destroy = null;
-        for (final ChoiceCaseNode child : cases) {
+        for (final ChoiceCaseNode child : cases.values()) {
             if ("attach".equals(child.getQName().getLocalName())) {
                 attach = child;
             } else if ("create".equals(child.getQName().getLocalName())) {
index f2f41150938c943a768c3263ba56e50c3c87f08a..28ac16d895b421ceb284ff72bfc3d79370dbf772 100644 (file)
@@ -64,7 +64,7 @@ public class CaseStmtTest {
         tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next();
         assertNotNull(tempSecondChild);
         assertFalse(tempSecondChild.isConfiguration());
-        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next();
+        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().values().iterator().next();
         assertNotNull(tempChoice);
         assertFalse(tempChoice.isConfiguration());
         tempThirdChild = tempChoice.getChildNodes().iterator().next();
@@ -77,7 +77,7 @@ public class CaseStmtTest {
         tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next();
         assertNotNull(tempSecondChild);
         assertFalse(tempSecondChild.isConfiguration());
-        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next();
+        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().values().iterator().next();
         assertNotNull(tempChoice);
         assertFalse(tempChoice.isConfiguration());
         tempThirdChild = tempChoice.getChildNodes().iterator().next();
@@ -90,7 +90,7 @@ public class CaseStmtTest {
         tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next();
         assertNotNull(tempSecondChild);
         assertFalse(tempSecondChild.isConfiguration());
-        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next();
+        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().values().iterator().next();
         assertNotNull(tempChoice);
         assertFalse(tempChoice.isConfiguration());
         tempThirdChild = tempChoice.getChildNodes().iterator().next();
@@ -103,7 +103,7 @@ public class CaseStmtTest {
         tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next();
         assertNotNull(tempSecondChild);
         assertFalse(tempSecondChild.isConfiguration());
-        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next();
+        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().values().iterator().next();
         assertNotNull(tempChoice);
         assertFalse(tempChoice.isConfiguration());
         tempThirdChild = tempChoice.getChildNodes().iterator().next();
@@ -116,7 +116,7 @@ public class CaseStmtTest {
         tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next();
         assertNotNull(tempSecondChild);
         assertTrue(tempSecondChild.isConfiguration());
-        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next();
+        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().values().iterator().next();
         assertNotNull(tempChoice);
         assertFalse(tempChoice.isConfiguration());
         tempThirdChild = tempChoice.getChildNodes().iterator().next();
@@ -129,7 +129,7 @@ public class CaseStmtTest {
         tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next();
         assertNotNull(tempSecondChild);
         assertFalse(tempSecondChild.isConfiguration());
-        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next();
+        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().values().iterator().next();
         assertNotNull(tempChoice);
         assertFalse(tempChoice.isConfiguration());
         tempThirdChild = tempChoice.getChildNodes().iterator().next();
@@ -142,7 +142,7 @@ public class CaseStmtTest {
         tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next();
         assertNotNull(tempSecondChild);
         assertFalse(tempSecondChild.isConfiguration());
-        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next();
+        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().values().iterator().next();
         assertNotNull(tempChoice);
         assertFalse(tempChoice.isConfiguration());
         tempThirdChild = tempChoice.getChildNodes().iterator().next();
@@ -155,7 +155,7 @@ public class CaseStmtTest {
         tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next();
         assertNotNull(tempSecondChild);
         assertTrue(tempSecondChild.isConfiguration());
-        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next();
+        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().values().iterator().next();
         assertNotNull(tempChoice);
         assertTrue(tempChoice.isConfiguration());
         tempThirdChild = tempChoice.getChildNodes().iterator().next();
@@ -168,7 +168,7 @@ public class CaseStmtTest {
         tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next();
         assertNotNull(tempSecondChild);
         assertTrue(tempSecondChild.isConfiguration());
-        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next();
+        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().values().iterator().next();
         assertNotNull(tempChoice);
         assertTrue(tempChoice.isConfiguration());
         tempThirdChild = tempChoice.getChildNodes().iterator().next();
@@ -181,7 +181,7 @@ public class CaseStmtTest {
         tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next();
         assertNotNull(tempSecondChild);
         assertTrue(tempSecondChild.isConfiguration());
-        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next();
+        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().values().iterator().next();
         assertNotNull(tempChoice);
         assertTrue(tempChoice.isConfiguration());
         tempThirdChild = tempChoice.getChildNodes().iterator().next();
@@ -194,7 +194,7 @@ public class CaseStmtTest {
         tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next();
         assertNotNull(tempSecondChild);
         assertTrue(tempSecondChild.isConfiguration());
-        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next();
+        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().values().iterator().next();
         assertNotNull(tempChoice);
         assertTrue(tempChoice.isConfiguration());
         tempThirdChild = tempChoice.getChildNodes().iterator().next();
@@ -207,7 +207,7 @@ public class CaseStmtTest {
         tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next();
         assertNotNull(tempSecondChild);
         assertTrue(tempSecondChild.isConfiguration());
-        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next();
+        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().values().iterator().next();
         assertNotNull(tempChoice);
         assertTrue(tempChoice.isConfiguration());
         tempThirdChild = tempChoice.getChildNodes().iterator().next();
@@ -220,7 +220,7 @@ public class CaseStmtTest {
         tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next();
         assertNotNull(tempSecondChild);
         assertTrue(tempSecondChild.isConfiguration());
-        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next();
+        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().values().iterator().next();
         assertNotNull(tempChoice);
         assertTrue(tempChoice.isConfiguration());
         tempThirdChild = tempChoice.getChildNodes().iterator().next();
@@ -233,7 +233,7 @@ public class CaseStmtTest {
         tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next();
         assertNotNull(tempSecondChild);
         assertTrue(tempSecondChild.isConfiguration());
-        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next();
+        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().values().iterator().next();
         assertNotNull(tempChoice);
         assertTrue(tempChoice.isConfiguration());
         tempThirdChild = tempChoice.getChildNodes().iterator().next();
@@ -246,7 +246,7 @@ public class CaseStmtTest {
         tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next();
         assertNotNull(tempSecondChild);
         assertFalse(tempSecondChild.isConfiguration());
-        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next();
+        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().values().iterator().next();
         assertNotNull(tempChoice);
         assertFalse(tempChoice.isConfiguration());
         tempThirdChild = tempChoice.getChildNodes().iterator().next();
@@ -259,7 +259,7 @@ public class CaseStmtTest {
         tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next();
         assertNotNull(tempSecondChild);
         assertTrue(tempSecondChild.isConfiguration());
-        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next();
+        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().values().iterator().next();
         assertNotNull(tempChoice);
         assertFalse(tempChoice.isConfiguration());
         tempThirdChild = tempChoice.getChildNodes().iterator().next();
@@ -272,7 +272,7 @@ public class CaseStmtTest {
         tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next();
         assertNotNull(tempSecondChild);
         assertFalse(tempSecondChild.isConfiguration());
-        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next();
+        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().values().iterator().next();
         assertNotNull(tempChoice);
         assertFalse(tempChoice.isConfiguration());
         tempThirdChild = tempChoice.getChildNodes().iterator().next();
@@ -285,7 +285,7 @@ public class CaseStmtTest {
         tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next();
         assertNotNull(tempSecondChild);
         assertTrue(tempSecondChild.isConfiguration());
-        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next();
+        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().values().iterator().next();
         assertNotNull(tempChoice);
         assertFalse(tempChoice.isConfiguration());
         tempThirdChild = tempChoice.getChildNodes().iterator().next();
@@ -301,7 +301,7 @@ public class CaseStmtTest {
         tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next();
         assertNotNull(tempSecondChild);
         assertFalse(tempSecondChild.isConfiguration());
-        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next();
+        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().values().iterator().next();
         assertNotNull(tempChoice);
         assertFalse(tempChoice.isConfiguration());
         tempThirdChild = tempChoice.getChildNodes().iterator().next();
@@ -314,7 +314,7 @@ public class CaseStmtTest {
         tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next();
         assertNotNull(tempSecondChild);
         assertFalse(tempSecondChild.isConfiguration());
-        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next();
+        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().values().iterator().next();
         assertNotNull(tempChoice);
         assertFalse(tempChoice.isConfiguration());
         tempThirdChild = tempChoice.getChildNodes().iterator().next();
@@ -327,7 +327,7 @@ public class CaseStmtTest {
         tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next();
         assertNotNull(tempSecondChild);
         assertFalse(tempSecondChild.isConfiguration());
-        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next();
+        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().values().iterator().next();
         assertNotNull(tempChoice);
         assertFalse(tempChoice.isConfiguration());
         tempThirdChild = tempChoice.getChildNodes().iterator().next();
@@ -340,7 +340,7 @@ public class CaseStmtTest {
         tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next();
         assertNotNull(tempSecondChild);
         assertFalse(tempSecondChild.isConfiguration());
-        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next();
+        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().values().iterator().next();
         assertNotNull(tempChoice);
         assertFalse(tempChoice.isConfiguration());
         tempThirdChild = tempChoice.getChildNodes().iterator().next();
@@ -353,7 +353,7 @@ public class CaseStmtTest {
         tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next();
         assertNotNull(tempSecondChild);
         assertTrue(tempSecondChild.isConfiguration());
-        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next();
+        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().values().iterator().next();
         assertNotNull(tempChoice);
         assertFalse(tempChoice.isConfiguration());
         tempThirdChild = tempChoice.getChildNodes().iterator().next();
@@ -366,7 +366,7 @@ public class CaseStmtTest {
         tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next();
         assertNotNull(tempSecondChild);
         assertFalse(tempSecondChild.isConfiguration());
-        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next();
+        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().values().iterator().next();
         assertNotNull(tempChoice);
         assertFalse(tempChoice.isConfiguration());
         tempThirdChild = tempChoice.getChildNodes().iterator().next();
@@ -379,7 +379,7 @@ public class CaseStmtTest {
         tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next();
         assertNotNull(tempSecondChild);
         assertFalse(tempSecondChild.isConfiguration());
-        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next();
+        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().values().iterator().next();
         assertNotNull(tempChoice);
         assertFalse(tempChoice.isConfiguration());
         tempThirdChild = tempChoice.getChildNodes().iterator().next();
@@ -392,7 +392,7 @@ public class CaseStmtTest {
         tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next();
         assertNotNull(tempSecondChild);
         assertTrue(tempSecondChild.isConfiguration());
-        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next();
+        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().values().iterator().next();
         assertNotNull(tempChoice);
         assertTrue(tempChoice.isConfiguration());
         tempThirdChild = tempChoice.getChildNodes().iterator().next();
@@ -405,7 +405,7 @@ public class CaseStmtTest {
         tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next();
         assertNotNull(tempSecondChild);
         assertTrue(tempSecondChild.isConfiguration());
-        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next();
+        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().values().iterator().next();
         assertNotNull(tempChoice);
         assertTrue(tempChoice.isConfiguration());
         tempThirdChild = tempChoice.getChildNodes().iterator().next();
@@ -418,7 +418,7 @@ public class CaseStmtTest {
         tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next();
         assertNotNull(tempSecondChild);
         assertTrue(tempSecondChild.isConfiguration());
-        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next();
+        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().values().iterator().next();
         assertNotNull(tempChoice);
         assertTrue(tempChoice.isConfiguration());
         tempThirdChild = tempChoice.getChildNodes().iterator().next();
@@ -431,7 +431,7 @@ public class CaseStmtTest {
         tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next();
         assertNotNull(tempSecondChild);
         assertTrue(tempSecondChild.isConfiguration());
-        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next();
+        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().values().iterator().next();
         assertNotNull(tempChoice);
         assertTrue(tempChoice.isConfiguration());
         tempThirdChild = tempChoice.getChildNodes().iterator().next();
@@ -444,7 +444,7 @@ public class CaseStmtTest {
         tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next();
         assertNotNull(tempSecondChild);
         assertTrue(tempSecondChild.isConfiguration());
-        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next();
+        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().values().iterator().next();
         assertNotNull(tempChoice);
         assertTrue(tempChoice.isConfiguration());
         tempThirdChild = tempChoice.getChildNodes().iterator().next();
@@ -457,7 +457,7 @@ public class CaseStmtTest {
         tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next();
         assertNotNull(tempSecondChild);
         assertTrue(tempSecondChild.isConfiguration());
-        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next();
+        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().values().iterator().next();
         assertNotNull(tempChoice);
         assertTrue(tempChoice.isConfiguration());
         tempThirdChild = tempChoice.getChildNodes().iterator().next();
@@ -470,7 +470,7 @@ public class CaseStmtTest {
         tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next();
         assertNotNull(tempSecondChild);
         assertTrue(tempSecondChild.isConfiguration());
-        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next();
+        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().values().iterator().next();
         assertNotNull(tempChoice);
         assertTrue(tempChoice.isConfiguration());
         tempThirdChild = tempChoice.getChildNodes().iterator().next();
@@ -483,7 +483,7 @@ public class CaseStmtTest {
         tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next();
         assertNotNull(tempSecondChild);
         assertFalse(tempSecondChild.isConfiguration());
-        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next();
+        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().values().iterator().next();
         assertNotNull(tempChoice);
         assertFalse(tempChoice.isConfiguration());
         tempThirdChild = tempChoice.getChildNodes().iterator().next();
@@ -496,7 +496,7 @@ public class CaseStmtTest {
         tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next();
         assertNotNull(tempSecondChild);
         assertTrue(tempSecondChild.isConfiguration());
-        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next();
+        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().values().iterator().next();
         assertNotNull(tempChoice);
         assertFalse(tempChoice.isConfiguration());
         tempThirdChild = tempChoice.getChildNodes().iterator().next();
@@ -509,7 +509,7 @@ public class CaseStmtTest {
         tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next();
         assertNotNull(tempSecondChild);
         assertFalse(tempSecondChild.isConfiguration());
-        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next();
+        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().values().iterator().next();
         assertNotNull(tempChoice);
         assertFalse(tempChoice.isConfiguration());
         tempThirdChild = tempChoice.getChildNodes().iterator().next();
@@ -522,7 +522,7 @@ public class CaseStmtTest {
         tempSecondChild = ((ContainerEffectiveStatementImpl) tempChild).getChildNodes().iterator().next();
         assertNotNull(tempSecondChild);
         assertTrue(tempSecondChild.isConfiguration());
-        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().iterator().next();
+        tempChoice = ((ChoiceEffectiveStatementImpl) tempSecondChild).getCases().values().iterator().next();
         assertNotNull(tempChoice);
         assertFalse(tempChoice.isConfiguration());
         tempThirdChild = tempChoice.getChildNodes().iterator().next();
index b2ab02b7cc2db4a7d344a73e5fea1b89e29fc020..aa6564d9adb3ad0d24fa278d80b0786f22c4b3b9 100644 (file)
@@ -51,16 +51,16 @@ public class ChoiceStmtTest {
         assertNotNull(choice);
         assertEquals(5, choice.getCases().size());
 
-        ChoiceCaseNode caseNode = choice.getCaseNodeByName("input");
+        ChoiceCaseNode caseNode = choice.findCaseNodes("input").iterator().next();
         assertNotNull(caseNode);
-        caseNode = choice.getCaseNodeByName("output");
+        caseNode = choice.findCaseNodes("output").iterator().next();
         assertNotNull(caseNode);
-        caseNode = choice.getCaseNodeByName("interval");
+        caseNode = choice.findCaseNodes("interval").iterator().next();
         assertNotNull(caseNode);
-        caseNode = choice.getCaseNodeByName("daily");
+        caseNode = choice.findCaseNodes("daily").iterator().next();
         assertNotNull(caseNode);
-        caseNode = choice.getCaseNodeByName("manual");
+        caseNode = choice.findCaseNodes("manual").iterator().next();
         assertNotNull(caseNode);
-        assertEquals("interval", choice.getDefaultCase());
+        assertEquals("interval", choice.getDefaultCase().get().getQName().getLocalName());
     }
 }
index 7a8c5bd3d3312cab118490de424fef9a5e6ab8e8..0fa92b68d5a1e9d9187dccd09fd2c8d91adad101 100644 (file)
@@ -92,7 +92,7 @@ public class ControllerStmtParserTest {
         assertTrue(dataChildChoice instanceof ChoiceSchemaNode);
 
         final ChoiceSchemaNode confChoice = (ChoiceSchemaNode) dataChildChoice;
-        final ChoiceCaseNode caseNodeByName = confChoice.getCaseNodeByName("dom-broker-impl");
+        final ChoiceCaseNode caseNodeByName = confChoice.findCaseNodes("dom-broker-impl").iterator().next();
 
         assertNotNull(caseNodeByName);
         final DataSchemaNode dataNode2 = caseNodeByName
@@ -110,7 +110,8 @@ public class ControllerStmtParserTest {
         assertEquals(unknownSchemaNode.getQName(), unknownSchemaNode.getPath().getLastComponent());
         assertEquals("dom-async-data-broker", unknownSchemaNode.getQName().getLocalName());
 
-        final ChoiceCaseNode domInmemoryDataBroker = confChoice.getCaseNodeByName("dom-inmemory-data-broker");
+        final ChoiceCaseNode domInmemoryDataBroker = confChoice.findCaseNodes("dom-inmemory-data-broker").iterator()
+                .next();
 
         assertNotNull(domInmemoryDataBroker);
         final DataSchemaNode schemaService = domInmemoryDataBroker
index ba303588d63dd3ce15734f58314c10fb859ca415..7168c747b65c3f57841b75accff8272acf392e1e 100644 (file)
@@ -91,7 +91,7 @@ public class DeviationResolutionTest {
         final ChoiceSchemaNode myChoice = (ChoiceSchemaNode) barModule.getDataChildByName(
                 QName.create(barModule.getQNameModule(), "my-choice"));
         assertNotNull(myChoice);
-        assertEquals("c2", myChoice.getDefaultCase());
+        assertEquals("c2", myChoice.getDefaultCase().get().getQName().getLocalName());
 
         final RpcDefinition myRpc = barModule.getRpcs().iterator().next();
         final ContainerSchemaNode input = myRpc.getInput();
index 9697cf18657827f68c9d60f85d8ae3bf3a66e46a..6381924a0d544b1c33b7c4660d3fcaf3f4484b91 100644 (file)
@@ -21,6 +21,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 import java.util.Set;
+import java.util.SortedMap;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -291,9 +292,9 @@ public class GroupingTest {
         assertNotNull(how_u);
         TestUtils.checkIsAddedByUses(how_u, true);
         assertFalse(how_u.isAugmenting());
-        final Set<ChoiceCaseNode> cases_u = how_u.getCases();
+        final SortedMap<QName, ChoiceCaseNode> cases_u = how_u.getCases();
         assertEquals(2, cases_u.size());
-        final ChoiceCaseNode interval = how_u.getCaseNodeByName("interval");
+        final ChoiceCaseNode interval = how_u.findCaseNodes("interval").iterator().next();
         assertFalse(interval.isAugmenting());
         final LeafSchemaNode name = (LeafSchemaNode) interval.getDataChildByName(QName.create(foo.getQNameModule(),
                 "name"));
index 737a260438357587f5c737de8c2f6a38ccbf50b0..8d39a4b678f8d222f39bb21d51d1de54ba8473d7 100644 (file)
@@ -153,7 +153,7 @@ public final class TestUtils {
                 checkIsAugmenting(child, expected);
             }
         } else if (node instanceof ChoiceSchemaNode) {
-            for (ChoiceCaseNode caseNode : ((ChoiceSchemaNode) node).getCases()) {
+            for (ChoiceCaseNode caseNode : ((ChoiceSchemaNode) node).getCases().values()) {
                 checkIsAugmenting(caseNode, expected);
             }
         }
@@ -176,7 +176,7 @@ public final class TestUtils {
                 checkIsAddedByUses(child, expected);
             }
         } else if (node instanceof ChoiceSchemaNode) {
-            for (ChoiceCaseNode caseNode : ((ChoiceSchemaNode) node).getCases()) {
+            for (ChoiceCaseNode caseNode : ((ChoiceSchemaNode) node).getCases().values()) {
                 checkIsAddedByUses(caseNode, expected);
             }
         }
index 62e39c5340052698bb4ebb68abb19ff6224ebc1e..a17845e518dd978c7e5b084cd7e47c386eff5624 100644 (file)
@@ -26,6 +26,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Optional;
 import java.util.Set;
+import java.util.SortedMap;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -516,11 +517,11 @@ public class YangParserTest {
             QName.create(foo.getQNameModule(), "transfer"));
         final ChoiceSchemaNode how = (ChoiceSchemaNode) transfer.getDataChildByName(
             QName.create(foo.getQNameModule(), "how"));
-        final Set<ChoiceCaseNode> cases = how.getCases();
+        final SortedMap<QName, ChoiceCaseNode> cases = how.getCases();
         assertEquals(5, cases.size());
         ChoiceCaseNode input = null;
         ChoiceCaseNode output = null;
-        for (final ChoiceCaseNode caseNode : cases) {
+        for (final ChoiceCaseNode caseNode : cases.values()) {
             if ("input".equals(caseNode.getQName().getLocalName())) {
                 input = caseNode;
             } else if ("output".equals(caseNode.getQName().getLocalName())) {
index 61351d5b8e92e27598abaf88151c045590d9c67c..5be7b4dca9c9fbc4f64086780b4a7a0d85449f6b 100644 (file)
@@ -61,7 +61,7 @@ public class YinFileChoiceStmtTest {
         assertEquals(1, choice.getCases().size());
 
         // this choice is augmented (see main-impl.yang.xml)
-        final Iterator<ChoiceCaseNode> casesIterator = choice.getCases().iterator();
+        final Iterator<ChoiceCaseNode> casesIterator = choice.getCases().values().iterator();
         final ChoiceCaseNode caseNode = casesIterator.next();
         assertEquals("main-impl", caseNode.getQName().getLocalName());
         assertEquals(13, caseNode.getChildNodes().size());
index 412f9c15a94cee69b1eb00034608dba937de79d1..5338ec34baecb3856ec9ec271d71f8259fa4a750 100644 (file)
@@ -34,7 +34,7 @@ submodule subfoo {
 
     container sub-transfer {
         choice how {
-            default interval;
+            default input;
             container input {
             }
             list output {
index e0008dee117632d198e36622c0ef9f9683eddb89..e591f80843f5ec3775a4c7f6ecfef2bdf527a94c 100644 (file)
@@ -34,7 +34,7 @@ submodule subfoo {
 
     container sub-transfer {
         choice how {
-            default interval;
+            default input;
             container input {
             }
             list output {
index 44e36e379867f45abce814c3687145a5b8fc9ed9..9c003fef211d9028adfb5e75b7fd7f3eebdd19f4 100644 (file)
@@ -34,7 +34,7 @@ submodule subfoo {
 
     container sub-transfer {
         choice how {
-            default interval;
+            default input;
             container input {
             }
             list output {