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