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