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 static com.google.common.base.Verify.verifyNotNull;
13 import com.google.common.collect.ImmutableList;
14 import com.google.common.collect.ImmutableSet;
15 import java.util.List;
16 import java.util.Objects;
18 import org.eclipse.jdt.annotation.NonNull;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.model.api.ActionDefinition;
21 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
22 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
23 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
24 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
25 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
26 import org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement;
27 import org.opendaylight.yangtools.yang.model.api.stmt.GroupingStatement;
28 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractEffectiveDocumentedDataNodeContainer;
29 import org.opendaylight.yangtools.yang.parser.spi.meta.CopyType;
30 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
32 final class GroupingEffectiveStatementImpl
33 extends AbstractEffectiveDocumentedDataNodeContainer<QName, GroupingStatement>
34 implements GroupingDefinition, GroupingEffectiveStatement {
35 private final @NonNull QName qname;
36 private final @NonNull SchemaPath path;
37 private final boolean addedByUses;
38 private final @NonNull Set<ActionDefinition> actions;
39 private final @NonNull Set<NotificationDefinition> notifications;
40 private final @NonNull List<UnknownSchemaNode> unknownNodes;
42 GroupingEffectiveStatementImpl(
43 final StmtContext<QName, GroupingStatement, EffectiveStatement<QName, GroupingStatement>> ctx) {
46 qname = verifyNotNull(ctx.getStatementArgument());
47 path = ctx.getSchemaPath().get();
48 addedByUses = ctx.getCopyHistory().contains(CopyType.ADDED_BY_USES);
50 final ImmutableSet.Builder<ActionDefinition> actionsBuilder = ImmutableSet.builder();
51 final ImmutableSet.Builder<NotificationDefinition> notificationsBuilder = ImmutableSet.builder();
52 final ImmutableList.Builder<UnknownSchemaNode> b = ImmutableList.builder();
53 for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
54 if (effectiveStatement instanceof ActionDefinition) {
55 actionsBuilder.add((ActionDefinition) effectiveStatement);
58 if (effectiveStatement instanceof NotificationDefinition) {
59 notificationsBuilder.add((NotificationDefinition) effectiveStatement);
62 if (effectiveStatement instanceof UnknownSchemaNode) {
63 b.add((UnknownSchemaNode) effectiveStatement);
67 this.actions = actionsBuilder.build();
68 this.notifications = notificationsBuilder.build();
69 unknownNodes = b.build();
73 public QName getQName() {
78 public SchemaPath getPath() {
83 public boolean isAddedByUses() {
88 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 + "]";