Add RFC6643 parser support
[yangtools.git] / yang / rfc6643-parser-support / src / main / java / org / opendaylight / yangtools / rfc6643 / parser / DefValEffectiveStatementImpl.java
1 /*
2  * Copyright (c) 2016, 2020 PANTHEON.tech, s.r.o. 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.rfc6643.parser;
9
10 import java.util.Objects;
11 import org.opendaylight.yangtools.rfc6643.model.api.DefValEffectiveStatement;
12 import org.opendaylight.yangtools.rfc6643.model.api.DefValSchemaNode;
13 import org.opendaylight.yangtools.rfc6643.model.api.DefValStatement;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
16 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.UnknownEffectiveStatementBase;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
18
19 final class DefValEffectiveStatementImpl extends UnknownEffectiveStatementBase<String, DefValStatement>
20         implements DefValEffectiveStatement, DefValSchemaNode {
21
22     private final SchemaPath path;
23     private final String valueFromNamespace;
24
25     DefValEffectiveStatementImpl(final StmtContext<String, DefValStatement, ?> ctx) {
26         super(ctx);
27         path = ctx.getParentContext().getSchemaPath().get().createChild(getNodeType());
28         valueFromNamespace = ctx.getFromNamespace(IetfYangSmiv2Namespace.class, ctx);
29     }
30
31     @Override
32     public String getArgument() {
33         return argument();
34     }
35
36     // FIXME: what good is this method?
37     public String getValueFromNamespace() {
38         return valueFromNamespace;
39     }
40
41     @Override
42     public QName getQName() {
43         return getNodeType();
44     }
45
46     @Override
47     public SchemaPath getPath() {
48         return path;
49     }
50
51     @Override
52     public int hashCode() {
53         return Objects.hash(path, getNodeType(), getNodeParameter());
54     }
55
56     @Override
57     public boolean equals(final Object obj) {
58         if (this == obj) {
59             return true;
60         }
61         if (obj == null) {
62             return false;
63         }
64         if (getClass() != obj.getClass()) {
65             return false;
66         }
67         final DefValEffectiveStatementImpl other = (DefValEffectiveStatementImpl) obj;
68         if (!Objects.equals(path, other.path)) {
69             return false;
70         }
71         if (!Objects.equals(getNodeType(), other.getNodeType())) {
72             return false;
73         }
74         if (!Objects.equals(getNodeParameter(), other.getNodeParameter())) {
75             return false;
76         }
77         return true;
78     }
79 }