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 java.util.LinkedList;
11 import java.util.List;
13 import org.opendaylight.yangtools.concepts.Immutable;
14 import org.opendaylight.yangtools.yang.model.api.Deviation;
15 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
16 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
17 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
18 import org.opendaylight.yangtools.yang.model.api.stmt.DeviationStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
22 import com.google.common.collect.ImmutableList;
24 public class DeviationEffectiveStatementImpl extends EffectiveStatementBase<SchemaNodeIdentifier, DeviationStatement>
25 implements Deviation, Immutable {
27 private SchemaPath targetPath;
28 private Deviate deviate;
29 private String reference;
30 private ImmutableList<UnknownSchemaNode> unknownSchemaNodes;
32 public DeviationEffectiveStatementImpl(StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> ctx) {
35 List<UnknownSchemaNode> unknownSchemaNodesInit = new LinkedList<>();
37 targetPath = SchemaPath.create(ctx.getStatementArgument().getPathFromRoot(), ctx.getStatementArgument()
40 for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
41 if (effectiveStatement instanceof DeviateEffectiveStatementImpl) {
42 deviate = ((DeviateEffectiveStatementImpl) effectiveStatement).argument();
44 if (effectiveStatement instanceof ReferenceEffectiveStatementImpl) {
45 reference = ((ReferenceEffectiveStatementImpl) effectiveStatement).argument();
47 if (effectiveStatement instanceof UnknownSchemaNode) {
48 unknownSchemaNodesInit.add((UnknownSchemaNode) effectiveStatement);
52 unknownSchemaNodes = ImmutableList.copyOf(unknownSchemaNodesInit);
56 public SchemaPath getTargetPath() {
61 public Deviate getDeviate() {
66 public String getReference() {
71 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
72 return unknownSchemaNodes;
76 public int hashCode() {
79 result = prime * result + ((targetPath == null) ? 0 : targetPath.hashCode());
80 result = prime * result + ((deviate == null) ? 0 : deviate.hashCode());
81 result = prime * result + ((reference == null) ? 0 : reference.hashCode());
86 public boolean equals(Object obj) {
93 if (getClass() != obj.getClass()) {
96 DeviationEffectiveStatementImpl other = (DeviationEffectiveStatementImpl) obj;
97 if (targetPath == null) {
98 if (other.targetPath != null) {
101 } else if (!targetPath.equals(other.targetPath)) {
104 if (deviate == null) {
105 if (other.deviate != null) {
108 } else if (!deviate.equals(other.deviate)) {
111 if (reference == null) {
112 if (other.reference != null) {
115 } else if (!reference.equals(other.reference)) {
122 public String toString() {
123 StringBuilder sb = new StringBuilder(DeviationEffectiveStatementImpl.class.getSimpleName());
125 sb.append("targetPath=").append(targetPath);
126 sb.append(", deviate=").append(deviate);
127 sb.append(", reference=").append(reference);
129 return sb.toString();