Add AbstractEffectiveDocumentedNodeWithoutStatus
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / deviation / DeviationEffectiveStatementImpl.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.deviation;
9
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;
26
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;
33
34     DeviationEffectiveStatementImpl(final StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> ctx) {
35         super(ctx);
36         this.targetPath = ctx.getStatementArgument().asSchemaPath();
37         this.deviateDefinitions = ImmutableList.copyOf(allSubstatementsOfType(DeviateDefinition.class));
38
39         List<UnknownSchemaNode> unknownSchemaNodesInit = new ArrayList<>();
40         for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
41             if (effectiveStatement instanceof UnknownSchemaNode) {
42                 unknownSchemaNodesInit.add((UnknownSchemaNode) effectiveStatement);
43             }
44         }
45         unknownSchemaNodes = ImmutableList.copyOf(unknownSchemaNodesInit);
46     }
47
48     @Override
49     public SchemaPath getTargetPath() {
50         return targetPath;
51     }
52
53     @Override
54     public List<DeviateDefinition> getDeviates() {
55         return deviateDefinitions;
56     }
57
58     @Override
59     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
60         return unknownSchemaNodes;
61     }
62
63     @Override
64     public int hashCode() {
65         return Objects.hash(targetPath, deviateDefinitions, nullableDescription(), nullableReference());
66     }
67
68     @Override
69     public boolean equals(final Object obj) {
70         if (this == obj) {
71             return true;
72         }
73         if (!(obj instanceof DeviationEffectiveStatementImpl)) {
74             return false;
75         }
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());
81     }
82
83     @Override
84     public String toString() {
85         return DeviationEffectiveStatementImpl.class.getSimpleName() + "["
86                 + "targetPath=" + targetPath
87                 + ", deviates=" + deviateDefinitions
88                 + ", description=" + nullableDescription()
89                 + ", reference=" + nullableReference()
90                 + "]";
91     }
92 }