Cleanup DocumentedNode
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / 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.stmt.rfc6020.effective;
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 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;
24
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;
33
34     public DeviationEffectiveStatementImpl(final StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> ctx) {
35         super(ctx);
36         this.targetPath = ctx.getStatementArgument().asSchemaPath();
37
38         this.deviateDefinitions = ImmutableList.copyOf(allSubstatementsOfType(DeviateDefinition.class));
39
40         DescriptionEffectiveStatementImpl descriptionStmt = firstEffective(DescriptionEffectiveStatementImpl.class);
41         this.description = descriptionStmt == null ? null : descriptionStmt.argument();
42
43         ReferenceEffectiveStatementImpl referenceStmt = firstEffective(ReferenceEffectiveStatementImpl.class);
44         this.reference = referenceStmt == null ? null : referenceStmt.argument();
45
46         List<UnknownSchemaNode> unknownSchemaNodesInit = new ArrayList<>();
47         for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
48             if (effectiveStatement instanceof UnknownSchemaNode) {
49                 unknownSchemaNodesInit.add((UnknownSchemaNode) effectiveStatement);
50             }
51         }
52         unknownSchemaNodes = ImmutableList.copyOf(unknownSchemaNodesInit);
53     }
54
55     @Override
56     public SchemaPath getTargetPath() {
57         return targetPath;
58     }
59
60     @Override
61     public List<DeviateDefinition> getDeviates() {
62         return deviateDefinitions;
63     }
64
65     @Override
66     public Optional<String> getDescription() {
67         return Optional.ofNullable(description);
68     }
69
70     @Override
71     public Optional<String> getReference() {
72         return Optional.ofNullable(reference);
73     }
74
75     @Override
76     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
77         return unknownSchemaNodes;
78     }
79
80     @Override
81     public int hashCode() {
82         final int prime = 31;
83         int result = 1;
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);
88         return result;
89     }
90
91     @Override
92     public boolean equals(final Object obj) {
93         if (this == obj) {
94             return true;
95         }
96         if (obj == null) {
97             return false;
98         }
99         if (getClass() != obj.getClass()) {
100             return false;
101         }
102         DeviationEffectiveStatementImpl other = (DeviationEffectiveStatementImpl) obj;
103         if (!Objects.equals(targetPath, other.targetPath)) {
104             return false;
105         }
106         if (!Objects.equals(deviateDefinitions, other.deviateDefinitions)) {
107             return false;
108         }
109         if (!Objects.equals(description, other.description)) {
110             return false;
111         }
112         if (!Objects.equals(reference, other.reference)) {
113             return false;
114         }
115         return true;
116     }
117
118     @Override
119     public String toString() {
120         return DeviationEffectiveStatementImpl.class.getSimpleName() + "["
121                 + "targetPath=" + targetPath
122                 + ", deviates=" + deviateDefinitions
123                 + ", description=" + description
124                 + ", reference=" + reference
125                 + "]";
126     }
127 }