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