*/
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;
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;
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<>();
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);
@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