67e46139c857b7ecda7fe63f6895ddbfaf626dcd
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / 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.stmt.rfc6020.effective;
9
10 import com.google.common.collect.ImmutableList;
11 import com.google.common.collect.ImmutableSet;
12 import java.util.Collection;
13 import java.util.HashSet;
14 import java.util.LinkedList;
15 import java.util.List;
16 import java.util.Objects;
17 import java.util.Set;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
20 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
21 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
22 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
24 import org.opendaylight.yangtools.yang.model.api.stmt.NotificationStatement;
25 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
26
27 public class NotificationEffectiveStatementImpl extends
28         AbstractEffectiveDocumentedDataNodeContainer<QName, NotificationStatement> implements NotificationDefinition {
29     private final QName qname;
30     private final SchemaPath path;
31     private final Set<AugmentationSchema> augmentations;
32     private final List<UnknownSchemaNode> unknownNodes;
33
34     public NotificationEffectiveStatementImpl(
35             final StmtContext<QName, NotificationStatement, EffectiveStatement<QName, NotificationStatement>> ctx) {
36         super(ctx);
37         this.qname = ctx.getStatementArgument();
38         this.path = ctx.getSchemaPath().get();
39
40         // initSubstatementCollections
41         Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
42         List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
43         Set<AugmentationSchema> augmentationsInit = new HashSet<>();
44         for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
45             if (effectiveStatement instanceof UnknownSchemaNode) {
46                 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
47                 unknownNodesInit.add(unknownNode);
48             }
49             if (effectiveStatement instanceof AugmentationSchema) {
50                 AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
51                 augmentationsInit.add(augmentationSchema);
52             }
53         }
54         this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
55         this.augmentations = ImmutableSet.copyOf(augmentationsInit);
56     }
57
58     @Override
59     public QName getQName() {
60         return qname;
61     }
62
63     @Override
64     public SchemaPath getPath() {
65         return path;
66     }
67
68     @Override
69     public Set<AugmentationSchema> getAvailableAugmentations() {
70         return augmentations;
71     }
72
73     @Override
74     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
75         return unknownNodes;
76     }
77
78     @Override
79     public int hashCode() {
80         final int prime = 31;
81         int result = 1;
82         result = prime * result + Objects.hashCode(qname);
83         result = prime * result + Objects.hashCode(path);
84         return result;
85     }
86
87     @Override
88     public boolean equals(final Object obj) {
89         if (this == obj) {
90             return true;
91         }
92         if (obj == null) {
93             return false;
94         }
95         if (getClass() != obj.getClass()) {
96             return false;
97         }
98         final NotificationEffectiveStatementImpl other = (NotificationEffectiveStatementImpl) obj;
99         return Objects.equals(qname, other.qname) && Objects.equals(path, other.path);
100     }
101
102     @Override
103     public String toString() {
104         StringBuilder sb = new StringBuilder(NotificationEffectiveStatementImpl.class.getSimpleName());
105         sb.append("[qname=").append(qname).append(", path=").append(path).append("]");
106         return sb.toString();
107     }
108 }