Bug 2366 - Effective statments impl merge, retest & bugfix
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / MustEffectiveStatementImpl.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.model.api.MustDefinition;
11 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
12 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
13 import org.opendaylight.yangtools.yang.model.api.stmt.MustStatement;
14 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
15
16 public class MustEffectiveStatementImpl extends
17         EffectiveStatementBase<RevisionAwareXPath, MustStatement> implements
18         MustDefinition {
19
20     private RevisionAwareXPath xPath;
21     private String description;
22     private String errorAppTag;
23     private String errorMessage;
24     private String reference;
25
26     public MustEffectiveStatementImpl(
27             StmtContext<RevisionAwareXPath, MustStatement, ?> ctx) {
28         super(ctx);
29
30         initFields();
31
32         xPath = ctx.getStatementArgument();
33     }
34
35     private void initFields() {
36
37         for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
38
39             if (effectiveStatement instanceof DescriptionEffectiveStatementImpl) {
40                 description = ((DescriptionEffectiveStatementImpl) effectiveStatement)
41                         .argument();
42             }
43             if (effectiveStatement instanceof ErrorAppTagEffectiveStatementImpl) {
44                 errorAppTag = ((ErrorAppTagEffectiveStatementImpl) effectiveStatement)
45                         .argument();
46             }
47             if (effectiveStatement instanceof ErrorMessageEffectiveStatementImpl) {
48                 errorMessage = ((ErrorMessageEffectiveStatementImpl) effectiveStatement)
49                         .argument();
50             }
51             if (effectiveStatement instanceof ReferenceEffectiveStatementImpl) {
52                 reference = ((ReferenceEffectiveStatementImpl) effectiveStatement)
53                         .argument();
54             }
55         }
56     }
57
58     @Override
59     public RevisionAwareXPath getXpath() {
60         return xPath;
61     }
62
63     @Override
64     public String getDescription() {
65         return description;
66     }
67
68     @Override
69     public String getErrorAppTag() {
70         return errorAppTag;
71     }
72
73     @Override
74     public String getErrorMessage() {
75         return errorMessage;
76     }
77
78     @Override
79     public String getReference() {
80         return reference;
81     }
82
83     @Override
84     public int hashCode() {
85         final int prime = 31;
86         int result = 1;
87         result = prime * result + ((xPath == null) ? 0 : xPath.hashCode());
88         result = prime * result
89                 + ((description == null) ? 0 : description.hashCode());
90         result = prime * result
91                 + ((reference == null) ? 0 : reference.hashCode());
92         return result;
93     }
94
95     @Override
96     public boolean equals(final Object obj) {
97         if (this == obj) {
98             return true;
99         }
100         if (obj == null) {
101             return false;
102         }
103         if (getClass() != obj.getClass()) {
104             return false;
105         }
106         final MustEffectiveStatementImpl other = (MustEffectiveStatementImpl) obj;
107         if (xPath == null) {
108             if (other.xPath != null) {
109                 return false;
110             }
111         } else if (!xPath.equals(other.xPath)) {
112             return false;
113         }
114         if (description == null) {
115             if (other.description != null) {
116                 return false;
117             }
118         } else if (!description.equals(other.description)) {
119             return false;
120         }
121         if (reference == null) {
122             if (other.reference != null) {
123                 return false;
124             }
125         } else if (!reference.equals(other.reference)) {
126             return false;
127         }
128         return true;
129     }
130
131     @Override
132     public String toString() {
133         return xPath.toString();
134     }
135 }