Sonar issues clean-up
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / OutputEffectiveStatementImpl.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.HashSet;
11 import java.util.LinkedList;
12 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
13
14 import com.google.common.collect.ImmutableList;
15 import com.google.common.collect.ImmutableSet;
16 import java.util.List;
17 import java.util.Set;
18 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
19 import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
20 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
21 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
22 import org.opendaylight.yangtools.yang.common.QName;
23 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
24 import java.util.Collection;
25 import org.opendaylight.yangtools.yang.model.api.stmt.OutputStatement;
26 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
27 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
28
29 public class OutputEffectiveStatementImpl extends
30         AbstractEffectiveDocumentedDataNodeContainer<QName, OutputStatement>
31         implements ContainerSchemaNode {
32
33     private final QName qname;
34     private final SchemaPath path;
35     private final boolean presence;
36
37     boolean augmenting;
38     boolean addedByUses;
39     boolean configuration;
40     ContainerSchemaNode original;
41     ConstraintDefinition constraints;
42
43     private ImmutableSet<AugmentationSchema> augmentations;
44     private ImmutableList<UnknownSchemaNode> unknownNodes;
45
46     public OutputEffectiveStatementImpl(
47             StmtContext<QName, OutputStatement, EffectiveStatement<QName, OutputStatement>> ctx) {
48         super(ctx);
49
50         qname = ctx.getStatementArgument();
51         path = Utils.getSchemaPath(ctx);
52         presence = (firstEffective(PresenceEffectiveStatementImpl.class) == null) ? false
53                 : true;
54         // :TODO init other fields
55
56         initSubstatementCollections();
57     }
58
59     private void initSubstatementCollections() {
60         Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
61
62         List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
63         Set<AugmentationSchema> augmentationsInit = new HashSet<>();
64
65         for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
66             if (effectiveStatement instanceof UnknownSchemaNode) {
67                 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
68                 unknownNodesInit.add(unknownNode);
69             }
70             if (effectiveStatement instanceof AugmentationSchema) {
71                 AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
72                 augmentationsInit.add(augmentationSchema);
73             }
74         }
75
76         this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
77         this.augmentations = ImmutableSet.copyOf(augmentationsInit);
78     }
79
80     @Override
81     public QName getQName() {
82         return qname;
83     }
84
85     @Override
86     public SchemaPath getPath() {
87         return path;
88     }
89
90     @Override
91     public boolean isAugmenting() {
92         return augmenting;
93     }
94
95     @Override
96     public boolean isAddedByUses() {
97         return addedByUses;
98     }
99
100     @Override
101     public boolean isConfiguration() {
102         return configuration;
103     }
104
105     @Override
106     public ConstraintDefinition getConstraints() {
107         return constraints;
108     }
109
110     @Override
111     public Set<AugmentationSchema> getAvailableAugmentations() {
112         return augmentations;
113     }
114
115     @Override
116     public boolean isPresenceContainer() {
117         return presence;
118     }
119
120     @Override
121     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
122         return unknownNodes;
123     }
124
125     @Override
126     public int hashCode() {
127         final int prime = 31;
128         int result = 1;
129         result = prime * result + ((qname == null) ? 0 : qname.hashCode());
130         result = prime * result + ((path == null) ? 0 : path.hashCode());
131         return result;
132     }
133
134     @Override
135     public boolean equals(final Object obj) {
136         if (this == obj) {
137             return true;
138         }
139         if (obj == null) {
140             return false;
141         }
142         if (getClass() != obj.getClass()) {
143             return false;
144         }
145         OutputEffectiveStatementImpl other = (OutputEffectiveStatementImpl) obj;
146         if (qname == null) {
147             if (other.qname != null) {
148                 return false;
149             }
150         } else if (!qname.equals(other.qname)) {
151             return false;
152         }
153         if (path == null) {
154             if (other.path != null) {
155                 return false;
156             }
157         } else if (!path.equals(other.path)) {
158             return false;
159         }
160         return true;
161     }
162
163     @Override
164     public String toString() {
165         return "RPC Output " + qname.getLocalName();
166     }
167
168 }