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