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.deviation;
10 import com.google.common.collect.ImmutableList;
11 import java.util.ArrayList;
12 import java.util.List;
13 import java.util.Objects;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.opendaylight.yangtools.concepts.Immutable;
16 import org.opendaylight.yangtools.yang.model.api.DeviateDefinition;
17 import org.opendaylight.yangtools.yang.model.api.Deviation;
18 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
19 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
21 import org.opendaylight.yangtools.yang.model.api.stmt.DeviationEffectiveStatement;
22 import org.opendaylight.yangtools.yang.model.api.stmt.DeviationStatement;
23 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
24 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractEffectiveDocumentedNodeWithoutStatus;
25 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
27 final class DeviationEffectiveStatementImpl
28 extends AbstractEffectiveDocumentedNodeWithoutStatus<SchemaNodeIdentifier, DeviationStatement>
29 implements Deviation, DeviationEffectiveStatement, Immutable {
30 private final SchemaPath targetPath;
31 private final @NonNull ImmutableList<UnknownSchemaNode> unknownSchemaNodes;
32 private final ImmutableList<DeviateDefinition> deviateDefinitions;
34 DeviationEffectiveStatementImpl(final StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> ctx) {
36 this.targetPath = ctx.getStatementArgument().asSchemaPath();
37 this.deviateDefinitions = ImmutableList.copyOf(allSubstatementsOfType(DeviateDefinition.class));
39 List<UnknownSchemaNode> unknownSchemaNodesInit = new ArrayList<>();
40 for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
41 if (effectiveStatement instanceof UnknownSchemaNode) {
42 unknownSchemaNodesInit.add((UnknownSchemaNode) effectiveStatement);
45 unknownSchemaNodes = ImmutableList.copyOf(unknownSchemaNodesInit);
49 public SchemaPath getTargetPath() {
54 public List<DeviateDefinition> getDeviates() {
55 return deviateDefinitions;
59 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
60 return unknownSchemaNodes;
64 public int hashCode() {
65 return Objects.hash(targetPath, deviateDefinitions, nullableDescription(), nullableReference());
69 public boolean equals(final Object obj) {
73 if (!(obj instanceof DeviationEffectiveStatementImpl)) {
76 final DeviationEffectiveStatementImpl other = (DeviationEffectiveStatementImpl) obj;
77 return Objects.equals(targetPath, other.targetPath)
78 && Objects.equals(deviateDefinitions, other.deviateDefinitions)
79 && Objects.equals(nullableDescription(), other.nullableDescription())
80 && Objects.equals(nullableReference(), other.nullableReference());
84 public String toString() {
85 return DeviationEffectiveStatementImpl.class.getSimpleName() + "["
86 + "targetPath=" + targetPath
87 + ", deviates=" + deviateDefinitions
88 + ", description=" + nullableDescription()
89 + ", reference=" + nullableReference()