BUG-865: deprecate pre-Beryllium parser elements
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / builder / impl / ChoiceSchemaNodeImpl.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.yangtools.yang.parser.builder.impl;
10
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;
16 import java.util.Set;
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;
26
27 /**
28  * @deprecated Pre-Beryllium implementation, scheduled for removal.
29  */
30 @Deprecated
31 final class ChoiceSchemaNodeImpl implements ChoiceSchemaNode, DerivableSchemaNode {
32     private final QName qname;
33     private final SchemaPath path;
34     String description;
35     String reference;
36     Status status;
37     boolean augmenting;
38     boolean addedByUses;
39     ChoiceSchemaNode original;
40     boolean configuration;
41     ConstraintDefinition constraints;
42     ImmutableSet<ChoiceCaseNode> cases;
43     ImmutableSet<AugmentationSchema> augmentations;
44     ImmutableList<UnknownSchemaNode> unknownNodes;
45     String defaultCase;
46
47     ChoiceSchemaNodeImpl(final QName qname, final SchemaPath path) {
48         this.qname = qname;
49         this.path = path;
50     }
51
52     @Override
53     public QName getQName() {
54         return qname;
55     }
56
57     @Override
58     public SchemaPath getPath() {
59         return path;
60     }
61
62     @Override
63     public String getDescription() {
64         return description;
65     }
66
67     @Override
68     public String getReference() {
69         return reference;
70     }
71
72     @Override
73     public Status getStatus() {
74         return status;
75     }
76
77     @Override
78     public boolean isAugmenting() {
79         return augmenting;
80     }
81
82     @Override
83     public boolean isAddedByUses() {
84         return addedByUses;
85     }
86
87     @Override
88     public Optional<ChoiceSchemaNode> getOriginal() {
89         return Optional.fromNullable(original);
90     }
91
92     @Override
93     public boolean isConfiguration() {
94         return configuration;
95     }
96
97     @Override
98     public ConstraintDefinition getConstraints() {
99         return constraints;
100     }
101
102     @Override
103     public Set<AugmentationSchema> getAvailableAugmentations() {
104         return augmentations;
105     }
106
107     @Override
108     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
109         return unknownNodes;
110     }
111
112     @Override
113     public Set<ChoiceCaseNode> getCases() {
114         return cases;
115     }
116
117     @Override
118     public ChoiceCaseNode getCaseNodeByName(final QName name) {
119         if (name == null) {
120             throw new IllegalArgumentException("Choice Case QName cannot be NULL!");
121         }
122         for (final ChoiceCaseNode caseNode : cases) {
123             if (caseNode != null && name.equals(caseNode.getQName())) {
124                 return caseNode;
125             }
126         }
127         return null;
128     }
129
130     @Override
131     public ChoiceCaseNode getCaseNodeByName(final String name) {
132         if (name == null) {
133             throw new IllegalArgumentException("Choice Case string Name cannot be NULL!");
134         }
135         for (final ChoiceCaseNode caseNode : cases) {
136             if (caseNode != null && (caseNode.getQName() != null)
137                     && name.equals(caseNode.getQName().getLocalName())) {
138                 return caseNode;
139             }
140         }
141         return null;
142     }
143
144     @Override
145     public String getDefaultCase() {
146         return defaultCase;
147     }
148
149     @Override
150     public int hashCode() {
151         final int prime = 31;
152         int result = 1;
153         result = prime * result + Objects.hashCode(qname);
154         result = prime * result + Objects.hashCode(path);
155         return result;
156     }
157
158     @Override
159     public boolean equals(final Object obj) {
160         if (this == obj) {
161             return true;
162         }
163         if (obj == null) {
164             return false;
165         }
166         if (getClass() != obj.getClass()) {
167             return false;
168         }
169         ChoiceSchemaNodeImpl other = (ChoiceSchemaNodeImpl) obj;
170         if (qname == null) {
171             if (other.qname != null) {
172                 return false;
173             }
174         } else if (!qname.equals(other.qname)) {
175             return false;
176         }
177         if (path == null) {
178             if (other.path != null) {
179                 return false;
180             }
181         } else if (!path.equals(other.path)) {
182             return false;
183         }
184         return true;
185     }
186
187     @Override
188     public String toString() {
189         StringBuilder sb = new StringBuilder(ChoiceSchemaNodeImpl.class.getSimpleName());
190         sb.append("[");
191         sb.append("qname=").append(qname);
192         sb.append("]");
193         return sb.toString();
194     }
195
196 }