Adjust test suite parser update to conform with API changes
[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         xpath = ctx.getStatementArgument();
35         description = findFirstEffectiveSubstatementArgument(DescriptionEffectiveStatement.class).orElse(null);
36         errorAppTag = findFirstEffectiveSubstatementArgument(ErrorAppTagEffectiveStatement.class).orElse(null);
37         errorMessage = findFirstEffectiveSubstatementArgument(ErrorMessageEffectiveStatement.class).orElse(null);
38         reference = findFirstEffectiveSubstatementArgument(ReferenceEffectiveStatement.class).orElse(null);
39     }
40
41     @Override
42     public RevisionAwareXPath getXpath() {
43         return xpath;
44     }
45
46     @Override
47     public Optional<String> getDescription() {
48         return Optional.ofNullable(description);
49     }
50
51     @Override
52     public Optional<String> getErrorAppTag() {
53         return Optional.ofNullable(errorAppTag);
54     }
55
56     @Override
57     public Optional<String> getErrorMessage() {
58         return Optional.ofNullable(errorMessage);
59     }
60
61     @Override
62     public Optional<String> getReference() {
63         return Optional.ofNullable(reference);
64     }
65
66     @Override
67     public int hashCode() {
68         final int prime = 31;
69         int result = 1;
70         result = prime * result + Objects.hashCode(xpath);
71         result = prime * result + Objects.hashCode(description);
72         result = prime * result + Objects.hashCode(reference);
73         return result;
74     }
75
76     @Override
77     public boolean equals(final Object obj) {
78         if (this == obj) {
79             return true;
80         }
81         if (obj == null) {
82             return false;
83         }
84         if (getClass() != obj.getClass()) {
85             return false;
86         }
87         final MustEffectiveStatementImpl other = (MustEffectiveStatementImpl) obj;
88         if (!Objects.equals(xpath, other.xpath)) {
89             return false;
90         }
91         if (!Objects.equals(description, other.description)) {
92             return false;
93         }
94         if (!Objects.equals(reference, other.reference)) {
95             return false;
96         }
97         return true;
98     }
99
100     @Override
101     public String toString() {
102         return xpath.toString();
103     }
104 }