YANGTOOLS-706: Split up base utility classes into rfc6020.util
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / SubmoduleEffectiveStatementImpl.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 static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.firstAttributeOf;
11
12 import java.util.Objects;
13 import org.opendaylight.yangtools.yang.common.QNameModule;
14 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
15 import org.opendaylight.yangtools.yang.model.api.stmt.BelongsToStatement;
16 import org.opendaylight.yangtools.yang.model.api.stmt.RevisionEffectiveStatement;
17 import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleEffectiveStatement;
18 import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
20 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
21
22 public final class SubmoduleEffectiveStatementImpl extends AbstractEffectiveModule<SubmoduleStatement>
23         implements SubmoduleEffectiveStatement {
24
25     private final QNameModule qnameModule;
26
27     public SubmoduleEffectiveStatementImpl(
28             final StmtContext<String, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>> ctx) {
29         super(ctx);
30
31         final String belongsToModuleName = firstAttributeOf(ctx.declaredSubstatements(), BelongsToStatement.class);
32         final QNameModule belongsToModuleQName = ctx.getFromNamespace(ModuleNameToModuleQName.class,
33                 belongsToModuleName);
34         final RevisionEffectiveStatement submoduleRevision = firstEffective(RevisionEffectiveStatement.class);
35         this.qnameModule = QNameModule.create(belongsToModuleQName.getNamespace(),
36             submoduleRevision == null ? null : submoduleRevision.argument()).intern();
37     }
38
39     @Override
40     public QNameModule getQNameModule() {
41         return qnameModule;
42     }
43
44     @Override
45     public int hashCode() {
46         final int prime = 31;
47         int result = 1;
48         result = prime * result + Objects.hashCode(getName());
49         result = prime * result + Objects.hashCode(getYangVersion());
50         result = prime * result + Objects.hashCode(qnameModule);
51         return result;
52     }
53
54     @Override
55     public boolean equals(final Object obj) {
56         if (this == obj) {
57             return true;
58         }
59         if (obj == null) {
60             return false;
61         }
62         if (getClass() != obj.getClass()) {
63             return false;
64         }
65         SubmoduleEffectiveStatementImpl other = (SubmoduleEffectiveStatementImpl) obj;
66         if (!Objects.equals(getName(), other.getName())) {
67             return false;
68         }
69         if (!qnameModule.equals(other.qnameModule)) {
70             return false;
71         }
72         if (!Objects.equals(getYangVersion(), other.getYangVersion())) {
73             return false;
74         }
75         return true;
76     }
77
78 }