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;
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.spi.meta.CopyType;
27 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
29 public class GroupingEffectiveStatementImpl
30 extends AbstractEffectiveDocumentedDataNodeContainer<QName, GroupingStatement>
31 implements GroupingDefinition, GroupingEffectiveStatement {
32 private final QName qname;
33 private final SchemaPath path;
34 private final boolean addedByUses;
35 private final Set<ActionDefinition> actions;
36 private final Set<NotificationDefinition> notifications;
37 private final List<UnknownSchemaNode> unknownNodes;
39 public GroupingEffectiveStatementImpl(
40 final StmtContext<QName, GroupingStatement, EffectiveStatement<QName, GroupingStatement>> ctx) {
43 qname = ctx.getStatementArgument();
44 path = ctx.getSchemaPath().get();
45 addedByUses = ctx.getCopyHistory().contains(CopyType.ADDED_BY_USES);
47 final ImmutableSet.Builder<ActionDefinition> actionsBuilder = ImmutableSet.builder();
48 final ImmutableSet.Builder<NotificationDefinition> notificationsBuilder = ImmutableSet.builder();
49 final ImmutableList.Builder<UnknownSchemaNode> b = ImmutableList.builder();
50 for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
51 if (effectiveStatement instanceof ActionDefinition) {
52 actionsBuilder.add((ActionDefinition) effectiveStatement);
55 if (effectiveStatement instanceof NotificationDefinition) {
56 notificationsBuilder.add((NotificationDefinition) effectiveStatement);
59 if (effectiveStatement instanceof UnknownSchemaNode) {
60 b.add((UnknownSchemaNode) effectiveStatement);
64 this.actions = actionsBuilder.build();
65 this.notifications = notificationsBuilder.build();
66 unknownNodes = b.build();
71 public QName getQName() {
77 public SchemaPath getPath() {
82 public boolean isAddedByUses() {
87 public Set<ActionDefinition> getActions() {
93 public Set<NotificationDefinition> getNotifications() {
98 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
103 public int hashCode() {
104 final int prime = 31;
106 result = prime * result + Objects.hashCode(qname);
107 result = prime * result + Objects.hashCode(path);
112 public boolean equals(final Object obj) {
119 if (getClass() != obj.getClass()) {
122 final GroupingEffectiveStatementImpl other = (GroupingEffectiveStatementImpl) obj;
123 return Objects.equals(qname, other.qname) && Objects.equals(path, other.path);
127 public String toString() {
128 return GroupingEffectiveStatementImpl.class.getSimpleName() + "[" + "qname=" + qname + "]";