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.ChoiceSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
21 import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
23 import org.opendaylight.yangtools.yang.model.api.Status;
24 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
26 final class ChoiceSchemaNodeImpl implements ChoiceSchemaNode, DerivableSchemaNode {
27 private final QName qname;
28 private final SchemaPath path;
34 ChoiceSchemaNode original;
35 boolean configuration;
36 ConstraintDefinition constraints;
37 ImmutableSet<ChoiceCaseNode> cases;
38 ImmutableSet<AugmentationSchema> augmentations;
39 ImmutableList<UnknownSchemaNode> unknownNodes;
42 ChoiceSchemaNodeImpl(final QName qname, final SchemaPath path) {
48 public QName getQName() {
53 public SchemaPath getPath() {
58 public String getDescription() {
63 public String getReference() {
68 public Status getStatus() {
73 public boolean isAugmenting() {
78 public boolean isAddedByUses() {
83 public Optional<ChoiceSchemaNode> getOriginal() {
84 return Optional.fromNullable(original);
88 public boolean isConfiguration() {
93 public ConstraintDefinition getConstraints() {
98 public Set<AugmentationSchema> getAvailableAugmentations() {
103 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
108 public Set<ChoiceCaseNode> getCases() {
113 public ChoiceCaseNode getCaseNodeByName(final QName name) {
115 throw new IllegalArgumentException("Choice Case QName cannot be NULL!");
117 for (final ChoiceCaseNode caseNode : cases) {
118 if (caseNode != null && name.equals(caseNode.getQName())) {
126 public ChoiceCaseNode getCaseNodeByName(final String name) {
128 throw new IllegalArgumentException("Choice Case string Name cannot be NULL!");
130 for (final ChoiceCaseNode caseNode : cases) {
131 if (caseNode != null && (caseNode.getQName() != null)
132 && name.equals(caseNode.getQName().getLocalName())) {
140 public String getDefaultCase() {
145 public int hashCode() {
146 final int prime = 31;
148 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
149 result = prime * result + ((path == null) ? 0 : path.hashCode());
154 public boolean equals(final Object obj) {
161 if (getClass() != obj.getClass()) {
164 ChoiceSchemaNodeImpl other = (ChoiceSchemaNodeImpl) obj;
166 if (other.qname != null) {
169 } else if (!qname.equals(other.qname)) {
173 if (other.path != null) {
176 } else if (!path.equals(other.path)) {
183 public String toString() {
184 StringBuilder sb = new StringBuilder(ChoiceSchemaNodeImpl.class.getSimpleName());
186 sb.append("qname=").append(qname);
188 return sb.toString();