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 java.util.Collection;
11 import java.util.HashSet;
12 import java.util.LinkedList;
14 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
15 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
16 import org.opendaylight.yangtools.yang.model.api.stmt.NotificationStatement;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
18 import com.google.common.collect.ImmutableList;
19 import com.google.common.collect.ImmutableSet;
20 import java.util.List;
22 import org.opendaylight.yangtools.yang.common.QName;
23 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
24 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
25 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
26 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
28 public class NotificationEffectiveStatementImpl
30 AbstractEffectiveDocumentedDataNodeContainer<QName, NotificationStatement>
31 implements NotificationDefinition {
32 private final QName qname;
33 private final SchemaPath path;
34 ImmutableSet<AugmentationSchema> augmentations;
35 ImmutableList<UnknownSchemaNode> unknownNodes;
37 public NotificationEffectiveStatementImpl(
38 StmtContext<QName, NotificationStatement, EffectiveStatement<QName, NotificationStatement>> ctx) {
40 this.qname = ctx.getStatementArgument();
41 this.path = Utils.getSchemaPath(ctx);
43 initSubstatementCollections();
46 private void initSubstatementCollections() {
47 Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
49 List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
50 Set<AugmentationSchema> augmentationsInit = new HashSet<>();
52 for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
53 if (effectiveStatement instanceof UnknownSchemaNode) {
54 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
55 unknownNodesInit.add(unknownNode);
57 if (effectiveStatement instanceof AugmentationSchema) {
58 AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
59 augmentationsInit.add(augmentationSchema);
63 this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
64 this.augmentations = ImmutableSet.copyOf(augmentationsInit);
68 public QName getQName() {
73 public SchemaPath getPath() {
78 public Set<AugmentationSchema> getAvailableAugmentations() {
83 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
88 public int hashCode() {
91 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
92 result = prime * result + ((path == null) ? 0 : path.hashCode());
97 public boolean equals(final Object obj) {
104 if (getClass() != obj.getClass()) {
107 final NotificationEffectiveStatementImpl other = (NotificationEffectiveStatementImpl) obj;
109 if (other.qname != null) {
112 } else if (!qname.equals(other.qname)) {
116 if (other.path != null) {
119 } else if (!path.equals(other.path)) {
126 public String toString() {
127 StringBuilder sb = new StringBuilder(
128 NotificationEffectiveStatementImpl.class.getSimpleName());
129 sb.append("[qname=").append(qname).append(", path=").append(path)
131 return sb.toString();