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.collect.ImmutableList;
12 import com.google.common.collect.Iterables;
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;
39 private final String description;
40 private final String reference;
41 private final Status status;
43 private final boolean augmenting;
44 private final boolean addedByUses;
45 ConstraintDefinition constraints;
46 private ChoiceCaseNode original;
48 ImmutableList<UnknownSchemaNode> unknownNodes;
50 public CaseShorthandImpl(DataSchemaNode caseShorthandNode) {
51 this.caseShorthandNode = caseShorthandNode;
52 this.qName = caseShorthandNode.getQName();
54 SchemaPath caseShorthandNodePath = caseShorthandNode.getPath();
55 Iterable<QName> pathFromRoot = caseShorthandNodePath.getPathFromRoot();
56 this.path = SchemaPath
57 .create(Iterables.limit(pathFromRoot,
58 Iterables.size(pathFromRoot) - 1),
59 caseShorthandNodePath.isAbsolute());
61 this.description = caseShorthandNode.getDescription();
62 this.reference = caseShorthandNode.getReference();
63 this.status = caseShorthandNode.getStatus();
65 this.augmenting = caseShorthandNode.isAugmenting();
66 this.addedByUses = caseShorthandNode.isAddedByUses();
67 this.constraints = caseShorthandNode.getConstraints();
68 this.unknownNodes = ImmutableList.copyOf(caseShorthandNode.getUnknownSchemaNodes());
72 public boolean isAugmenting() {
77 public boolean isAddedByUses() {
82 public boolean isConfiguration() {
87 public ConstraintDefinition getConstraints() {
92 public QName getQName() {
97 public SchemaPath getPath() {
102 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
107 public String getDescription() {
112 public String getReference() {
117 public Status getStatus() {
122 public Set<TypeDefinition<?>> getTypeDefinitions() {
123 return Collections.emptySet();
127 public Collection<DataSchemaNode> getChildNodes() {
128 return Arrays.asList(caseShorthandNode);
132 public Set<GroupingDefinition> getGroupings() {
133 return Collections.emptySet();
137 public DataSchemaNode getDataChildByName(QName name) {
138 if (qName.equals(name)) {
139 return caseShorthandNode;
146 public DataSchemaNode getDataChildByName(String name) {
147 if (qName.getLocalName().equals(name)) {
148 return caseShorthandNode;
155 public Set<UsesNode> getUses() {
156 return Collections.emptySet();
160 public Set<AugmentationSchema> getAvailableAugmentations() {
161 return Collections.emptySet();
165 public Optional<? extends SchemaNode> getOriginal() {
166 return Optional.fromNullable(original);
170 public int hashCode() {
171 final int prime = 31;
173 result = prime * result + Objects.hashCode(qName);
174 result = prime * result + Objects.hashCode(path);
179 public boolean equals(final Object obj) {
186 if (getClass() != obj.getClass()) {
189 CaseShorthandImpl other = (CaseShorthandImpl) obj;
191 if (other.qName != null) {
194 } else if (!qName.equals(other.qName)) {
198 if (other.path != null) {
201 } else if (!path.equals(other.path)) {
208 public String toString() {
209 StringBuilder sb = new StringBuilder(
210 CaseShorthandImpl.class.getSimpleName());
215 return sb.toString();