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
9 package org.opendaylight.yangtools.yang.parser.builder.impl;
11 import com.google.common.base.Optional;
12 import com.google.common.collect.ImmutableList;
13 import com.google.common.collect.ImmutableSet;
14 import java.util.List;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
18 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
19 import org.opendaylight.yangtools.yang.model.api.ChoiceNode;
20 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
22 import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
24 import org.opendaylight.yangtools.yang.model.api.Status;
25 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
27 // FIXME: BUG-1513: remove ChoiceNode in Beryllium timeframe
28 final class ChoiceNodeImpl implements ChoiceNode, ChoiceSchemaNode, DerivableSchemaNode {
29 private final QName qname;
30 private final SchemaPath path;
36 ChoiceSchemaNode original;
37 boolean configuration;
38 ConstraintDefinition constraints;
39 ImmutableSet<ChoiceCaseNode> cases;
40 ImmutableSet<AugmentationSchema> augmentations;
41 ImmutableList<UnknownSchemaNode> unknownNodes;
44 ChoiceNodeImpl(final QName qname, final SchemaPath path) {
50 public QName getQName() {
55 public SchemaPath getPath() {
60 public String getDescription() {
65 public String getReference() {
70 public Status getStatus() {
75 public boolean isAugmenting() {
80 public boolean isAddedByUses() {
85 public Optional<ChoiceSchemaNode> getOriginal() {
86 return Optional.fromNullable(original);
90 public boolean isConfiguration() {
95 public ConstraintDefinition getConstraints() {
100 public Set<AugmentationSchema> getAvailableAugmentations() {
101 return augmentations;
105 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
110 public Set<ChoiceCaseNode> getCases() {
115 public ChoiceCaseNode getCaseNodeByName(final QName name) {
117 throw new IllegalArgumentException("Choice Case QName cannot be NULL!");
119 for (final ChoiceCaseNode caseNode : cases) {
120 if (caseNode != null && name.equals(caseNode.getQName())) {
128 public ChoiceCaseNode getCaseNodeByName(final String name) {
130 throw new IllegalArgumentException("Choice Case string Name cannot be NULL!");
132 for (final ChoiceCaseNode caseNode : cases) {
133 if (caseNode != null && (caseNode.getQName() != null)
134 && name.equals(caseNode.getQName().getLocalName())) {
142 public String getDefaultCase() {
147 public int hashCode() {
148 final int prime = 31;
150 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
151 result = prime * result + ((path == null) ? 0 : path.hashCode());
156 public boolean equals(final Object obj) {
163 if (getClass() != obj.getClass()) {
166 ChoiceNodeImpl other = (ChoiceNodeImpl) obj;
168 if (other.qname != null) {
171 } else if (!qname.equals(other.qname)) {
175 if (other.path != null) {
178 } else if (!path.equals(other.path)) {
185 public String toString() {
186 StringBuilder sb = new StringBuilder(ChoiceNodeImpl.class.getSimpleName());
188 sb.append("qname=").append(qname);
190 return sb.toString();