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;
20 public final class CaseEffectiveStatementImpl extends AbstractEffectiveSimpleDataNodeContainer<CaseStatement> implements
21 ChoiceCaseNode, DerivableSchemaNode {
23 private final ChoiceCaseNode original;
24 private final boolean configuration;
26 public CaseEffectiveStatementImpl(
27 final StmtContext<QName, CaseStatement, EffectiveStatement<QName, CaseStatement>> ctx) {
29 this.original = (ChoiceCaseNode) ctx.getOriginalCtx().map(StmtContext::buildEffective).orElse(null);
31 if (ctx.isConfiguration()) {
32 configuration = isAtLeastOneChildConfiguration(ctx.declaredSubstatements())
33 || isAtLeastOneChildConfiguration(ctx.effectiveSubstatements());
35 configuration = false;
39 private static boolean isAtLeastOneChildConfiguration(final Collection<? extends StmtContext<?, ?, ?>> children) {
40 return children.stream().anyMatch(StmtContext::isConfiguration);
44 public Optional<ChoiceCaseNode> getOriginal() {
45 return Optional.fromNullable(original);
49 public boolean isConfiguration() {
54 public int hashCode() {
57 result = prime * result + Objects.hashCode(getQName());
58 result = prime * result + Objects.hashCode(getPath());
63 public boolean equals(final Object obj) {
70 if (getClass() != obj.getClass()) {
73 CaseEffectiveStatementImpl other = (CaseEffectiveStatementImpl) obj;
74 return Objects.equals(getQName(), other.getQName()) && Objects.equals(getPath(), other.getPath());
78 public String toString() {
79 return CaseEffectiveStatementImpl.class.getSimpleName() + "[" +