36d2a13726de043aa2227c3f8bdbcdfa4f9c49b3
[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 int hashCode() {
37         final int prime = 31;
38         int result = 1;
39         result = prime * result + Objects.hashCode(getQName());
40         result = prime * result + Objects.hashCode(getPath());
41         return result;
42     }
43
44     @Override
45     public boolean equals(final Object obj) {
46         if (this == obj) {
47             return true;
48         }
49         if (obj == null) {
50             return false;
51         }
52         if (getClass() != obj.getClass()) {
53             return false;
54         }
55         CaseEffectiveStatementImpl other = (CaseEffectiveStatementImpl) obj;
56         return Objects.equals(getQName(), other.getQName()) && Objects.equals(getPath(), other.getPath());
57     }
58
59     @Override
60     public String toString() {
61         StringBuilder sb = new StringBuilder(CaseEffectiveStatementImpl.class.getSimpleName());
62         sb.append("[");
63         sb.append("qname=");
64         sb.append(getQName());
65         sb.append("]");
66         return sb.toString();
67     }
68 }