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 org.eclipse.jdt.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 @NonNull QName qname;
34 private final @NonNull SchemaPath path;
35 private final boolean addedByUses;
36 private final @NonNull Set<ActionDefinition> actions;
37 private final @NonNull Set<NotificationDefinition> notifications;
38 private final @NonNull List<UnknownSchemaNode> unknownNodes;
40 GroupingEffectiveStatementImpl(
41 final StmtContext<QName, GroupingStatement, EffectiveStatement<QName, GroupingStatement>> ctx) {
44 qname = ctx.coerceStatementArgument();
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();
71 public QName getQName() {
76 public SchemaPath getPath() {
81 public boolean isAddedByUses() {
86 public Set<ActionDefinition> getActions() {
91 public Set<NotificationDefinition> getNotifications() {
96 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
101 public int hashCode() {
102 final int prime = 31;
104 result = prime * result + Objects.hashCode(qname);
105 result = prime * result + Objects.hashCode(path);
110 public boolean equals(final Object obj) {
117 if (getClass() != obj.getClass()) {
120 final GroupingEffectiveStatementImpl other = (GroupingEffectiveStatementImpl) obj;
121 return Objects.equals(qname, other.qname) && Objects.equals(path, other.path);
125 public String toString() {
126 return GroupingEffectiveStatementImpl.class.getSimpleName() + "[" + "qname=" + qname + "]";