d5fdbe8d6f0f3140ac45c04ead7a0ebd6ab0b02d
[yangtools.git] / yang / yang-parser-rfc7950 / 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         return Objects.hash(xpath, description, reference);
69     }
70
71     @Override
72     public boolean equals(final Object obj) {
73         if (this == obj) {
74             return true;
75         }
76         if (!(obj instanceof MustEffectiveStatementImpl)) {
77             return false;
78         }
79         final MustEffectiveStatementImpl other = (MustEffectiveStatementImpl) obj;
80         return Objects.equals(xpath, other.xpath) && Objects.equals(description, other.description)
81                 && Objects.equals(reference, other.reference);
82     }
83
84     @Override
85     public String toString() {
86         return xpath.getOriginalString();
87     }
88 }