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