6f06e8ef76689fca389781c999f7846ee3390825
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / notification / NotificationEffectiveStatementImpl.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.notification;
9
10 import com.google.common.collect.ImmutableList;
11 import java.util.Objects;
12 import java.util.Optional;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
16 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
17 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
18 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement;
20 import org.opendaylight.yangtools.yang.model.api.stmt.NotificationStatement;
21 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractDeclaredEffectiveStatement.DefaultWithDataTree.WithSubstatements;
22 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStatementMixins.AugmentationTargetMixin;
23 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStatementMixins.CopyableMixin;
24 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStatementMixins.DataNodeContainerMixin;
25 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStatementMixins.MustConstraintMixin;
26 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStatementMixins.SchemaNodeMixin;
27 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
28
29 final class NotificationEffectiveStatementImpl
30         extends WithSubstatements<QName, NotificationStatement, NotificationEffectiveStatement>
31         implements NotificationDefinition, NotificationEffectiveStatement,
32                    SchemaNodeMixin<QName, NotificationStatement>, DataNodeContainerMixin<QName, NotificationStatement>,
33                    AugmentationTargetMixin<QName, NotificationStatement>, CopyableMixin<QName, NotificationStatement>,
34                    MustConstraintMixin<QName, NotificationStatement> {
35
36     private final @NonNull SchemaPath path;
37     private final int flags;
38
39     NotificationEffectiveStatementImpl(final NotificationStatement declared, final int flags,
40             final StmtContext<QName, NotificationStatement, NotificationEffectiveStatement> ctx,
41             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
42         super(declared, ctx, substatements);
43         this.path = ctx.getSchemaPath().get();
44         this.flags = flags;
45     }
46
47     @Override
48     public @NonNull QName argument() {
49         return getQName();
50     }
51
52     @Override
53     public Optional<DataSchemaNode> findDataChildByName(final QName name) {
54         return findDataSchemaNode(name);
55     }
56
57     @Override
58     public int flags() {
59         return flags;
60     }
61
62     @Override
63     public SchemaPath getPath() {
64         return path;
65     }
66
67     @Override
68     public int hashCode() {
69         final int prime = 31;
70         int result = 1;
71         result = prime * result + Objects.hashCode(getQName());
72         result = prime * result + Objects.hashCode(path);
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 || getClass() != obj.getClass()) {
82             return false;
83         }
84         final NotificationEffectiveStatementImpl other = (NotificationEffectiveStatementImpl) obj;
85         return Objects.equals(getQName(), other.getQName()) && Objects.equals(path, other.path);
86     }
87
88     @Override
89     public String toString() {
90         return NotificationEffectiveStatementImpl.class.getSimpleName() + "[qname=" + getQName() + ", path=" + path
91                 + "]";
92     }
93 }