Use Objects.hashCode()
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / ImportEffectiveStatementImpl.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 org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
11
12 import java.util.Date;
13 import java.util.Objects;
14 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
15 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
16 import org.opendaylight.yangtools.yang.model.api.stmt.ImportStatement;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
18
19 public class ImportEffectiveStatementImpl extends EffectiveStatementBase<String, ImportStatement> implements
20         ModuleImport {
21
22     private String moduleName;
23     private Date revision;
24     private String prefix;
25
26     public ImportEffectiveStatementImpl(StmtContext<String, ImportStatement, ?> ctx) {
27         super(ctx);
28
29         moduleName = ctx.getStatementArgument();
30         revision = SimpleDateFormatUtil.DEFAULT_DATE_IMP;
31
32         for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
33             if (effectiveStatement instanceof RevisionDateEffectiveStatementImpl) {
34                 revision = ((RevisionDateEffectiveStatementImpl) effectiveStatement).argument();
35             }
36             if (effectiveStatement instanceof PrefixEffectiveStatementImpl) {
37                 prefix = ((PrefixEffectiveStatementImpl) effectiveStatement).argument();
38             }
39         }
40     }
41
42     @Override
43     public String getModuleName() {
44         return moduleName;
45     }
46
47     @Override
48     public Date getRevision() {
49         return revision;
50     }
51
52     @Override
53     public String getPrefix() {
54         return prefix;
55     }
56
57     @Override
58     public int hashCode() {
59         final int prime = 31;
60         int result = 1;
61         result = prime * result + Objects.hashCode(moduleName);
62         result = prime * result + Objects.hashCode(revision);
63         result = prime * result + Objects.hashCode(prefix);
64         return result;
65     }
66
67     @Override
68     public boolean equals(Object obj) {
69         if (this == obj) {
70             return true;
71         }
72         if (obj == null) {
73             return false;
74         }
75         if (getClass() != obj.getClass()) {
76             return false;
77         }
78         ImportEffectiveStatementImpl other = (ImportEffectiveStatementImpl) obj;
79         if (getModuleName() == null) {
80             if (other.getModuleName() != null) {
81                 return false;
82             }
83         } else if (!getModuleName().equals(other.getModuleName())) {
84             return false;
85         }
86         if (getRevision() == null) {
87             if (other.getRevision() != null) {
88                 return false;
89             }
90         } else if (!getRevision().equals(other.getRevision())) {
91             return false;
92         }
93         if (getPrefix() == null) {
94             if (other.getPrefix() != null) {
95                 return false;
96             }
97         } else if (!getPrefix().equals(other.getPrefix())) {
98             return false;
99         }
100         return true;
101     }
102
103     @Override
104     public String toString() {
105         return ImportEffectiveStatementImpl.class.getSimpleName() + "[moduleName=" + moduleName + ", revision="
106                 + revision + ", prefix=" + prefix + "]";
107     }
108 }