2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
10 import com.google.common.collect.ImmutableSet;
11 import java.util.Collection;
12 import java.util.HashSet;
13 import java.util.LinkedHashSet;
14 import java.util.Objects;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
19 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
20 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
21 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
22 import org.opendaylight.yangtools.yang.model.api.stmt.RpcStatement;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
25 public class RpcEffectiveStatementImpl extends AbstractEffectiveSchemaNode<RpcStatement> implements RpcDefinition {
26 private final ContainerSchemaNode input;
27 private final ContainerSchemaNode output;
28 private final Set<TypeDefinition<?>> typeDefinitions;
29 private final Set<GroupingDefinition> groupings;
31 public RpcEffectiveStatementImpl(final StmtContext<QName, RpcStatement, EffectiveStatement<QName, RpcStatement>> ctx) {
33 this.input = firstEffective(InputEffectiveStatementImpl.class);
34 this.output = firstEffective(OutputEffectiveStatementImpl.class);
37 Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
38 Set<GroupingDefinition> groupingsInit = new HashSet<>();
39 Set<TypeDefinition<?>> mutableTypeDefinitions = new LinkedHashSet<>();
40 for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
41 if (effectiveStatement instanceof GroupingDefinition) {
42 GroupingDefinition groupingDefinition = (GroupingDefinition) effectiveStatement;
43 groupingsInit.add(groupingDefinition);
45 if (effectiveStatement instanceof TypeDefEffectiveStatementImpl) {
46 TypeDefEffectiveStatementImpl typeDef = (TypeDefEffectiveStatementImpl) effectiveStatement;
47 TypeDefinition<?> type = typeDef.getTypeDefinition();
48 if (!mutableTypeDefinitions.contains(type)) {
49 mutableTypeDefinitions.add(type);
51 throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement);
55 this.groupings = ImmutableSet.copyOf(groupingsInit);
56 this.typeDefinitions = ImmutableSet.copyOf(mutableTypeDefinitions);
60 public ContainerSchemaNode getInput() {
65 public ContainerSchemaNode getOutput() {
70 public Set<TypeDefinition<?>> getTypeDefinitions() {
71 return typeDefinitions;
75 public Set<GroupingDefinition> getGroupings() {
80 public int hashCode() {
83 result = prime * result + Objects.hashCode(getQName());
84 result = prime * result + Objects.hashCode(getPath());
89 public boolean equals(final Object obj) {
96 if (getClass() != obj.getClass()) {
99 final RpcEffectiveStatementImpl other = (RpcEffectiveStatementImpl) obj;
100 return Objects.equals(getQName(), other.getQName()) && Objects.equals(getPath(), other.getPath());
104 public String toString() {
105 return RpcEffectiveStatementImpl.class.getSimpleName() + "[" +