/**
* 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.stmt.rfc6020.effective;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableMap;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
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;
public abstract class AbstractEffectiveDocumentedDataNodeContainer>
extends AbstractEffectiveDocumentedNode implements
DataNodeContainer {
private final ImmutableMap childNodes;
private final ImmutableSet groupings;
private final ImmutableSet uses;
private final ImmutableSet> typeDefinitions;
private final ImmutableSet publicChildNodes;
protected AbstractEffectiveDocumentedDataNodeContainer(
final StmtContext ctx) {
super(ctx);
Collection extends EffectiveStatement, ?>> effectiveSubstatements = effectiveSubstatements();
HashMap childNodes = new HashMap();
HashSet groupings = new HashSet();
HashSet uses = new HashSet();
HashSet> typeDefinitions = new HashSet>();
HashSet publicChildNodes = new HashSet();
for (EffectiveStatement, ?> effectiveStatement : effectiveSubstatements) {
if (effectiveStatement instanceof DataSchemaNode) {
DataSchemaNode dataSchemaNode = (DataSchemaNode) effectiveStatement;
childNodes.put(dataSchemaNode.getQName(), dataSchemaNode);
publicChildNodes.add(dataSchemaNode);
}
if (effectiveStatement instanceof UsesNode) {
UsesNode usesNode = (UsesNode) effectiveStatement;
uses.add(usesNode);
}
if (effectiveStatement instanceof TypeDefinition) {
TypeDefinition> typeDef = (TypeDefinition>) effectiveStatement;
typeDefinitions.add(typeDef);
}
if (effectiveStatement instanceof GroupingDefinition) {
GroupingDefinition grp = (GroupingDefinition) effectiveStatement;
groupings.add(grp);
}
}
this.childNodes = ImmutableMap.copyOf(childNodes);
this.groupings = ImmutableSet.copyOf(groupings);
this.publicChildNodes = ImmutableSet.copyOf(publicChildNodes);
this.typeDefinitions = ImmutableSet.copyOf(typeDefinitions);
this.uses = ImmutableSet.copyOf(uses);
}
@Override
public final Set> getTypeDefinitions() {
return typeDefinitions;
}
@Override
public final Set getChildNodes() {
return publicChildNodes;
}
@Override
public final Set getGroupings() {
return groupings;
}
@Override
public final DataSchemaNode getDataChildByName(final QName name) {
// Child nodes are keyed by their container name, so we can do a direct
// lookup
return childNodes.get(name);
}
@Override
public final DataSchemaNode getDataChildByName(final String name) {
for (DataSchemaNode node : childNodes.values()) {
if (node.getQName().getLocalName().equals(name)) {
return node;
}
}
return null;
}
@Override
public Set getUses() {
return uses;
}
}