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.base.Optional;
11 import com.google.common.collect.ImmutableSet;
12 import com.google.common.collect.ImmutableSet.Builder;
13 import java.util.Objects;
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.ContainerStatement;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
24 public final class ContainerEffectiveStatementImpl extends AbstractEffectiveContainerSchemaNode<ContainerStatement> implements
26 private final Set<ActionDefinition> actions;
27 private final Set<NotificationDefinition> notifications;
28 private final ContainerSchemaNode original;
30 public ContainerEffectiveStatementImpl(
31 final StmtContext<QName, ContainerStatement, EffectiveStatement<QName, ContainerStatement>> ctx) {
33 this.original = (ContainerSchemaNode) ctx.getOriginalCtx().map(StmtContext::buildEffective).orElse(null);
34 final ImmutableSet.Builder<ActionDefinition> actionsBuilder = ImmutableSet.builder();
35 final Builder<NotificationDefinition> notificationsBuilder = ImmutableSet.builder();
36 for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
37 if (effectiveStatement instanceof ActionDefinition) {
38 actionsBuilder.add((ActionDefinition) effectiveStatement);
41 if (effectiveStatement instanceof NotificationDefinition) {
42 notificationsBuilder.add((NotificationDefinition) effectiveStatement);
46 this.actions = actionsBuilder.build();
47 this.notifications = notificationsBuilder.build();
51 public Optional<ContainerSchemaNode> getOriginal() {
52 return Optional.fromNullable(original);
56 public Set<ActionDefinition> getActions() {
61 public Set<NotificationDefinition> getNotifications() {
66 public int hashCode() {
69 result = prime * result + Objects.hashCode(getQName());
70 result = prime * result + Objects.hashCode(getPath());
75 public boolean equals(final Object obj) {
82 if (getClass() != obj.getClass()) {
85 final ContainerEffectiveStatementImpl other = (ContainerEffectiveStatementImpl) obj;
86 return Objects.equals(getQName(), other.getQName()) && Objects.equals(getPath(), other.getPath());
90 public String toString() {
91 return "container " + getQName().getLocalName();