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.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();
43 addedByUses = ctx.getCopyHistory().contains(CopyType.ADDED_BY_USES);
45 final ImmutableSet.Builder<ActionDefinition> actionsBuilder = ImmutableSet.builder();
46 final ImmutableSet.Builder<NotificationDefinition> notificationsBuilder = ImmutableSet.builder();
47 final ImmutableList.Builder<UnknownSchemaNode> b = ImmutableList.builder();
48 for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
49 if (effectiveStatement instanceof ActionDefinition) {
50 actionsBuilder.add((ActionDefinition) effectiveStatement);
53 if (effectiveStatement instanceof NotificationDefinition) {
54 notificationsBuilder.add((NotificationDefinition) effectiveStatement);
57 if (effectiveStatement instanceof UnknownSchemaNode) {
58 b.add((UnknownSchemaNode) effectiveStatement);
62 this.actions = actionsBuilder.build();
63 this.notifications = notificationsBuilder.build();
64 unknownNodes = b.build();
69 public QName getQName() {
75 public SchemaPath getPath() {
80 public boolean isAddedByUses() {
85 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 + "]";