Propagate @Nonnull and @Nullable annotations
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / GroupingEffectiveStatementImpl.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
9 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
10
11 import com.google.common.collect.ImmutableList;
12 import com.google.common.collect.ImmutableList.Builder;
13 import java.util.List;
14 import java.util.Objects;
15 import javax.annotation.Nonnull;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
18 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
19 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
21 import org.opendaylight.yangtools.yang.model.api.stmt.GroupingStatement;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.CopyType;
24
25 public class GroupingEffectiveStatementImpl extends
26         AbstractEffectiveDocumentedDataNodeContainer<QName, GroupingStatement> implements GroupingDefinition {
27     private final QName qname;
28     private final SchemaPath path;
29     private final boolean addedByUses;
30     private final List<UnknownSchemaNode> unknownNodes;
31
32     public GroupingEffectiveStatementImpl(
33             final StmtContext<QName, GroupingStatement, EffectiveStatement<QName, GroupingStatement>> ctx) {
34         super(ctx);
35
36         qname = ctx.getStatementArgument();
37         path = ctx.getSchemaPath().get();
38
39         addedByUses = ctx.getCopyHistory().contains(CopyType.ADDED_BY_USES);
40
41         final Builder<UnknownSchemaNode> b = ImmutableList.builder();
42         for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
43             if (effectiveStatement instanceof UnknownSchemaNode) {
44                 b.add((UnknownSchemaNode) effectiveStatement);
45             }
46         }
47
48         unknownNodes = b.build();
49     }
50
51     @Nonnull
52     @Override
53     public QName getQName() {
54         return qname;
55     }
56
57     @Nonnull
58     @Override
59     public SchemaPath getPath() {
60         return path;
61     }
62
63     @Override
64     public boolean isAddedByUses() {
65         return addedByUses;
66     }
67
68     @Nonnull
69     @Override
70     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
71         return unknownNodes;
72     }
73
74     @Override
75     public int hashCode() {
76         final int prime = 31;
77         int result = 1;
78         result = prime * result + Objects.hashCode(qname);
79         result = prime * result + Objects.hashCode(path);
80         return result;
81     }
82
83     @Override
84     public boolean equals(final Object obj) {
85         if (this == obj) {
86             return true;
87         }
88         if (obj == null) {
89             return false;
90         }
91         if (getClass() != obj.getClass()) {
92             return false;
93         }
94         final GroupingEffectiveStatementImpl other = (GroupingEffectiveStatementImpl) obj;
95         return Objects.equals(qname, other.qname) && Objects.equals(path, other.path);
96     }
97
98     @Override
99     public String toString() {
100         return GroupingEffectiveStatementImpl.class.getSimpleName() + "[" +
101                 "qname=" + qname +
102                 "]";
103     }
104 }