Use Objects.equals() in effective statements
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / type / BitEffectiveStatementImpl.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.type;
9
10 import com.google.common.collect.ImmutableList;
11 import java.util.ArrayList;
12 import java.util.List;
13 import java.util.Objects;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
16 import org.opendaylight.yangtools.yang.model.api.Status;
17 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.BitStatement;
20 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
22 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
23 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.DescriptionEffectiveStatementImpl;
24 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveStatementBase;
25 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.PositionEffectiveStatementImpl;
26 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.ReferenceEffectiveStatementImpl;
27 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.StatusEffectiveStatementImpl;
28
29 public class BitEffectiveStatementImpl extends EffectiveStatementBase<QName, BitStatement> implements
30         BitsTypeDefinition.Bit {
31
32     private final QName qName;
33     private final SchemaPath schemaPath;
34     private Long position;
35     private String description;
36     private String reference;
37     private Status status;
38     private final List<UnknownSchemaNode> unknownSchemaNodes;
39
40     public BitEffectiveStatementImpl(final StmtContext<QName, BitStatement, ?> ctx) {
41         super(ctx);
42
43         List<UnknownSchemaNode> unknownSchemaNodesInit = new ArrayList<>();
44
45         qName = ctx.getStatementArgument();
46         schemaPath = Utils.getSchemaPath(ctx);
47
48         for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
49             if (effectiveStatement instanceof DescriptionEffectiveStatementImpl) {
50                 description = ((DescriptionEffectiveStatementImpl) effectiveStatement).argument();
51             }
52             if (effectiveStatement instanceof ReferenceEffectiveStatementImpl) {
53                 reference = ((ReferenceEffectiveStatementImpl) effectiveStatement).argument();
54             }
55             if (effectiveStatement instanceof StatusEffectiveStatementImpl) {
56                 status = ((StatusEffectiveStatementImpl) effectiveStatement).argument();
57             }
58             if (effectiveStatement instanceof PositionEffectiveStatementImpl) {
59                 position = ((PositionEffectiveStatementImpl) effectiveStatement).argument();
60             }
61
62             if (effectiveStatement instanceof UnknownSchemaNode) {
63                 unknownSchemaNodesInit.add((UnknownSchemaNode) effectiveStatement);
64             }
65         }
66
67         unknownSchemaNodes = ImmutableList.copyOf(unknownSchemaNodesInit);
68     }
69
70     @Override
71     public Long getPosition() {
72         return position;
73     }
74
75     @Override
76     public String getName() {
77         return qName.getLocalName();
78     }
79
80     @Override
81     public QName getQName() {
82         return qName;
83     }
84
85     @Override
86     public SchemaPath getPath() {
87         return schemaPath;
88     }
89
90     @Override
91     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
92         return unknownSchemaNodes;
93     }
94
95     @Override
96     public String getDescription() {
97         return description;
98     }
99
100     @Override
101     public String getReference() {
102         return reference;
103     }
104
105     @Override
106     public Status getStatus() {
107         return status;
108     }
109
110     @Override
111     public int hashCode() {
112         final int prime = 31;
113         int result = 1;
114         result = prime * result + qName.hashCode();
115         result = prime * result + schemaPath.hashCode();
116         result = prime * result + Objects.hashCode(position);
117         result = prime * result + Objects.hashCode(unknownSchemaNodes);
118         return result;
119     }
120
121     @Override
122     public boolean equals(final Object obj) {
123         if (this == obj) {
124             return true;
125         }
126         if (obj == null) {
127             return false;
128         }
129         if (getClass() != obj.getClass()) {
130             return false;
131         }
132         BitsTypeDefinition.Bit other = (BitsTypeDefinition.Bit) obj;
133         return Objects.equals(qName, other.getQName()) && Objects.equals(schemaPath, other.getPath());
134     }
135
136     @Override
137     public String toString() {
138         return BitEffectiveStatementImpl.class.getSimpleName() + "[name=" + qName.getLocalName() + ", position="
139                 + position + "]";
140     }
141 }