BUG-6757: revert fix for BUG-4456
[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 import java.util.Objects;
12 import org.opendaylight.yangtools.yang.common.QNameModule;
13 import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
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         String belongsToModuleName = firstAttributeOf(ctx.declaredSubstatements(), BelongsToStatement.class);
29         final QNameModule belongsToModuleQName = ctx.getFromNamespace(ModuleNameToModuleQName.class,
30                 belongsToModuleName);
31         RevisionEffectiveStatementImpl submoduleRevision = firstEffective(RevisionEffectiveStatementImpl.class);
32
33         this.qNameModule = (submoduleRevision == null ?
34                 QNameModule.create(belongsToModuleQName.getNamespace(), SimpleDateFormatUtil.DEFAULT_DATE_REV) :
35                     QNameModule.create(belongsToModuleQName.getNamespace(), submoduleRevision.argument())).intern();
36     }
37
38     @Override
39     public QNameModule getQNameModule() {
40         return qNameModule;
41     }
42
43     @Override
44     public int hashCode() {
45         final int prime = 31;
46         int result = 1;
47         result = prime * result + Objects.hashCode(getName());
48         result = prime * result + Objects.hashCode(getYangVersion());
49         result = prime * result + Objects.hashCode(qNameModule);
50         return result;
51     }
52
53     @Override
54     public boolean equals(final Object obj) {
55         if (this == obj) {
56             return true;
57         }
58         if (obj == null) {
59             return false;
60         }
61         if (getClass() != obj.getClass()) {
62             return false;
63         }
64         SubmoduleEffectiveStatementImpl other = (SubmoduleEffectiveStatementImpl) obj;
65         if (!Objects.equals(getName(), other.getName())) {
66             return false;
67         }
68         if (!qNameModule.equals(other.qNameModule)) {
69             return false;
70         }
71         if (!Objects.equals(getYangVersion(), other.getYangVersion())) {
72             return false;
73         }
74         return true;
75     }
76
77 }