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