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.ImmutableList;
11 import com.google.common.collect.ImmutableSet;
12 import java.util.Collection;
13 import java.util.HashSet;
14 import java.util.LinkedList;
15 import java.util.List;
16 import java.util.Objects;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
20 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
21 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
22 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
23 import org.opendaylight.yangtools.yang.model.api.stmt.NotificationStatement;
24 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
25 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
26 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
28 public class NotificationEffectiveStatementImpl
29 extends AbstractEffectiveDocumentedDataNodeContainer<QName, NotificationStatement>
30 implements NotificationDefinition {
31 private final QName qname;
32 private final SchemaPath path;
33 ImmutableSet<AugmentationSchema> augmentations;
34 ImmutableList<UnknownSchemaNode> unknownNodes;
36 public NotificationEffectiveStatementImpl(
37 StmtContext<QName, NotificationStatement, EffectiveStatement<QName, NotificationStatement>> ctx) {
39 this.qname = ctx.getStatementArgument();
40 this.path = Utils.getSchemaPath(ctx);
42 initSubstatementCollections();
45 private void initSubstatementCollections() {
46 Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
48 List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
49 Set<AugmentationSchema> augmentationsInit = new HashSet<>();
51 for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
52 if (effectiveStatement instanceof UnknownSchemaNode) {
53 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
54 unknownNodesInit.add(unknownNode);
56 if (effectiveStatement instanceof AugmentationSchema) {
57 AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
58 augmentationsInit.add(augmentationSchema);
62 this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
63 this.augmentations = ImmutableSet.copyOf(augmentationsInit);
67 public QName getQName() {
72 public SchemaPath getPath() {
77 public Set<AugmentationSchema> getAvailableAugmentations() {
82 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
87 public int hashCode() {
90 result = prime * result + Objects.hashCode(qname);
91 result = prime * result + Objects.hashCode(path);
96 public boolean equals(final Object obj) {
103 if (getClass() != obj.getClass()) {
106 final NotificationEffectiveStatementImpl other = (NotificationEffectiveStatementImpl) obj;
108 if (other.qname != null) {
111 } else if (!qname.equals(other.qname)) {
115 if (other.path != null) {
118 } else if (!path.equals(other.path)) {
125 public String toString() {
126 StringBuilder sb = new StringBuilder(
127 NotificationEffectiveStatementImpl.class.getSimpleName());
128 sb.append("[qname=").append(qname).append(", path=").append(path)
130 return sb.toString();