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
8 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
10 import com.google.common.collect.ImmutableSet;
11 import com.google.common.collect.ImmutableSet.Builder;
12 import java.util.Objects;
13 import java.util.Optional;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.model.api.ActionDefinition;
17 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
20 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
21 import org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement;
22 import org.opendaylight.yangtools.yang.model.api.stmt.ContainerStatement;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
25 public final class ContainerEffectiveStatementImpl extends AbstractEffectiveContainerSchemaNode<ContainerStatement>
26 implements ContainerEffectiveStatement, DerivableSchemaNode {
27 private final Set<ActionDefinition> actions;
28 private final Set<NotificationDefinition> notifications;
29 private final ContainerSchemaNode original;
31 public ContainerEffectiveStatementImpl(
32 final StmtContext<QName, ContainerStatement, EffectiveStatement<QName, ContainerStatement>> ctx) {
34 this.original = (ContainerSchemaNode) ctx.getOriginalCtx().map(StmtContext::buildEffective).orElse(null);
35 final ImmutableSet.Builder<ActionDefinition> actionsBuilder = ImmutableSet.builder();
36 final Builder<NotificationDefinition> notificationsBuilder = ImmutableSet.builder();
37 for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
38 if (effectiveStatement instanceof ActionDefinition) {
39 actionsBuilder.add((ActionDefinition) effectiveStatement);
42 if (effectiveStatement instanceof NotificationDefinition) {
43 notificationsBuilder.add((NotificationDefinition) effectiveStatement);
47 this.actions = actionsBuilder.build();
48 this.notifications = notificationsBuilder.build();
52 public Optional<ContainerSchemaNode> getOriginal() {
53 return Optional.ofNullable(original);
57 public Set<ActionDefinition> getActions() {
62 public Set<NotificationDefinition> getNotifications() {
67 public int hashCode() {
70 result = prime * result + Objects.hashCode(getQName());
71 result = prime * result + Objects.hashCode(getPath());
76 public boolean equals(final Object obj) {
83 if (getClass() != obj.getClass()) {
86 final ContainerEffectiveStatementImpl other = (ContainerEffectiveStatementImpl) obj;
87 return Objects.equals(getQName(), other.getQName()) && Objects.equals(getPath(), other.getPath());
91 public String toString() {
92 return "container " + getQName().getLocalName();