Bug 4412: New yang parser effective statements cleanup
[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.stmt.MustStatement;
14 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
15
16 public class MustEffectiveStatementImpl extends EffectiveStatementBase<RevisionAwareXPath, MustStatement> implements
17         MustDefinition {
18
19     private final RevisionAwareXPath xPath;
20     private final String description;
21     private final String errorAppTag;
22     private final String errorMessage;
23     private final String reference;
24
25     public MustEffectiveStatementImpl(final StmtContext<RevisionAwareXPath, MustStatement, ?> ctx) {
26         super(ctx);
27         this.xPath = ctx.getStatementArgument();
28
29         DescriptionEffectiveStatementImpl descriptionStmt = firstEffective(DescriptionEffectiveStatementImpl.class);
30         this.description = (descriptionStmt == null) ? null : descriptionStmt.argument();
31
32         ErrorAppTagEffectiveStatementImpl errorAppTagStmt = firstEffective(ErrorAppTagEffectiveStatementImpl.class);
33         this.errorAppTag = (errorAppTagStmt == null) ? null : errorAppTagStmt.argument();
34
35         ErrorMessageEffectiveStatementImpl errorMessageStmt = firstEffective(ErrorMessageEffectiveStatementImpl.class);
36         this.errorMessage = (errorMessageStmt == null) ? null : errorMessageStmt.argument();
37
38         ReferenceEffectiveStatementImpl referenceStmt = firstEffective(ReferenceEffectiveStatementImpl.class);
39         this.reference = (referenceStmt == null) ? null : referenceStmt.argument();
40     }
41
42     @Override
43     public RevisionAwareXPath getXpath() {
44         return xPath;
45     }
46
47     @Override
48     public String getDescription() {
49         return description;
50     }
51
52     @Override
53     public String getErrorAppTag() {
54         return errorAppTag;
55     }
56
57     @Override
58     public String getErrorMessage() {
59         return errorMessage;
60     }
61
62     @Override
63     public String getReference() {
64         return reference;
65     }
66
67     @Override
68     public int hashCode() {
69         final int prime = 31;
70         int result = 1;
71         result = prime * result + Objects.hashCode(xPath);
72         result = prime * result + Objects.hashCode(description);
73         result = prime * result + Objects.hashCode(reference);
74         return result;
75     }
76
77     @Override
78     public boolean equals(final Object obj) {
79         if (this == obj) {
80             return true;
81         }
82         if (obj == null) {
83             return false;
84         }
85         if (getClass() != obj.getClass()) {
86             return false;
87         }
88         final MustEffectiveStatementImpl other = (MustEffectiveStatementImpl) obj;
89         if (!Objects.equals(xPath, other.xPath)) {
90             return false;
91         }
92         if (!Objects.equals(description, other.description)) {
93             return false;
94         }
95         if (!Objects.equals(reference, other.reference)) {
96             return false;
97         }
98         return true;
99     }
100
101     @Override
102     public String toString() {
103         return xPath.toString();
104     }
105 }