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.LinkedList;
12 import java.util.List;
13 import java.util.Objects;
14 import org.opendaylight.yangtools.concepts.Immutable;
15 import org.opendaylight.yangtools.yang.model.api.Deviation;
16 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
17 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.DeviationStatement;
20 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
23 public class DeviationEffectiveStatementImpl extends EffectiveStatementBase<SchemaNodeIdentifier, DeviationStatement>
24 implements Deviation, Immutable {
26 private final SchemaPath targetPath;
27 private Deviate deviate;
28 private String reference;
29 private final ImmutableList<UnknownSchemaNode> unknownSchemaNodes;
31 public DeviationEffectiveStatementImpl(final StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> ctx) {
34 List<UnknownSchemaNode> unknownSchemaNodesInit = new LinkedList<>();
36 targetPath = SchemaPath.create(ctx.getStatementArgument().getPathFromRoot(), ctx.getStatementArgument()
39 for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
40 if (effectiveStatement instanceof DeviateEffectiveStatementImpl) {
41 deviate = ((DeviateEffectiveStatementImpl) effectiveStatement).argument();
43 if (effectiveStatement instanceof ReferenceEffectiveStatementImpl) {
44 reference = ((ReferenceEffectiveStatementImpl) effectiveStatement).argument();
46 if (effectiveStatement instanceof UnknownSchemaNode) {
47 unknownSchemaNodesInit.add((UnknownSchemaNode) effectiveStatement);
51 unknownSchemaNodes = ImmutableList.copyOf(unknownSchemaNodesInit);
55 public SchemaPath getTargetPath() {
60 public Deviate getDeviate() {
65 public String getReference() {
70 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
71 return unknownSchemaNodes;
75 public int hashCode() {
78 result = prime * result + Objects.hashCode(targetPath);
79 result = prime * result + Objects.hashCode(deviate);
80 result = prime * result + Objects.hashCode(reference);
85 public boolean equals(final Object obj) {
92 if (getClass() != obj.getClass()) {
95 DeviationEffectiveStatementImpl other = (DeviationEffectiveStatementImpl) obj;
96 if (!Objects.equals(targetPath, other.targetPath)) {
99 if (!Objects.equals(deviate, other.deviate)) {
102 if (!Objects.equals(reference, other.reference)) {
109 public String toString() {
110 StringBuilder sb = new StringBuilder(DeviationEffectiveStatementImpl.class.getSimpleName());
112 sb.append("targetPath=").append(targetPath);
113 sb.append(", deviate=").append(deviate);
114 sb.append(", reference=").append(reference);
116 return sb.toString();