1effe416762e518fe449eee18410bcacad5744d4
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / case_ / CaseEffectiveStatementImpl.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.case_;
9
10 import java.util.Objects;
11 import java.util.Optional;
12 import org.opendaylight.yangtools.yang.common.QName;
13 import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
14 import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
15 import org.opendaylight.yangtools.yang.model.api.stmt.CaseEffectiveStatement;
16 import org.opendaylight.yangtools.yang.model.api.stmt.CaseStatement;
17 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractEffectiveSimpleDataNodeContainer;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
19
20 final class CaseEffectiveStatementImpl extends AbstractEffectiveSimpleDataNodeContainer<CaseStatement>
21         implements CaseEffectiveStatement, CaseSchemaNode, DerivableSchemaNode {
22
23     private final CaseSchemaNode original;
24     private final boolean configuration;
25
26     CaseEffectiveStatementImpl(final StmtContext<QName, CaseStatement, CaseEffectiveStatement> ctx) {
27         super(ctx);
28         this.original = (CaseSchemaNode) ctx.getOriginalCtx().map(StmtContext::buildEffective).orElse(null);
29
30         if (ctx.isConfiguration()) {
31             configuration = ctx.allSubstatementsStream().anyMatch(StmtContext::isConfiguration);
32         } else {
33             configuration = false;
34         }
35     }
36
37     @Override
38     public Optional<CaseSchemaNode> getOriginal() {
39         return Optional.ofNullable(original);
40     }
41
42     @Override
43     public boolean isConfiguration() {
44         return configuration;
45     }
46
47     @Override
48     public int hashCode() {
49         final int prime = 31;
50         int result = 1;
51         result = prime * result + Objects.hashCode(getQName());
52         result = prime * result + Objects.hashCode(getPath());
53         return result;
54     }
55
56     @Override
57     public boolean equals(final Object obj) {
58         if (this == obj) {
59             return true;
60         }
61         if (obj == null) {
62             return false;
63         }
64         if (getClass() != obj.getClass()) {
65             return false;
66         }
67         CaseEffectiveStatementImpl other = (CaseEffectiveStatementImpl) obj;
68         return Objects.equals(getQName(), other.getQName()) && Objects.equals(getPath(), other.getPath());
69     }
70
71     @Override
72     public String toString() {
73         return CaseEffectiveStatementImpl.class.getSimpleName() + "["
74                 + "qname=" + getQName()
75                 + "]";
76     }
77 }