BUG-6757: revert fix for BUG-4456
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / ModuleEffectiveStatementImpl.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 java.util.Objects;
11 import org.opendaylight.yangtools.yang.common.QNameModule;
12 import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
13 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
14 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
15 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
16 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
17
18 public final class ModuleEffectiveStatementImpl extends AbstractEffectiveModule<ModuleStatement> {
19     private final QNameModule qNameModule;
20
21     public ModuleEffectiveStatementImpl(
22             final StmtContext<String, ModuleStatement, EffectiveStatement<String, ModuleStatement>> ctx) {
23         super(ctx);
24
25         final QNameModule module = ctx.getFromNamespace(ModuleCtxToModuleQName.class, ctx);
26         if (module.getRevision() == null) {
27             qNameModule = QNameModule.create(module.getNamespace(), SimpleDateFormatUtil.DEFAULT_DATE_REV).intern();
28         } else {
29             qNameModule = module;
30         }
31     }
32
33     @Override
34     public QNameModule getQNameModule() {
35         return qNameModule;
36     }
37
38     @Override
39     public int hashCode() {
40         final int prime = 31;
41         int result = 1;
42         result = prime * result + Objects.hashCode(getName());
43         result = prime * result + Objects.hashCode(getYangVersion());
44         result = prime * result + Objects.hashCode(qNameModule);
45         return result;
46     }
47
48     @Override
49     public boolean equals(final Object obj) {
50         if (this == obj) {
51             return true;
52         }
53         if (!(obj instanceof ModuleEffectiveStatementImpl)) {
54             return false;
55         }
56         ModuleEffectiveStatementImpl other = (ModuleEffectiveStatementImpl) obj;
57         if (!Objects.equals(getName(), other.getName())) {
58             return false;
59         }
60         if (!qNameModule.equals(other.qNameModule)) {
61             return false;
62         }
63         if (!Objects.equals(getYangVersion(), other.getYangVersion())) {
64             return false;
65         }
66         return true;
67     }
68
69 }