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.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.RpcStatement;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
24 public class RpcEffectiveStatementImpl extends AbstractEffectiveSchemaNode<RpcStatement> implements RpcDefinition {
25 private final ContainerSchemaNode input;
26 private final ContainerSchemaNode output;
27 private final Set<TypeDefinition<?>> typeDefinitions;
28 private final Set<GroupingDefinition> groupings;
30 public RpcEffectiveStatementImpl(final StmtContext<QName, RpcStatement, EffectiveStatement<QName, RpcStatement>> ctx) {
32 this.input = firstEffective(InputEffectiveStatementImpl.class);
33 this.output = firstEffective(OutputEffectiveStatementImpl.class);
36 Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
37 Set<GroupingDefinition> groupingsInit = new HashSet<>();
38 Set<TypeDefinition<?>> typeDefinitionsInit = new HashSet<>();
39 for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
40 if (effectiveStatement instanceof GroupingDefinition) {
41 GroupingDefinition groupingDefinition = (GroupingDefinition) effectiveStatement;
42 groupingsInit.add(groupingDefinition);
44 if (effectiveStatement instanceof TypeDefinition) {
45 TypeDefinition<?> typeDefinition = (TypeDefinition<?>) effectiveStatement;
46 typeDefinitionsInit.add(typeDefinition);
49 this.groupings = ImmutableSet.copyOf(groupingsInit);
50 this.typeDefinitions = ImmutableSet.copyOf(typeDefinitionsInit);
54 public ContainerSchemaNode getInput() {
59 public ContainerSchemaNode getOutput() {
64 public Set<TypeDefinition<?>> getTypeDefinitions() {
65 return typeDefinitions;
69 public Set<GroupingDefinition> getGroupings() {
74 public int hashCode() {
77 result = prime * result + Objects.hashCode(getQName());
78 result = prime * result + Objects.hashCode(getPath());
83 public boolean equals(final Object obj) {
90 if (getClass() != obj.getClass()) {
93 final RpcEffectiveStatementImpl other = (RpcEffectiveStatementImpl) obj;
94 return Objects.equals(getQName(), other.getQName()) && Objects.equals(getPath(), other.getPath());
98 public String toString() {
99 StringBuilder sb = new StringBuilder(RpcEffectiveStatementImpl.class.getSimpleName());
102 sb.append(getQName());
103 sb.append(", path=");
104 sb.append(getPath());
105 sb.append(", input=");
107 sb.append(", output=");
110 return sb.toString();