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.HashSet;
12 import java.util.LinkedHashSet;
13 import java.util.Objects;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
17 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
18 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
19 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
20 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
21 import org.opendaylight.yangtools.yang.model.api.stmt.RpcEffectiveStatement;
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>
26 implements RpcDefinition, RpcEffectiveStatement {
27 private final ContainerSchemaNode input;
28 private final ContainerSchemaNode output;
29 private final Set<TypeDefinition<?>> typeDefinitions;
30 private final Set<GroupingDefinition> groupings;
32 public RpcEffectiveStatementImpl(final StmtContext<QName, RpcStatement,
33 EffectiveStatement<QName, RpcStatement>> ctx) {
35 this.input = firstEffective(InputEffectiveStatementImpl.class);
36 this.output = firstEffective(OutputEffectiveStatementImpl.class);
39 Set<GroupingDefinition> groupingsInit = new HashSet<>();
40 Set<TypeDefinition<?>> mutableTypeDefinitions = new LinkedHashSet<>();
41 for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
42 if (effectiveStatement instanceof GroupingDefinition) {
43 GroupingDefinition groupingDefinition = (GroupingDefinition) effectiveStatement;
44 groupingsInit.add(groupingDefinition);
46 if (effectiveStatement instanceof TypeDefEffectiveStatementImpl) {
47 TypeDefEffectiveStatementImpl typeDef = (TypeDefEffectiveStatementImpl) effectiveStatement;
48 TypeDefinition<?> type = typeDef.getTypeDefinition();
49 if (!mutableTypeDefinitions.contains(type)) {
50 mutableTypeDefinitions.add(type);
52 throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement);
56 this.groupings = ImmutableSet.copyOf(groupingsInit);
57 this.typeDefinitions = ImmutableSet.copyOf(mutableTypeDefinitions);
61 public ContainerSchemaNode getInput() {
66 public ContainerSchemaNode getOutput() {
71 public Set<TypeDefinition<?>> getTypeDefinitions() {
72 return typeDefinitions;
76 public Set<GroupingDefinition> getGroupings() {
81 public int hashCode() {
84 result = prime * result + Objects.hashCode(getQName());
85 result = prime * result + Objects.hashCode(getPath());
90 public boolean equals(final Object obj) {
97 if (getClass() != obj.getClass()) {
100 final RpcEffectiveStatementImpl other = (RpcEffectiveStatementImpl) obj;
101 return Objects.equals(getQName(), other.getQName()) && Objects.equals(getPath(), other.getPath());
105 public String toString() {
106 return RpcEffectiveStatementImpl.class.getSimpleName() + "["
107 + "qname=" + getQName()
108 + ", path=" + getPath()
110 + ", output=" + output