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.stmt.rfc6020.effective;
10 import com.google.common.collect.ImmutableList;
11 import java.util.ArrayList;
12 import java.util.List;
13 import java.util.Objects;
14 import java.util.Optional;
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.DeviationStatement;
22 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
25 public class DeviationEffectiveStatementImpl
26 extends DeclaredEffectiveStatementBase<SchemaNodeIdentifier, DeviationStatement>
27 implements Deviation, Immutable {
28 private final SchemaPath targetPath;
29 private final String description;
30 private final String reference;
31 private final List<UnknownSchemaNode> unknownSchemaNodes;
32 private final List<DeviateDefinition> deviateDefinitions;
34 public DeviationEffectiveStatementImpl(final StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> ctx) {
36 this.targetPath = ctx.getStatementArgument().asSchemaPath();
38 this.deviateDefinitions = ImmutableList.copyOf(allSubstatementsOfType(DeviateDefinition.class));
40 DescriptionEffectiveStatementImpl descriptionStmt = firstEffective(DescriptionEffectiveStatementImpl.class);
41 this.description = descriptionStmt == null ? null : descriptionStmt.argument();
43 ReferenceEffectiveStatementImpl referenceStmt = firstEffective(ReferenceEffectiveStatementImpl.class);
44 this.reference = referenceStmt == null ? null : referenceStmt.argument();
46 List<UnknownSchemaNode> unknownSchemaNodesInit = new ArrayList<>();
47 for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
48 if (effectiveStatement instanceof UnknownSchemaNode) {
49 unknownSchemaNodesInit.add((UnknownSchemaNode) effectiveStatement);
52 unknownSchemaNodes = ImmutableList.copyOf(unknownSchemaNodesInit);
56 public SchemaPath getTargetPath() {
61 public List<DeviateDefinition> getDeviates() {
62 return deviateDefinitions;
66 public Optional<String> getDescription() {
67 return Optional.ofNullable(description);
71 public Optional<String> getReference() {
72 return Optional.ofNullable(reference);
76 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
77 return unknownSchemaNodes;
81 public int hashCode() {
84 result = prime * result + Objects.hashCode(targetPath);
85 result = prime * result + Objects.hashCode(deviateDefinitions);
86 result = prime * result + Objects.hashCode(description);
87 result = prime * result + Objects.hashCode(reference);
92 public boolean equals(final Object obj) {
99 if (getClass() != obj.getClass()) {
102 DeviationEffectiveStatementImpl other = (DeviationEffectiveStatementImpl) obj;
103 if (!Objects.equals(targetPath, other.targetPath)) {
106 if (!Objects.equals(deviateDefinitions, other.deviateDefinitions)) {
109 if (!Objects.equals(description, other.description)) {
112 if (!Objects.equals(reference, other.reference)) {
119 public String toString() {
120 return DeviationEffectiveStatementImpl.class.getSimpleName() + "["
121 + "targetPath=" + targetPath
122 + ", deviates=" + deviateDefinitions
123 + ", description=" + description
124 + ", reference=" + reference