2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.notification;
10 import com.google.common.collect.ImmutableSet;
11 import java.lang.invoke.MethodHandles;
12 import java.lang.invoke.VarHandle;
13 import java.util.Collection;
14 import java.util.LinkedHashSet;
15 import java.util.Objects;
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.MustDefinition;
21 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
22 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
23 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
24 import org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement;
25 import org.opendaylight.yangtools.yang.model.api.stmt.NotificationStatement;
26 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractEffectiveDocumentedDataNodeContainer;
27 import org.opendaylight.yangtools.yang.parser.spi.meta.CopyHistory;
28 import org.opendaylight.yangtools.yang.parser.spi.meta.CopyType;
29 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
31 final class NotificationEffectiveStatementImpl
32 extends AbstractEffectiveDocumentedDataNodeContainer<QName, NotificationStatement>
33 implements NotificationDefinition, NotificationEffectiveStatement {
34 private static final VarHandle MUST_CONSTRAINTS;
38 MUST_CONSTRAINTS = MethodHandles.lookup().findVarHandle(
39 NotificationEffectiveStatementImpl.class, "mustConstraints", ImmutableSet.class);
40 } catch (NoSuchFieldException | IllegalAccessException e) {
41 throw new ExceptionInInitializerError(e);
45 private final @NonNull QName qname;
46 private final @NonNull SchemaPath path;
47 private final ImmutableSet<AugmentationSchemaNode> augmentations;
48 private final boolean augmenting;
49 private final boolean addedByUses;
51 @SuppressWarnings("unused")
52 private volatile ImmutableSet<MustDefinition> mustConstraints;
54 NotificationEffectiveStatementImpl(
55 final StmtContext<QName, NotificationStatement, NotificationEffectiveStatement> ctx) {
57 this.qname = ctx.coerceStatementArgument();
58 this.path = ctx.getSchemaPath().get();
60 // initSubstatementCollections
61 final Set<AugmentationSchemaNode> augmentationsInit = new LinkedHashSet<>();
62 for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
63 if (effectiveStatement instanceof AugmentationSchemaNode) {
64 final AugmentationSchemaNode augmentationSchema = (AugmentationSchemaNode) effectiveStatement;
65 augmentationsInit.add(augmentationSchema);
68 this.augmentations = ImmutableSet.copyOf(augmentationsInit);
71 final CopyHistory copyTypesFromOriginal = ctx.getCopyHistory();
72 if (copyTypesFromOriginal.contains(CopyType.ADDED_BY_USES_AUGMENTATION)) {
73 this.augmenting = true;
74 this.addedByUses = true;
76 this.augmenting = copyTypesFromOriginal.contains(CopyType.ADDED_BY_AUGMENTATION);
77 this.addedByUses = copyTypesFromOriginal.contains(CopyType.ADDED_BY_USES);
82 public QName getQName() {
87 public SchemaPath getPath() {
92 public Collection<? extends MustDefinition> getMustConstraints() {
93 return derivedSet(MUST_CONSTRAINTS, MustDefinition.class);
97 public Collection<? extends AugmentationSchemaNode> getAvailableAugmentations() {
103 public boolean isAugmenting() {
109 public boolean isAddedByUses() {
114 public int hashCode() {
115 final int prime = 31;
117 result = prime * result + Objects.hashCode(qname);
118 result = prime * result + Objects.hashCode(path);
123 public boolean equals(final Object obj) {
130 if (getClass() != obj.getClass()) {
133 final NotificationEffectiveStatementImpl other = (NotificationEffectiveStatementImpl) obj;
134 return Objects.equals(qname, other.qname) && Objects.equals(path, other.path);
138 public String toString() {
139 return NotificationEffectiveStatementImpl.class.getSimpleName() + "[qname=" + qname + ", path=" + path + "]";