Fix Status encoding
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / AbstractEffectiveDocumentedDataNodeContainer.java
index 84b32691c8c7f0b67199fc8281235e0d9723ea11..c13fc5bc65957ce246a0074a6410d8b5a746fa27 100644 (file)
@@ -7,20 +7,13 @@
  */
 package org.opendaylight.yangtools.yang.parser.rfc7950.stmt;
 
-import static java.util.Objects.requireNonNull;
-
-import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
+import java.util.Collection;
 import java.util.HashSet;
-import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
-import java.util.Map;
 import java.util.Optional;
 import java.util.Set;
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
@@ -29,15 +22,11 @@ import org.opendaylight.yangtools.yang.model.api.UsesNode;
 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.TypedefEffectiveStatement;
-import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.YangValidationBundles;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.choice.ImplicitCaseSchemaNode;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.source.AugmentToChoiceNamespace;
 
 public abstract class AbstractEffectiveDocumentedDataNodeContainer<A, D extends DeclaredStatement<A>>
         extends AbstractSchemaEffectiveDocumentedNode<A, D> implements DataNodeContainer {
 
-    private final ImmutableMap<QName, DataSchemaNode> childNodes;
     private final ImmutableSet<GroupingDefinition> groupings;
     private final ImmutableSet<UsesNode> uses;
     private final ImmutableSet<TypeDefinition<?>> typeDefinitions;
@@ -46,7 +35,6 @@ public abstract class AbstractEffectiveDocumentedDataNodeContainer<A, D extends
     protected AbstractEffectiveDocumentedDataNodeContainer(final StmtContext<A, D, ?> ctx) {
         super(ctx);
 
-        Map<QName, DataSchemaNode> mutableChildNodes = new LinkedHashMap<>();
         Set<GroupingDefinition> mutableGroupings = new HashSet<>();
         Set<UsesNode> mutableUses = new HashSet<>();
         Set<TypeDefinition<?>> mutableTypeDefinitions = new LinkedHashSet<>();
@@ -54,52 +42,20 @@ public abstract class AbstractEffectiveDocumentedDataNodeContainer<A, D extends
 
         for (EffectiveStatement<?, ?> stmt : effectiveSubstatements()) {
             if (stmt instanceof DataSchemaNode) {
-                final DataSchemaNode dataSchemaNode = (DataSchemaNode) stmt;
-                if (mutableChildNodes.containsKey(dataSchemaNode.getQName())) {
-                    throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, stmt);
-                }
-
-                //  Add case short hand when augmenting choice with short hand
-                if (this instanceof AugmentationSchemaNode
-                        && !(stmt instanceof CaseSchemaNode || stmt instanceof ChoiceSchemaNode)
-                        && YangValidationBundles.SUPPORTED_CASE_SHORTHANDS.contains(stmt.statementDefinition())
-                        && Boolean.TRUE.equals(ctx.getFromNamespace(AugmentToChoiceNamespace.class, ctx))) {
-                    final ImplicitCaseSchemaNode caseShorthand = new ImplicitCaseSchemaNode(dataSchemaNode);
-                    mutableChildNodes.put(caseShorthand.getQName(), caseShorthand);
-                    mutablePublicChildNodes.add(caseShorthand);
-                } else {
-                    mutableChildNodes.put(dataSchemaNode.getQName(), dataSchemaNode);
-                    mutablePublicChildNodes.add(dataSchemaNode);
-                }
+                mutablePublicChildNodes.add((DataSchemaNode) stmt);
             }
-            if (stmt instanceof UsesNode) {
-                UsesNode usesNode = (UsesNode) stmt;
-                if (!mutableUses.contains(usesNode)) {
-                    mutableUses.add(usesNode);
-                } else {
-                    throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, stmt);
-                }
+            if (stmt instanceof UsesNode && !mutableUses.add((UsesNode) stmt)) {
+                throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, stmt);
             }
-            if (stmt instanceof TypedefEffectiveStatement) {
-                TypedefEffectiveStatement typeDef = (TypedefEffectiveStatement) stmt;
-                TypeDefinition<?> type = typeDef.getTypeDefinition();
-                if (!mutableTypeDefinitions.contains(type)) {
-                    mutableTypeDefinitions.add(type);
-                } else {
-                    throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, stmt);
-                }
+            if (stmt instanceof TypedefEffectiveStatement
+                    && !mutableTypeDefinitions.add(((TypedefEffectiveStatement) stmt).getTypeDefinition())) {
+                throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, stmt);
             }
-            if (stmt instanceof GroupingDefinition) {
-                GroupingDefinition grp = (GroupingDefinition) stmt;
-                if (!mutableGroupings.contains(grp)) {
-                    mutableGroupings.add(grp);
-                } else {
-                    throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, stmt);
-                }
+            if (stmt instanceof GroupingDefinition && !mutableGroupings.add((GroupingDefinition) stmt)) {
+                throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, stmt);
             }
         }
 
-        this.childNodes = ImmutableMap.copyOf(mutableChildNodes);
         this.groupings = ImmutableSet.copyOf(mutableGroupings);
         this.publicChildNodes = ImmutableSet.copyOf(mutablePublicChildNodes);
         this.typeDefinitions = ImmutableSet.copyOf(mutableTypeDefinitions);
@@ -107,12 +63,12 @@ public abstract class AbstractEffectiveDocumentedDataNodeContainer<A, D extends
     }
 
     @Override
-    public final Set<TypeDefinition<?>> getTypeDefinitions() {
+    public final Collection<? extends TypeDefinition<?>> getTypeDefinitions() {
         return typeDefinitions;
     }
 
     @Override
-    public final Set<DataSchemaNode> getChildNodes() {
+    public final Collection<? extends DataSchemaNode> getChildNodes() {
         return publicChildNodes;
     }
 
@@ -123,8 +79,7 @@ public abstract class AbstractEffectiveDocumentedDataNodeContainer<A, D extends
 
     @Override
     public final Optional<DataSchemaNode> findDataChildByName(final QName name) {
-        // Child nodes are keyed by their container name, so we can do a direct lookup
-        return Optional.ofNullable(childNodes.get(requireNonNull(name)));
+        return findDataSchemaNode(name);
     }
 
     @Override