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