Bug 6551: Support for third-party Yang extensions implementation
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / thirdparty / plugin / ThirdPartyExtensionEffectiveStatementImpl.java
1 /*
2  * Copyright (c) 2016 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
9 package org.opendaylight.yangtools.yang.thirdparty.plugin;
10
11 import com.google.common.annotations.Beta;
12 import java.util.Objects;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
15 import org.opendaylight.yangtools.yang.model.api.stmt.UnknownStatement;
16 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
17 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.UnknownEffectiveStatementBase;
18
19 @Beta
20 public final class ThirdPartyExtensionEffectiveStatementImpl extends UnknownEffectiveStatementBase<String> {
21
22     private final SchemaPath path;
23     private final String valueFromNamespace;
24
25     public ThirdPartyExtensionEffectiveStatementImpl(final StmtContext<String, UnknownStatement<String>, ?> ctx) {
26         super(ctx);
27         path = ctx.getParentContext().getSchemaPath().get().createChild(getNodeType());
28         valueFromNamespace = ctx.getFromNamespace(ThirdPartyNamespace.class, ctx);
29     }
30
31     public String getValueFromNamespace() {
32         return valueFromNamespace;
33     }
34
35     @Override
36     public QName getQName() {
37         return getNodeType();
38     }
39
40     @Override
41     public SchemaPath getPath() {
42         return path;
43     }
44
45     @Override
46     public int hashCode() {
47         return Objects.hash(path, getNodeType(), getNodeParameter());
48     }
49
50     @Override
51     public boolean equals(final Object obj) {
52         if (this == obj) {
53             return true;
54         }
55         if (obj == null) {
56             return false;
57         }
58         if (getClass() != obj.getClass()) {
59             return false;
60         }
61         final ThirdPartyExtensionEffectiveStatementImpl other = (ThirdPartyExtensionEffectiveStatementImpl) obj;
62         if (!Objects.equals(path, other.path)) {
63             return false;
64         }
65         if (!Objects.equals(getNodeType(), other.getNodeType())) {
66             return false;
67         }
68         if (!Objects.equals(getNodeParameter(), other.getNodeParameter())) {
69             return false;
70         }
71         return true;
72     }
73 }