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 com.google.common.base.Preconditions;
12 import com.google.common.collect.ImmutableList;
13 import com.google.common.collect.ImmutableSet;
14 import java.util.Collection;
15 import java.util.List;
16 import java.util.Objects;
18 import javax.annotation.Nonnull;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
21 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
22 import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
23 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
24 import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
25 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
26 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
27 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
28 import org.opendaylight.yangtools.yang.model.api.Status;
29 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
30 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
31 import org.opendaylight.yangtools.yang.model.api.UsesNode;
33 final class CaseShorthandImpl implements ChoiceCaseNode, DerivableSchemaNode {
35 private final DataSchemaNode caseShorthandNode;
36 private final ChoiceCaseNode original;
37 private final SchemaPath path;
38 private final boolean augmenting;
40 CaseShorthandImpl(final DataSchemaNode caseShorthandNode) {
41 this.caseShorthandNode = Preconditions.checkNotNull(caseShorthandNode);
42 this.path = Preconditions.checkNotNull(caseShorthandNode.getPath().getParent());
43 this.original = getOriginalIfPresent(caseShorthandNode);
45 // We need to cache this, as it will be reset
46 this.augmenting = caseShorthandNode.isAugmenting();
50 public boolean isAugmenting() {
55 public boolean isAddedByUses() {
56 return caseShorthandNode.isAddedByUses();
60 public boolean isConfiguration() {
61 return caseShorthandNode.isConfiguration();
65 public ConstraintDefinition getConstraints() {
66 return caseShorthandNode.getConstraints();
71 public QName getQName() {
72 return caseShorthandNode.getQName();
77 public SchemaPath getPath() {
83 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
84 return ImmutableList.of();
88 public String getDescription() {
89 return caseShorthandNode.getDescription();
93 public String getReference() {
94 return caseShorthandNode.getReference();
99 public Status getStatus() {
100 return caseShorthandNode.getStatus();
104 public Set<TypeDefinition<?>> getTypeDefinitions() {
105 return ImmutableSet.of();
109 public Collection<DataSchemaNode> getChildNodes() {
110 return ImmutableList.of(caseShorthandNode);
114 public Set<GroupingDefinition> getGroupings() {
115 return ImmutableSet.of();
119 public DataSchemaNode getDataChildByName(final QName name) {
120 return getQName().equals(name) ? caseShorthandNode : null;
124 public Set<UsesNode> getUses() {
125 return ImmutableSet.of();
129 public Set<AugmentationSchema> getAvailableAugmentations() {
130 return ImmutableSet.of();
134 public Optional<? extends SchemaNode> getOriginal() {
135 return Optional.fromNullable(original);
139 public int hashCode() {
140 final int prime = 31;
142 result = prime * result + Objects.hashCode(getQName());
143 result = prime * result + Objects.hashCode(path);
148 public boolean equals(final Object obj) {
155 if (getClass() != obj.getClass()) {
158 CaseShorthandImpl other = (CaseShorthandImpl) obj;
159 return Objects.equals(getQName(), other.getQName()) && Objects.equals(path, other.path);
163 public String toString() {
164 return CaseShorthandImpl.class.getSimpleName() + "[" + "qname=" + getQName() + "]";
167 private static ChoiceCaseNode getOriginalIfPresent(final SchemaNode caseShorthandNode) {
168 if (caseShorthandNode instanceof DerivableSchemaNode) {
169 final Optional<? extends SchemaNode> original = ((DerivableSchemaNode) caseShorthandNode).getOriginal();
170 if (original.isPresent()) {
171 return new CaseShorthandImpl((DataSchemaNode) original.get());