a33d19e7d77e3ff132dd7c83f7f026222864d634
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / NotificationEffectiveStatementImpl.java
1 /**
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
9
10 import com.google.common.collect.ImmutableList;
11 import com.google.common.collect.ImmutableSet;
12 import java.util.Collection;
13 import java.util.LinkedHashSet;
14 import java.util.LinkedList;
15 import java.util.List;
16 import java.util.Objects;
17 import java.util.Set;
18 import javax.annotation.Nonnull;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
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.UnknownSchemaNode;
24 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
25 import org.opendaylight.yangtools.yang.model.api.stmt.NotificationStatement;
26 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
27
28 public class NotificationEffectiveStatementImpl extends
29         AbstractEffectiveDocumentedDataNodeContainer<QName, NotificationStatement> implements NotificationDefinition {
30     private final QName qname;
31     private final SchemaPath path;
32     private final Set<AugmentationSchema> augmentations;
33     private final List<UnknownSchemaNode> unknownNodes;
34
35     public NotificationEffectiveStatementImpl(
36             final StmtContext<QName, NotificationStatement, EffectiveStatement<QName, NotificationStatement>> ctx) {
37         super(ctx);
38         this.qname = ctx.getStatementArgument();
39         this.path = ctx.getSchemaPath().get();
40
41         // initSubstatementCollections
42         Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
43         List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
44         Set<AugmentationSchema> augmentationsInit = new LinkedHashSet<>();
45         for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
46             if (effectiveStatement instanceof UnknownSchemaNode) {
47                 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
48                 unknownNodesInit.add(unknownNode);
49             }
50             if (effectiveStatement instanceof AugmentationSchema) {
51                 AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
52                 augmentationsInit.add(augmentationSchema);
53             }
54         }
55         this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
56         this.augmentations = ImmutableSet.copyOf(augmentationsInit);
57     }
58
59     @Nonnull
60     @Override
61     public QName getQName() {
62         return qname;
63     }
64
65     @Nonnull
66     @Override
67     public SchemaPath getPath() {
68         return path;
69     }
70
71     @Override
72     public Set<AugmentationSchema> getAvailableAugmentations() {
73         return augmentations;
74     }
75
76     @Nonnull
77     @Override
78     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
79         return unknownNodes;
80     }
81
82     @Override
83     public int hashCode() {
84         final int prime = 31;
85         int result = 1;
86         result = prime * result + Objects.hashCode(qname);
87         result = prime * result + Objects.hashCode(path);
88         return result;
89     }
90
91     @Override
92     public boolean equals(final Object obj) {
93         if (this == obj) {
94             return true;
95         }
96         if (obj == null) {
97             return false;
98         }
99         if (getClass() != obj.getClass()) {
100             return false;
101         }
102         final NotificationEffectiveStatementImpl other = (NotificationEffectiveStatementImpl) obj;
103         return Objects.equals(qname, other.qname) && Objects.equals(path, other.path);
104     }
105
106     @Override
107     public String toString() {
108         return NotificationEffectiveStatementImpl.class.getSimpleName() + "[qname=" + qname + ", path=" + path + "]";
109     }
110 }