Migrate AbstractTypeStatementSupport
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / AbstractEffectiveDocumentedDataNodeContainer.java
index 5dfc8ecdd50aa158b9daf4324e27a3ee62a2474b..f48ab11d79c61b9c6a647fb164d2a448f8251819 100644 (file)
@@ -7,14 +7,9 @@
  */
 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.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;
@@ -28,10 +23,10 @@ import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.TypedefEffectiveStatement;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 
+@Deprecated(forRemoval = true)
 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;
@@ -40,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<>();
@@ -48,42 +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);
-                }
-
-                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,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