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.rfc7950.stmt.choice;
10 import com.google.common.collect.ImmutableList;
11 import com.google.common.collect.ImmutableSortedMap;
12 import java.util.Objects;
13 import java.util.Optional;
14 import java.util.SortedMap;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
22 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
23 import org.opendaylight.yangtools.yang.model.api.stmt.ChoiceEffectiveStatement;
24 import org.opendaylight.yangtools.yang.model.api.stmt.ChoiceStatement;
25 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractDeclaredEffectiveStatement.DefaultWithSchemaTree.WithSubstatements;
26 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStatementMixins.AugmentationTargetMixin;
27 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStatementMixins.DataSchemaNodeMixin;
28 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStatementMixins.MandatoryMixin;
29 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
31 final class ChoiceEffectiveStatementImpl extends WithSubstatements<QName, ChoiceStatement, ChoiceEffectiveStatement>
32 implements ChoiceEffectiveStatement, ChoiceSchemaNode, DerivableSchemaNode,
33 DataSchemaNodeMixin<QName, ChoiceStatement>, AugmentationTargetMixin<QName, ChoiceStatement>,
34 MandatoryMixin<QName, ChoiceStatement> {
35 private final ImmutableSortedMap<QName, CaseSchemaNode> cases;
36 private final CaseSchemaNode defaultCase;
37 private final ChoiceSchemaNode original;
38 private final @NonNull SchemaPath path;
39 private final int flags;
41 ChoiceEffectiveStatementImpl(final ChoiceStatement declared,
42 final StmtContext<QName, ChoiceStatement, ChoiceEffectiveStatement> ctx,
43 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements, final int flags,
44 final SortedMap<QName, CaseSchemaNode> cases, final @Nullable CaseSchemaNode defaultCase,
45 final @Nullable ChoiceSchemaNode original) {
46 super(declared, ctx, substatements);
48 this.path = ctx.getSchemaPath().get();
49 this.cases = ImmutableSortedMap.copyOfSorted(cases);
50 this.defaultCase = defaultCase;
51 this.original = original;
55 public @NonNull QName argument() {
60 public SchemaPath getPath() {
70 public Optional<ChoiceSchemaNode> getOriginal() {
71 return Optional.ofNullable(original);
75 public SortedMap<QName, CaseSchemaNode> getCases() {
80 public Optional<CaseSchemaNode> getDefaultCase() {
81 return Optional.ofNullable(defaultCase);
85 public int hashCode() {
88 result = prime * result + Objects.hashCode(getQName());
89 result = prime * result + Objects.hashCode(getPath());
94 public boolean equals(final Object obj) {
101 if (getClass() != obj.getClass()) {
104 final ChoiceEffectiveStatementImpl other = (ChoiceEffectiveStatementImpl) obj;
105 return Objects.equals(getQName(), other.getQName()) && Objects.equals(getPath(), other.getPath());
110 public String toString() {
111 return ChoiceEffectiveStatementImpl.class.getSimpleName() + "["
112 + "qname=" + getQName()