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
9 package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.grouping;
11 import com.google.common.collect.ImmutableList;
12 import com.google.common.collect.ImmutableSet;
13 import java.util.List;
14 import java.util.Objects;
16 import javax.annotation.Nonnull;
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.GroupingDefinition;
20 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
21 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
22 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
24 import org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement;
25 import org.opendaylight.yangtools.yang.model.api.stmt.GroupingStatement;
26 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractEffectiveDocumentedDataNodeContainer;
27 import org.opendaylight.yangtools.yang.parser.spi.meta.CopyType;
28 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
30 final class GroupingEffectiveStatementImpl
31 extends AbstractEffectiveDocumentedDataNodeContainer<QName, GroupingStatement>
32 implements GroupingDefinition, GroupingEffectiveStatement {
33 private final QName qname;
34 private final SchemaPath path;
35 private final boolean addedByUses;
36 private final Set<ActionDefinition> actions;
37 private final Set<NotificationDefinition> notifications;
38 private final List<UnknownSchemaNode> unknownNodes;
40 GroupingEffectiveStatementImpl(
41 final StmtContext<QName, GroupingStatement, EffectiveStatement<QName, GroupingStatement>> ctx) {
44 qname = ctx.getStatementArgument();
45 path = ctx.getSchemaPath().get();
46 addedByUses = ctx.getCopyHistory().contains(CopyType.ADDED_BY_USES);
48 final ImmutableSet.Builder<ActionDefinition> actionsBuilder = ImmutableSet.builder();
49 final ImmutableSet.Builder<NotificationDefinition> notificationsBuilder = ImmutableSet.builder();
50 final ImmutableList.Builder<UnknownSchemaNode> b = ImmutableList.builder();
51 for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
52 if (effectiveStatement instanceof ActionDefinition) {
53 actionsBuilder.add((ActionDefinition) effectiveStatement);
56 if (effectiveStatement instanceof NotificationDefinition) {
57 notificationsBuilder.add((NotificationDefinition) effectiveStatement);
60 if (effectiveStatement instanceof UnknownSchemaNode) {
61 b.add((UnknownSchemaNode) effectiveStatement);
65 this.actions = actionsBuilder.build();
66 this.notifications = notificationsBuilder.build();
67 unknownNodes = b.build();
72 public QName getQName() {
78 public SchemaPath getPath() {
83 public boolean isAddedByUses() {
88 public Set<ActionDefinition> getActions() {
94 public Set<NotificationDefinition> getNotifications() {
99 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
104 public int hashCode() {
105 final int prime = 31;
107 result = prime * result + Objects.hashCode(qname);
108 result = prime * result + Objects.hashCode(path);
113 public boolean equals(final Object obj) {
120 if (getClass() != obj.getClass()) {
123 final GroupingEffectiveStatementImpl other = (GroupingEffectiveStatementImpl) obj;
124 return Objects.equals(qname, other.qname) && Objects.equals(path, other.path);
128 public String toString() {
129 return GroupingEffectiveStatementImpl.class.getSimpleName() + "[" + "qname=" + qname + "]";