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