/* * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.yangtools.yang.parser.rfc7950.stmt; import com.google.common.collect.ImmutableSet; import java.util.Collection; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.Optional; import java.util.Set; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.GroupingDefinition; import org.opendaylight.yangtools.yang.model.api.TypeDefinition; 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.spi.meta.StmtContext; public abstract class AbstractEffectiveDocumentedDataNodeContainer> extends AbstractSchemaEffectiveDocumentedNode implements DataNodeContainer { private final ImmutableSet groupings; private final ImmutableSet uses; private final ImmutableSet> typeDefinitions; private final ImmutableSet publicChildNodes; protected AbstractEffectiveDocumentedDataNodeContainer(final StmtContext ctx) { super(ctx); Set mutableGroupings = new HashSet<>(); Set mutableUses = new HashSet<>(); Set> mutableTypeDefinitions = new LinkedHashSet<>(); Set mutablePublicChildNodes = new LinkedHashSet<>(); for (EffectiveStatement stmt : effectiveSubstatements()) { if (stmt instanceof DataSchemaNode) { mutablePublicChildNodes.add((DataSchemaNode) stmt); } if (stmt instanceof UsesNode && !mutableUses.add((UsesNode) stmt)) { throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, stmt); } if (stmt instanceof TypedefEffectiveStatement && !mutableTypeDefinitions.add(((TypedefEffectiveStatement) stmt).getTypeDefinition())) { throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, stmt); } if (stmt instanceof GroupingDefinition && !mutableGroupings.add((GroupingDefinition) stmt)) { throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, stmt); } } this.groupings = ImmutableSet.copyOf(mutableGroupings); this.publicChildNodes = ImmutableSet.copyOf(mutablePublicChildNodes); this.typeDefinitions = ImmutableSet.copyOf(mutableTypeDefinitions); this.uses = ImmutableSet.copyOf(mutableUses); } @Override public final Collection> getTypeDefinitions() { return typeDefinitions; } @Override public final Collection getChildNodes() { return publicChildNodes; } @Override public final Set getGroupings() { return groupings; } @Override public final Optional findDataChildByName(final QName name) { return findDataSchemaNode(name); } @Override public Set getUses() { return uses; } }