099c89adb51e9f4b6ce20929d2afd3c58352d04e
[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.SubmoduleStatement;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
18 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
19
20 public final class SubmoduleEffectiveStatementImpl extends AbstractEffectiveModule<SubmoduleStatement> {
21
22     private final QNameModule qnameModule;
23
24     public SubmoduleEffectiveStatementImpl(
25             final StmtContext<String, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>> ctx) {
26         super(ctx);
27
28         final String belongsToModuleName = firstAttributeOf(ctx.declaredSubstatements(), BelongsToStatement.class);
29         final QNameModule belongsToModuleQName = ctx.getFromNamespace(ModuleNameToModuleQName.class,
30                 belongsToModuleName);
31         final RevisionEffectiveStatementImpl submoduleRevision = firstEffective(RevisionEffectiveStatementImpl.class);
32         this.qnameModule = QNameModule.create(belongsToModuleQName.getNamespace(),
33             submoduleRevision == null ? null : submoduleRevision.argument()).intern();
34     }
35
36     @Override
37     public QNameModule getQNameModule() {
38         return qnameModule;
39     }
40
41     @Override
42     public int hashCode() {
43         final int prime = 31;
44         int result = 1;
45         result = prime * result + Objects.hashCode(getName());
46         result = prime * result + Objects.hashCode(getYangVersion());
47         result = prime * result + Objects.hashCode(qnameModule);
48         return result;
49     }
50
51     @Override
52     public boolean equals(final Object obj) {
53         if (this == obj) {
54             return true;
55         }
56         if (obj == null) {
57             return false;
58         }
59         if (getClass() != obj.getClass()) {
60             return false;
61         }
62         SubmoduleEffectiveStatementImpl other = (SubmoduleEffectiveStatementImpl) obj;
63         if (!Objects.equals(getName(), other.getName())) {
64             return false;
65         }
66         if (!qnameModule.equals(other.qnameModule)) {
67             return false;
68         }
69         if (!Objects.equals(getYangVersion(), other.getYangVersion())) {
70             return false;
71         }
72         return true;
73     }
74
75 }