Bug 5884: Augmenting a choice without a case results in no getter
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / ContainerEffectiveStatementImpl.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.ContainerSchemaNode;
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.ContainerStatement;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
18
19 public final class ContainerEffectiveStatementImpl extends AbstractEffectiveContainerSchemaNode<ContainerStatement>
20         implements
21         DerivableSchemaNode {
22
23     private final ContainerSchemaNode original;
24
25     public ContainerEffectiveStatementImpl(
26             final StmtContext<QName, ContainerStatement, EffectiveStatement<QName, ContainerStatement>> ctx) {
27         super(ctx);
28         this.original = ctx.getOriginalCtx() == null ? null : (ContainerSchemaNode) ctx.getOriginalCtx().buildEffective();
29     }
30
31     @Override
32     public Optional<ContainerSchemaNode> getOriginal() {
33         return Optional.fromNullable(original);
34     }
35
36     @Override
37     public int hashCode() {
38         final int prime = 31;
39         int result = 1;
40         result = prime * result + Objects.hashCode(getQName());
41         result = prime * result + Objects.hashCode(getPath());
42         return result;
43     }
44
45     @Override
46     public boolean equals(final Object obj) {
47         if (this == obj) {
48             return true;
49         }
50         if (obj == null) {
51             return false;
52         }
53         if (getClass() != obj.getClass()) {
54             return false;
55         }
56         ContainerEffectiveStatementImpl other = (ContainerEffectiveStatementImpl) obj;
57         return Objects.equals(getQName(), other.getQName()) && Objects.equals(getPath(), other.getPath());
58     }
59
60     @Override
61     public String toString() {
62         return "container " + getQName().getLocalName();
63     }
64 }