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;
15 import java.util.Objects;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
19 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
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 final class ChoiceSchemaNodeImpl implements ChoiceSchemaNode, DerivableSchemaNode {
28 private final QName qname;
29 private final SchemaPath path;
35 ChoiceSchemaNode original;
36 boolean configuration;
37 ConstraintDefinition constraints;
38 ImmutableSet<ChoiceCaseNode> cases;
39 ImmutableSet<AugmentationSchema> augmentations;
40 ImmutableList<UnknownSchemaNode> unknownNodes;
43 ChoiceSchemaNodeImpl(final QName qname, final SchemaPath path) {
49 public QName getQName() {
54 public SchemaPath getPath() {
59 public String getDescription() {
64 public String getReference() {
69 public Status getStatus() {
74 public boolean isAugmenting() {
79 public boolean isAddedByUses() {
84 public Optional<ChoiceSchemaNode> getOriginal() {
85 return Optional.fromNullable(original);
89 public boolean isConfiguration() {
94 public ConstraintDefinition getConstraints() {
99 public Set<AugmentationSchema> getAvailableAugmentations() {
100 return augmentations;
104 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
109 public Set<ChoiceCaseNode> getCases() {
114 public ChoiceCaseNode getCaseNodeByName(final QName name) {
116 throw new IllegalArgumentException("Choice Case QName cannot be NULL!");
118 for (final ChoiceCaseNode caseNode : cases) {
119 if (caseNode != null && name.equals(caseNode.getQName())) {
127 public ChoiceCaseNode getCaseNodeByName(final String name) {
129 throw new IllegalArgumentException("Choice Case string Name cannot be NULL!");
131 for (final ChoiceCaseNode caseNode : cases) {
132 if (caseNode != null && (caseNode.getQName() != null)
133 && name.equals(caseNode.getQName().getLocalName())) {
141 public String getDefaultCase() {
146 public int hashCode() {
147 final int prime = 31;
149 result = prime * result + Objects.hashCode(qname);
150 result = prime * result + Objects.hashCode(path);
155 public boolean equals(final Object obj) {
162 if (getClass() != obj.getClass()) {
165 ChoiceSchemaNodeImpl other = (ChoiceSchemaNodeImpl) obj;
167 if (other.qname != null) {
170 } else if (!qname.equals(other.qname)) {
174 if (other.path != null) {
177 } else if (!path.equals(other.path)) {
184 public String toString() {
185 StringBuilder sb = new StringBuilder(ChoiceSchemaNodeImpl.class.getSimpleName());
187 sb.append("qname=").append(qname);
189 return sb.toString();