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.stmt.rfc6020.effective;
11 import com.google.common.collect.ImmutableList;
12 import com.google.common.collect.ImmutableSet;
13 import java.util.List;
14 import java.util.Objects;
15 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.GroupingStatement;
25 import org.opendaylight.yangtools.yang.parser.spi.meta.CopyType;
26 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
28 public class GroupingEffectiveStatementImpl extends
29 AbstractEffectiveDocumentedDataNodeContainer<QName, GroupingStatement> implements GroupingDefinition {
30 private final QName qname;
31 private final SchemaPath path;
32 private final boolean addedByUses;
33 private final Set<ActionDefinition> actions;
34 private final Set<NotificationDefinition> notifications;
35 private final List<UnknownSchemaNode> unknownNodes;
37 public GroupingEffectiveStatementImpl(
38 final StmtContext<QName, GroupingStatement, EffectiveStatement<QName, GroupingStatement>> ctx) {
41 qname = ctx.getStatementArgument();
42 path = ctx.getSchemaPath().get();
44 addedByUses = ctx.getCopyHistory().contains(CopyType.ADDED_BY_USES);
46 final ImmutableSet.Builder<ActionDefinition> actionsBuilder = ImmutableSet.builder();
47 final ImmutableSet.Builder<NotificationDefinition> notificationsBuilder = ImmutableSet.builder();
48 final ImmutableList.Builder<UnknownSchemaNode> b = ImmutableList.builder();
49 for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
50 if (effectiveStatement instanceof ActionDefinition) {
51 actionsBuilder.add((ActionDefinition) effectiveStatement);
54 if (effectiveStatement instanceof NotificationDefinition) {
55 notificationsBuilder.add((NotificationDefinition) effectiveStatement);
58 if (effectiveStatement instanceof UnknownSchemaNode) {
59 b.add((UnknownSchemaNode) effectiveStatement);
63 this.actions = actionsBuilder.build();
64 this.notifications = notificationsBuilder.build();
65 unknownNodes = b.build();
70 public QName getQName() {
76 public SchemaPath getPath() {
81 public boolean isAddedByUses() {
86 public Set<ActionDefinition> getActions() {
92 public Set<NotificationDefinition> getNotifications() {
97 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
102 public int hashCode() {
103 final int prime = 31;
105 result = prime * result + Objects.hashCode(qname);
106 result = prime * result + Objects.hashCode(path);
111 public boolean equals(final Object obj) {
118 if (getClass() != obj.getClass()) {
121 final GroupingEffectiveStatementImpl other = (GroupingEffectiveStatementImpl) obj;
122 return Objects.equals(qname, other.qname) && Objects.equals(path, other.path);
126 public String toString() {
127 return GroupingEffectiveStatementImpl.class.getSimpleName() + "[" + "qname=" + qname + "]";