2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
10 import com.google.common.base.Optional;
11 import java.util.Collection;
12 import java.util.Objects;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
15 import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
16 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
17 import org.opendaylight.yangtools.yang.model.api.stmt.CaseStatement;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
19 import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
21 public final class CaseEffectiveStatementImpl extends AbstractEffectiveSimpleDataNodeContainer<CaseStatement> implements
22 ChoiceCaseNode, DerivableSchemaNode {
24 private final ChoiceCaseNode original;
25 private final boolean configuration;
27 public CaseEffectiveStatementImpl(
28 final StmtContext<QName, CaseStatement, EffectiveStatement<QName, CaseStatement>> ctx) {
30 this.original = ctx.getOriginalCtx() == null ? null : (ChoiceCaseNode) ctx.getOriginalCtx().buildEffective();
32 if (ctx.isConfiguration()) {
33 configuration = isAtLeastOneChildConfiguration(ctx.declaredSubstatements()) ||
34 isAtLeastOneChildConfiguration(ctx.effectiveSubstatements());
36 configuration = false;
40 private static boolean isAtLeastOneChildConfiguration(final Collection<StatementContextBase<?, ?, ?>> substatements) {
41 for (StatementContextBase<?, ?, ?> substatement : substatements) {
42 if (substatement.isConfiguration()) {
50 public Optional<ChoiceCaseNode> getOriginal() {
51 return Optional.fromNullable(original);
55 public boolean isConfiguration() {
60 public int hashCode() {
63 result = prime * result + Objects.hashCode(getQName());
64 result = prime * result + Objects.hashCode(getPath());
69 public boolean equals(final Object obj) {
76 if (getClass() != obj.getClass()) {
79 CaseEffectiveStatementImpl other = (CaseEffectiveStatementImpl) obj;
80 return Objects.equals(getQName(), other.getQName()) && Objects.equals(getPath(), other.getPath());
84 public String toString() {
85 return CaseEffectiveStatementImpl.class.getSimpleName() + "[" +