}
for (final ChoiceSchemaNode choiceNode : choices) {
- for (final ChoiceCaseNode concreteCase : choiceNode.getCases()) {
+ for (final ChoiceCaseNode concreteCase : choiceNode.getCases().values()) {
potentialUris.addAll(resolveAllPotentialNamespaces(elementName, concreteCase));
}
}
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;
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;
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;
}
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;
}
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;
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;
} 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);
}
}
} 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);
}
}
}
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);
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;
}
}
} 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);
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) {
}
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()) {
}
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();
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);
}
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);
}
// 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;
}
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) {
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()));
}
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);
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()) {
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;
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;
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;
}
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;
}
}
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);
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) {
// 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()) {
*/
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();
}
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);
}
} 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);
}
}
}
if (container.getChildNodes() != null) {
final Collection<DataSchemaNode> childNodes = container.getChildNodes();
- if ((childNodes != null) && !childNodes.isEmpty()) {
+ if (childNodes != null && !childNodes.isEmpty()) {
return childNodes.iterator().hasNext();
}
}
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);
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;
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,
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));
*/
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;
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) {
}
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);
}
}
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) {
}
@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
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"),
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"),
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"),
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"),
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"),
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());
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;
// 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;
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())) {
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())) {
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();
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();
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();
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();
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();
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();
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();
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();
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();
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();
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();
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();
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();
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();
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();
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();
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();
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();
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();
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();
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();
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();
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();
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();
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();
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();
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();
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();
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();
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();
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();
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();
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();
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();
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();
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();
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());
}
}
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
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
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();
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;
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"));
checkIsAugmenting(child, expected);
}
} else if (node instanceof ChoiceSchemaNode) {
- for (ChoiceCaseNode caseNode : ((ChoiceSchemaNode) node).getCases()) {
+ for (ChoiceCaseNode caseNode : ((ChoiceSchemaNode) node).getCases().values()) {
checkIsAugmenting(caseNode, expected);
}
}
checkIsAddedByUses(child, expected);
}
} else if (node instanceof ChoiceSchemaNode) {
- for (ChoiceCaseNode caseNode : ((ChoiceSchemaNode) node).getCases()) {
+ for (ChoiceCaseNode caseNode : ((ChoiceSchemaNode) node).getCases().values()) {
checkIsAddedByUses(caseNode, expected);
}
}
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;
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())) {
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());
container sub-transfer {
choice how {
- default interval;
+ default input;
container input {
}
list output {
container sub-transfer {
choice how {
- default interval;
+ default input;
container input {
}
list output {
container sub-transfer {
choice how {
- default interval;
+ default input;
container input {
}
list output {