2 * Copyright (c) 2016 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
9 package org.opendaylight.yangtools.yang.parser.stmt.rfc7950.effective;
11 import com.google.common.base.MoreObjects;
12 import com.google.common.collect.ImmutableSet;
13 import java.util.HashSet;
14 import java.util.LinkedHashSet;
15 import java.util.Objects;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.model.api.ActionDefinition;
19 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
21 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
22 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
23 import org.opendaylight.yangtools.yang.model.api.stmt.ActionStatement;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
25 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.AbstractEffectiveSchemaNode;
26 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveStmtUtils;
27 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.InputEffectiveStatementImpl;
28 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.OutputEffectiveStatementImpl;
29 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.TypeDefEffectiveStatementImpl;
31 public class ActionEffectiveStatementImpl extends AbstractEffectiveSchemaNode<ActionStatement>
32 implements ActionDefinition {
33 private final ContainerSchemaNode input;
34 private final ContainerSchemaNode output;
35 private final Set<TypeDefinition<?>> typeDefinitions;
36 private final Set<GroupingDefinition> groupings;
38 public ActionEffectiveStatementImpl(
39 final StmtContext<QName, ActionStatement, EffectiveStatement<QName, ActionStatement>> ctx) {
41 this.input = firstEffective(InputEffectiveStatementImpl.class);
42 this.output = firstEffective(OutputEffectiveStatementImpl.class);
45 Set<GroupingDefinition> groupingsInit = new HashSet<>();
46 Set<TypeDefinition<?>> mutableTypeDefinitions = new LinkedHashSet<>();
47 for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
48 if (effectiveStatement instanceof GroupingDefinition) {
49 GroupingDefinition groupingDefinition = (GroupingDefinition) effectiveStatement;
50 groupingsInit.add(groupingDefinition);
52 if (effectiveStatement instanceof TypeDefEffectiveStatementImpl) {
53 TypeDefEffectiveStatementImpl typeDef = (TypeDefEffectiveStatementImpl) effectiveStatement;
54 TypeDefinition<?> type = typeDef.getTypeDefinition();
55 if (!mutableTypeDefinitions.contains(type)) {
56 mutableTypeDefinitions.add(type);
58 throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement);
62 this.groupings = ImmutableSet.copyOf(groupingsInit);
63 this.typeDefinitions = ImmutableSet.copyOf(mutableTypeDefinitions);
67 public ContainerSchemaNode getInput() {
72 public ContainerSchemaNode getOutput() {
77 public Set<TypeDefinition<?>> getTypeDefinitions() {
78 return typeDefinitions;
82 public Set<GroupingDefinition> getGroupings() {
87 public int hashCode() {
88 return Objects.hash(getQName(), getPath());
92 public boolean equals(final Object obj) {
101 if (getClass() != obj.getClass()) {
105 final ActionEffectiveStatementImpl other = (ActionEffectiveStatementImpl) obj;
106 return Objects.equals(getQName(), other.getQName()) && Objects.equals(getPath(), other.getPath());
110 public String toString() {
111 return MoreObjects.toStringHelper(this).add("qname", getQName()).add("path", getPath()).add("input", input)
112 .add("output", output).toString();