1 package org.opendaylight.yangtools.yang.parser.builder.impl;
3 import com.google.common.base.Optional;
4 import com.google.common.collect.ImmutableList;
5 import com.google.common.collect.ImmutableSet;
8 import org.opendaylight.yangtools.yang.common.QName;
9 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
10 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
11 import org.opendaylight.yangtools.yang.model.api.ChoiceNode;
12 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
13 import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
14 import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
15 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
16 import org.opendaylight.yangtools.yang.model.api.Status;
17 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
19 // FIXME: BUG-1513: remove ChoiceNode in Beryllium timeframe
20 final class ChoiceNodeImpl implements ChoiceNode, ChoiceSchemaNode, DerivableSchemaNode {
21 private final QName qname;
22 private final SchemaPath path;
28 ChoiceSchemaNode original;
29 boolean configuration;
30 ConstraintDefinition constraints;
31 ImmutableSet<ChoiceCaseNode> cases;
32 ImmutableSet<AugmentationSchema> augmentations;
33 ImmutableList<UnknownSchemaNode> unknownNodes;
36 ChoiceNodeImpl(final QName qname, final SchemaPath path) {
42 public QName getQName() {
47 public SchemaPath getPath() {
52 public String getDescription() {
57 public String getReference() {
62 public Status getStatus() {
67 public boolean isAugmenting() {
72 public boolean isAddedByUses() {
77 public Optional<ChoiceSchemaNode> getOriginal() {
78 return Optional.fromNullable(original);
82 public boolean isConfiguration() {
87 public ConstraintDefinition getConstraints() {
92 public Set<AugmentationSchema> getAvailableAugmentations() {
97 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
102 public Set<ChoiceCaseNode> getCases() {
107 public ChoiceCaseNode getCaseNodeByName(final QName name) {
109 throw new IllegalArgumentException("Choice Case QName cannot be NULL!");
111 for (final ChoiceCaseNode caseNode : cases) {
112 if (caseNode != null && name.equals(caseNode.getQName())) {
120 public ChoiceCaseNode getCaseNodeByName(final String name) {
122 throw new IllegalArgumentException("Choice Case string Name cannot be NULL!");
124 for (final ChoiceCaseNode caseNode : cases) {
125 if (caseNode != null && (caseNode.getQName() != null)
126 && name.equals(caseNode.getQName().getLocalName())) {
134 public String getDefaultCase() {
139 public int hashCode() {
140 final int prime = 31;
142 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
143 result = prime * result + ((path == null) ? 0 : path.hashCode());
148 public boolean equals(final Object obj) {
155 if (getClass() != obj.getClass()) {
158 ChoiceNodeImpl other = (ChoiceNodeImpl) obj;
160 if (other.qname != null) {
163 } else if (!qname.equals(other.qname)) {
167 if (other.path != null) {
170 } else if (!path.equals(other.path)) {
177 public String toString() {
178 StringBuilder sb = new StringBuilder(ChoiceNodeImpl.class.getSimpleName());
180 sb.append("qname=").append(qname);
182 return sb.toString();