From 1cb3b70ea959108d66dd19cbe30c86d78c77e5c9 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Sat, 28 Oct 2017 16:54:46 +0200 Subject: [PATCH] Update ChoiceSchemaNode design 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 --- .../data/codec/gson/JsonParserStream.java | 2 +- .../xml/NormalizedNodeXmlTranslationTest.java | 32 +++---- .../yang/data/impl/codec/SchemaTracker.java | 4 +- .../leafref/LeafRefContextTreeBuilder.java | 31 ++---- .../schema/InstanceIdToCompositeNodes.java | 2 +- .../data/impl/schema/InstanceIdToNodes.java | 2 +- .../SchemaOrderedNormalizedNodeWriter.java | 2 +- .../yang/data/impl/schema/SchemaUtils.java | 18 ++-- .../tree/ChoiceModificationStrategy.java | 2 +- .../schema/NormalizedDataBuilderTest.java | 31 +++--- .../yang/data/util/ChoiceNodeContextNode.java | 2 +- .../yang/data/util/DataSchemaContextNode.java | 14 +-- .../yang/data/util/ParserStreamUtils.java | 2 +- .../yang/model/api/ChoiceSchemaNode.java | 94 ++++++++++++++----- .../model/export/SchemaContextEmitter.java | 2 +- .../yang/model/util/DataNodeIterator.java | 9 +- .../yang/model/util/SchemaContextUtil.java | 2 +- .../yang/model/util/DataNodeIteratorTest.java | 12 ++- .../ChoiceEffectiveStatementImpl.java | 74 +++++++-------- .../parser/util/SchemaContextUtilTest.java | 24 +++-- .../yang/stmt/AugmentProcessTest.java | 2 +- .../yangtools/yang/stmt/AugmentTest.java | 9 +- .../yangtools/yang/stmt/CaseStmtTest.java | 72 +++++++------- .../yangtools/yang/stmt/ChoiceStmtTest.java | 12 +-- .../yang/stmt/ControllerStmtParserTest.java | 5 +- .../yang/stmt/DeviationResolutionTest.java | 2 +- .../yangtools/yang/stmt/GroupingTest.java | 5 +- .../yangtools/yang/stmt/TestUtils.java | 4 +- .../yangtools/yang/stmt/YangParserTest.java | 5 +- .../yang/stmt/yin/YinFileChoiceStmtTest.java | 2 +- .../src/test/resources/model/subfoo.yang | 2 +- .../test/resources/rfc7950/model/subfoo.yang | 2 +- .../model/subfoo.yang | 2 +- 33 files changed, 259 insertions(+), 226 deletions(-) diff --git a/yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/JsonParserStream.java b/yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/JsonParserStream.java index 8c42de6c88..c9251e59c1 100644 --- a/yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/JsonParserStream.java +++ b/yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/JsonParserStream.java @@ -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)); } } diff --git a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/NormalizedNodeXmlTranslationTest.java b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/NormalizedNodeXmlTranslationTest.java index d070482441..e3040bcb71 100644 --- a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/NormalizedNodeXmlTranslationTest.java +++ b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/NormalizedNodeXmlTranslationTest.java @@ -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 children, final String name) { - List 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; } diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/SchemaTracker.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/SchemaTracker.java index 4fb46dcd3e..24ec5b9948 100644 --- a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/SchemaTracker.java +++ b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/SchemaTracker.java @@ -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; diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/leafref/LeafRefContextTreeBuilder.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/leafref/LeafRefContextTreeBuilder.java index f8265bed56..ddda315c07 100644 --- a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/leafref/LeafRefContextTreeBuilder.java +++ b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/leafref/LeafRefContextTreeBuilder.java @@ -102,10 +102,8 @@ class LeafRefContextTreeBuilder { } else if (node instanceof ChoiceSchemaNode) { final ChoiceSchemaNode choice = (ChoiceSchemaNode) node; - final Set 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 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 foundLeafRefs = getLeafRefsFor(node, - currentModule); + } else if (node instanceof LeafSchemaNode || node instanceof LeafListSchemaNode) { + final List 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); } } } diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToCompositeNodes.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToCompositeNodes.java index cf5e2a16d0..f891cda0b7 100644 --- a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToCompositeNodes.java +++ b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToCompositeNodes.java @@ -330,7 +330,7 @@ abstract class InstanceIdToCompositeNodes extends Instan super(NodeIdentifier.create(schema.getQName())); final ImmutableMap.Builder> 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); diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToNodes.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToNodes.java index a4ddcc41a9..471d8b07e4 100644 --- a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToNodes.java +++ b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToNodes.java @@ -179,7 +179,7 @@ abstract class InstanceIdToNodes 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; diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/SchemaOrderedNormalizedNodeWriter.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/SchemaOrderedNormalizedNodeWriter.java index 186d88c55d..fb4033140d 100644 --- a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/SchemaOrderedNormalizedNodeWriter.java +++ b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/SchemaOrderedNormalizedNodeWriter.java @@ -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); diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/SchemaUtils.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/SchemaUtils.java index 5e9546c02a..b1bd57459d 100644 --- a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/SchemaUtils.java +++ b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/SchemaUtils.java @@ -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 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 qnames) { - for (final ChoiceCaseNode choiceCaseNode : schema.getCases()) { + for (final ChoiceCaseNode choiceCaseNode : schema.getCases().values()) { final Optional 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 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 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); diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ChoiceModificationStrategy.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ChoiceModificationStrategy.java index 338b93eb0e..bc03a63eed 100644 --- a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ChoiceModificationStrategy.java +++ b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ChoiceModificationStrategy.java @@ -49,7 +49,7 @@ final class ChoiceModificationStrategy extends AbstractNodeContainerModification final Builder childBuilder = ImmutableMap.builder(); final Builder 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 e : enforcer.getChildEntries()) { diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/NormalizedDataBuilderTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/NormalizedDataBuilderTest.java index f81f595465..ca57bc31fd 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/NormalizedDataBuilderTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/NormalizedDataBuilderTest.java @@ -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 children, final String name) { - List 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; } } diff --git a/yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/ChoiceNodeContextNode.java b/yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/ChoiceNodeContextNode.java index e212655819..27bacac529 100644 --- a/yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/ChoiceNodeContextNode.java +++ b/yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/ChoiceNodeContextNode.java @@ -25,7 +25,7 @@ class ChoiceNodeContextNode extends AbstractMixinContextNode { ImmutableMap.Builder> byQNameBuilder = ImmutableMap.builder(); ImmutableMap.Builder> 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); diff --git a/yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/DataSchemaContextNode.java b/yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/DataSchemaContextNode.java index 07ce69fff6..336ab56e94 100644 --- a/yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/DataSchemaContextNode.java +++ b/yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/DataSchemaContextNode.java @@ -97,23 +97,23 @@ public abstract class DataSchemaContextNode 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 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) { diff --git a/yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/ParserStreamUtils.java b/yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/ParserStreamUtils.java index e2372c2f1a..b9c17416fc 100644 --- a/yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/ParserStreamUtils.java +++ b/yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/ParserStreamUtils.java @@ -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 resultFromRecursion = findSchemaNodeByNameAndNamespace(concreteCase, childName, namespace); if (!resultFromRecursion.isEmpty()) { diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/ChoiceSchemaNode.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/ChoiceSchemaNode.java index 0da6676886..073b25c6c7 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/ChoiceSchemaNode.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/ChoiceSchemaNode.java @@ -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 case - * substatement of the choice statement + * @return set of ChoiceCaseNode objects defined in this node which represents set of arguments of the YANG + * case substatement of the choice statement. */ - Set getCases(); + SortedMap 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, null 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 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, null 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 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 findDataSchemaChild(final QName qname) { + requireNonNull(qname); + for (ChoiceCaseNode caseNode : getCases().values()) { + final Optional 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, null otherwise. * - * @return string with the name of case which is specified in the argument - * of the YANG default substatement of - * choice 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 default + * substatement of choice statement. + */ + Optional getDefaultCase(); } diff --git a/yang/yang-model-export/src/main/java/org/opendaylight/yangtools/yang/model/export/SchemaContextEmitter.java b/yang/yang-model-export/src/main/java/org/opendaylight/yangtools/yang/model/export/SchemaContextEmitter.java index efd936bf16..7f8172df96 100644 --- a/yang/yang-model-export/src/main/java/org/opendaylight/yangtools/yang/model/export/SchemaContextEmitter.java +++ b/yang/yang-model-export/src/main/java/org/opendaylight/yangtools/yang/model/export/SchemaContextEmitter.java @@ -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); } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/DataNodeIterator.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/DataNodeIterator.java index 1c7543cf32..55433e2ba9 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/DataNodeIterator.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/DataNodeIterator.java @@ -125,11 +125,8 @@ public class DataNodeIterator implements Iterator { } else if (childNode instanceof ChoiceSchemaNode) { final ChoiceSchemaNode choiceNode = (ChoiceSchemaNode) childNode; allChoices.add(choiceNode); - final Set 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 { if (container.getChildNodes() != null) { final Collection childNodes = container.getChildNodes(); - if ((childNodes != null) && !childNodes.isEmpty()) { + if (childNodes != null && !childNodes.isEmpty()) { return childNodes.iterator().hasNext(); } } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtil.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtil.java index 650ab65e63..06ae0d090f 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtil.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtil.java @@ -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); diff --git a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/DataNodeIteratorTest.java b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/DataNodeIteratorTest.java index 8bcc5345a3..65321570fd 100644 --- a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/DataNodeIteratorTest.java +++ b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/DataNodeIteratorTest.java @@ -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 cases = ImmutableSet.of(mockedCase1, mockedCase2); + final QName mockedCase2QName = QName.create("", "case2"); + final SortedMap cases = ImmutableSortedMap.of(mockedCase1QName, mockedCase1, + mockedCase2QName, mockedCase2); doReturn(cases).when(mockedChoice).getCases(); final Set 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)); diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ChoiceEffectiveStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ChoiceEffectiveStatementImpl.java index a9360a6134..f76df175a8 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ChoiceEffectiveStatementImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ChoiceEffectiveStatementImpl.java @@ -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 implements ChoiceSchemaNode, DerivableSchemaNode { - private final ChoiceSchemaNode original; - private final String defaultCase; - private final Set cases; private final Set augmentations; + private final SortedMap cases; + private final ChoiceCaseNode defaultCase; + private final ChoiceSchemaNode original; public ChoiceEffectiveStatementImpl( final StmtContext> 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 augmentationsInit = new LinkedHashSet<>(); - final SortedSet casesInit = new TreeSet<>((o1, o2) -> o1.getQName().compareTo(o2.getQName())); + final SortedMap 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 getCases() { + public SortedMap 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 getDefaultCase() { + return Optional.ofNullable(defaultCase); } @Override diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/util/SchemaContextUtilTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/util/SchemaContextUtilTest.java index 51e4d9e50e..dcb9f2bdd3 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/util/SchemaContextUtilTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/util/SchemaContextUtilTest.java @@ -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"), diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentProcessTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentProcessTest.java index 7f66b54234..9f96a0f26c 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentProcessTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentProcessTest.java @@ -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()); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentTest.java index 300111b7a8..30160c075c 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentTest.java @@ -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 cases = odl.getCases(); + final SortedMap 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 cases = arguments.getCases(); + final SortedMap 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())) { diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/CaseStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/CaseStmtTest.java index f2f4115093..28ac16d895 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/CaseStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/CaseStmtTest.java @@ -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(); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ChoiceStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ChoiceStmtTest.java index b2ab02b7cc..aa6564d9ad 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ChoiceStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ChoiceStmtTest.java @@ -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()); } } diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ControllerStmtParserTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ControllerStmtParserTest.java index 7a8c5bd3d3..0fa92b68d5 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ControllerStmtParserTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ControllerStmtParserTest.java @@ -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 diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/DeviationResolutionTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/DeviationResolutionTest.java index ba303588d6..7168c747b6 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/DeviationResolutionTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/DeviationResolutionTest.java @@ -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(); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/GroupingTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/GroupingTest.java index 9697cf1865..6381924a0d 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/GroupingTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/GroupingTest.java @@ -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 cases_u = how_u.getCases(); + final SortedMap 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")); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/TestUtils.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/TestUtils.java index 737a260438..8d39a4b678 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/TestUtils.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/TestUtils.java @@ -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); } } diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserTest.java index 62e39c5340..a17845e518 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserTest.java @@ -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 cases = how.getCases(); + final SortedMap 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())) { diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileChoiceStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileChoiceStmtTest.java index 61351d5b8e..5be7b4dca9 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileChoiceStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileChoiceStmtTest.java @@ -61,7 +61,7 @@ public class YinFileChoiceStmtTest { assertEquals(1, choice.getCases().size()); // this choice is augmented (see main-impl.yang.xml) - final Iterator casesIterator = choice.getCases().iterator(); + final Iterator casesIterator = choice.getCases().values().iterator(); final ChoiceCaseNode caseNode = casesIterator.next(); assertEquals("main-impl", caseNode.getQName().getLocalName()); assertEquals(13, caseNode.getChildNodes().size()); diff --git a/yang/yang-parser-impl/src/test/resources/model/subfoo.yang b/yang/yang-parser-impl/src/test/resources/model/subfoo.yang index 412f9c15a9..5338ec34ba 100644 --- a/yang/yang-parser-impl/src/test/resources/model/subfoo.yang +++ b/yang/yang-parser-impl/src/test/resources/model/subfoo.yang @@ -34,7 +34,7 @@ submodule subfoo { container sub-transfer { choice how { - default interval; + default input; container input { } list output { diff --git a/yang/yang-parser-impl/src/test/resources/rfc7950/model/subfoo.yang b/yang/yang-parser-impl/src/test/resources/rfc7950/model/subfoo.yang index e0008dee11..e591f80843 100644 --- a/yang/yang-parser-impl/src/test/resources/rfc7950/model/subfoo.yang +++ b/yang/yang-parser-impl/src/test/resources/rfc7950/model/subfoo.yang @@ -34,7 +34,7 @@ submodule subfoo { container sub-transfer { choice how { - default interval; + default input; container input { } list output { diff --git a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/model/subfoo.yang b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/model/subfoo.yang index 44e36e3798..9c003fef21 100644 --- a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/model/subfoo.yang +++ b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/model/subfoo.yang @@ -34,7 +34,7 @@ submodule subfoo { container sub-transfer { choice how { - default interval; + default input; container input { } list output { -- 2.36.6