Refactor deviation statement implementations
[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.List;
12 import java.util.Objects;
13 import org.opendaylight.yangtools.yang.model.api.DeviateDefinition;
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.meta.EffectiveStatement;
17 import org.opendaylight.yangtools.yang.model.api.stmt.DeviationEffectiveStatement;
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.rfc7950.stmt.AbstractDeclaredEffectiveStatement.DefaultArgument.WithSubstatements;
21 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStatementMixins.DocumentedNodeMixin;
22
23 final class DeviationEffectiveStatementImpl extends WithSubstatements<SchemaNodeIdentifier, DeviationStatement>
24         implements DeviationEffectiveStatement, Deviation,
25             DocumentedNodeMixin<SchemaNodeIdentifier, DeviationStatement> {
26     DeviationEffectiveStatementImpl(final DeviationStatement declared,
27             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
28         super(declared, substatements);
29     }
30
31     @Override
32     public SchemaPath getTargetPath() {
33         return argument().asSchemaPath();
34     }
35
36     @Override
37     public List<DeviateDefinition> getDeviates() {
38         return filterEffectiveStatementsList(DeviateDefinition.class);
39     }
40
41     @Override
42     public int hashCode() {
43         return Objects.hash(getTargetPath(), getDeviates(), getDescription().orElse(null), getReference().orElse(null));
44     }
45
46     @Override
47     public boolean equals(final Object obj) {
48         if (this == obj) {
49             return true;
50         }
51         if (!(obj instanceof DeviationEffectiveStatementImpl)) {
52             return false;
53         }
54         final DeviationEffectiveStatementImpl other = (DeviationEffectiveStatementImpl) obj;
55         return Objects.equals(getTargetPath(), other.getTargetPath())
56                 && Objects.equals(getDeviates(), other.getDeviates())
57                 && Objects.equals(getDescription(),  other.getDescription())
58                 && Objects.equals(getReference(), other.getReference());
59     }
60
61     @Override
62     public String toString() {
63         return DeviationEffectiveStatementImpl.class.getSimpleName() + "["
64                 + "targetPath=" + getTargetPath()
65                 + ", deviates=" + getDeviates()
66                 + ", description=" + getDescription().orElse(null)
67                 + ", reference=" + getReference().orElse(null)
68                 + "]";
69     }
70 }