Sonar issues clean-up
[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 java.util.Collection;
11 import java.util.HashSet;
12 import java.util.LinkedList;
13
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;
21 import java.util.Set;
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;
27
28 public class NotificationEffectiveStatementImpl
29         extends
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;
36
37     public NotificationEffectiveStatementImpl(
38             StmtContext<QName, NotificationStatement, EffectiveStatement<QName, NotificationStatement>> ctx) {
39         super(ctx);
40         this.qname = ctx.getStatementArgument();
41         this.path = Utils.getSchemaPath(ctx);
42
43         initSubstatementCollections();
44     }
45
46     private void initSubstatementCollections() {
47         Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
48
49         List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
50         Set<AugmentationSchema> augmentationsInit = new HashSet<>();
51
52         for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
53             if (effectiveStatement instanceof UnknownSchemaNode) {
54                 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
55                 unknownNodesInit.add(unknownNode);
56             }
57             if (effectiveStatement instanceof AugmentationSchema) {
58                 AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
59                 augmentationsInit.add(augmentationSchema);
60             }
61         }
62
63         this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
64         this.augmentations = ImmutableSet.copyOf(augmentationsInit);
65     }
66
67     @Override
68     public QName getQName() {
69         return qname;
70     }
71
72     @Override
73     public SchemaPath getPath() {
74         return path;
75     }
76
77     @Override
78     public Set<AugmentationSchema> getAvailableAugmentations() {
79         return augmentations;
80     }
81
82     @Override
83     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
84         return unknownNodes;
85     }
86
87     @Override
88     public int hashCode() {
89         final int prime = 31;
90         int result = 1;
91         result = prime * result + ((qname == null) ? 0 : qname.hashCode());
92         result = prime * result + ((path == null) ? 0 : path.hashCode());
93         return result;
94     }
95
96     @Override
97     public boolean equals(final Object obj) {
98         if (this == obj) {
99             return true;
100         }
101         if (obj == null) {
102             return false;
103         }
104         if (getClass() != obj.getClass()) {
105             return false;
106         }
107         final NotificationEffectiveStatementImpl other = (NotificationEffectiveStatementImpl) obj;
108         if (qname == null) {
109             if (other.qname != null) {
110                 return false;
111             }
112         } else if (!qname.equals(other.qname)) {
113             return false;
114         }
115         if (path == null) {
116             if (other.path != null) {
117                 return false;
118             }
119         } else if (!path.equals(other.path)) {
120             return false;
121         }
122         return true;
123     }
124
125     @Override
126     public String toString() {
127         StringBuilder sb = new StringBuilder(
128                 NotificationEffectiveStatementImpl.class.getSimpleName());
129         sb.append("[qname=").append(qname).append(", path=").append(path)
130                 .append("]");
131         return sb.toString();
132     }
133 }