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 java.util.Arrays;
14 import java.util.Collection;
15 import java.util.Collections;
16 import java.util.List;
17 import java.util.Objects;
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 public class CaseShorthandImpl implements ChoiceCaseNode, DerivableSchemaNode {
35 private final DataSchemaNode caseShorthandNode;
36 private final QName qName;
37 private final SchemaPath path;
38 private final String description;
39 private final String reference;
40 private final Status status;
41 private final boolean augmenting;
42 private final boolean addedByUses;
43 private final ConstraintDefinition constraints;
44 private final List<UnknownSchemaNode> unknownNodes;
45 private final ChoiceCaseNode original;
47 public CaseShorthandImpl(final DataSchemaNode caseShorthandNode) {
48 this.caseShorthandNode = caseShorthandNode;
49 this.qName = caseShorthandNode.getQName();
50 this.path = Preconditions.checkNotNull(caseShorthandNode.getPath().getParent());
51 this.description = caseShorthandNode.getDescription();
52 this.reference = caseShorthandNode.getReference();
53 this.status = caseShorthandNode.getStatus();
55 this.augmenting = caseShorthandNode.isAugmenting();
56 this.addedByUses = caseShorthandNode.isAddedByUses();
57 this.constraints = caseShorthandNode.getConstraints();
58 this.unknownNodes = ImmutableList.copyOf(caseShorthandNode.getUnknownSchemaNodes());
60 this.original = getOriginalIfPresent(caseShorthandNode);
64 public boolean isAugmenting() {
69 public boolean isAddedByUses() {
74 public boolean isConfiguration() {
79 public ConstraintDefinition getConstraints() {
84 public QName getQName() {
89 public SchemaPath getPath() {
94 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
99 public String getDescription() {
104 public String getReference() {
109 public Status getStatus() {
114 public Set<TypeDefinition<?>> getTypeDefinitions() {
115 return Collections.emptySet();
119 public Collection<DataSchemaNode> getChildNodes() {
120 return Arrays.asList(caseShorthandNode);
124 public Set<GroupingDefinition> getGroupings() {
125 return Collections.emptySet();
129 public DataSchemaNode getDataChildByName(final QName name) {
130 if (qName.equals(name)) {
131 return caseShorthandNode;
138 public DataSchemaNode getDataChildByName(final String name) {
139 if (qName.getLocalName().equals(name)) {
140 return caseShorthandNode;
147 public Set<UsesNode> getUses() {
148 return Collections.emptySet();
152 public Set<AugmentationSchema> getAvailableAugmentations() {
153 return Collections.emptySet();
157 public Optional<? extends SchemaNode> getOriginal() {
158 return Optional.fromNullable(original);
162 public int hashCode() {
163 final int prime = 31;
165 result = prime * result + Objects.hashCode(qName);
166 result = prime * result + Objects.hashCode(path);
171 public boolean equals(final Object obj) {
178 if (getClass() != obj.getClass()) {
181 CaseShorthandImpl other = (CaseShorthandImpl) obj;
182 return Objects.equals(qName, other.qName) && Objects.equals(path, other.path);
186 public String toString() {
187 StringBuilder sb = new StringBuilder(CaseShorthandImpl.class.getSimpleName());
192 return sb.toString();
195 private static ChoiceCaseNode getOriginalIfPresent(final SchemaNode caseShorthandNode) {
196 if (caseShorthandNode instanceof DerivableSchemaNode) {
197 final Optional<? extends SchemaNode> original = ((DerivableSchemaNode) caseShorthandNode).getOriginal();
198 if (original.isPresent()) {
199 return new CaseShorthandImpl((DataSchemaNode) original.get());