2 * Copyright (c) 2013 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
8 package org.opendaylight.controller.yang.model.util;
10 import org.opendaylight.controller.yang.model.api.type.LengthConstraint;
11 import org.opendaylight.controller.yang.model.api.type.PatternConstraint;
12 import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
14 public final class BaseConstraints {
16 private BaseConstraints() {
19 public static LengthConstraint lengthConstraint(final Number min,
20 final Number max, final String description, final String reference) {
21 return new LengthConstraintImpl(min, max, description, reference);
24 public static RangeConstraint rangeConstraint(final Number min,
25 final Number max, final String description, final String reference) {
26 return new RangeConstraintImpl(min, max, description, reference);
29 public static PatternConstraint patternConstraint(final String pattern,
30 final String description, final String reference) {
31 return new PatternConstraintImpl(pattern, description, reference);
34 private static final class LengthConstraintImpl implements LengthConstraint {
36 private final Number min;
37 private final Number max;
39 private final String description;
40 private final String reference;
42 private final String errorAppTag;
43 private final String errorMessage;
45 public LengthConstraintImpl(Number min, Number max,
46 final String description, final String reference) {
50 this.description = description;
51 this.reference = reference;
53 this.errorAppTag = "length-out-of-specified-bounds";
54 this.errorMessage = "The argument is out of bounds <" + min + ", "
59 public String getDescription() {
64 public String getErrorAppTag() {
69 public String getErrorMessage() {
74 public String getReference() {
79 public Number getMin() {
84 public Number getMax() {
89 public int hashCode() {
92 result = prime * result
93 + ((description == null) ? 0 : description.hashCode());
94 result = prime * result
95 + ((errorAppTag == null) ? 0 : errorAppTag.hashCode());
96 result = prime * result
97 + ((errorMessage == null) ? 0 : errorMessage.hashCode());
98 result = prime * result + ((max == null) ? 0 : max.hashCode());
99 result = prime * result + ((min == null) ? 0 : min.hashCode());
100 result = prime * result
101 + ((reference == null) ? 0 : reference.hashCode());
106 public boolean equals(final Object obj) {
113 if (getClass() != obj.getClass()) {
116 final LengthConstraintImpl other = (LengthConstraintImpl) obj;
117 if (description == null) {
118 if (other.description != null) {
121 } else if (!description.equals(other.description)) {
124 if (errorAppTag == null) {
125 if (other.errorAppTag != null) {
128 } else if (!errorAppTag.equals(other.errorAppTag)) {
131 if (errorMessage == null) {
132 if (other.errorMessage != null) {
135 } else if (!errorMessage.equals(other.errorMessage)) {
138 if (max != other.max) {
141 if (min != other.min) {
144 if (reference == null) {
145 if (other.reference != null) {
148 } else if (!reference.equals(other.reference)) {
155 public String toString() {
156 StringBuilder builder = new StringBuilder();
157 builder.append("LengthConstraintImpl [min=");
159 builder.append(", max=");
161 builder.append(", description=");
162 builder.append(description);
163 builder.append(", errorAppTag=");
164 builder.append(errorAppTag);
165 builder.append(", reference=");
166 builder.append(reference);
167 builder.append(", errorMessage=");
168 builder.append(errorMessage);
170 return builder.toString();
174 private final static class RangeConstraintImpl implements RangeConstraint {
175 private final Number min;
176 private final Number max;
178 private final String description;
179 private final String reference;
181 private final String errorAppTag;
182 private final String errorMessage;
184 public RangeConstraintImpl(Number min, Number max, String description,
189 this.description = description;
190 this.reference = reference;
192 this.errorAppTag = "range-out-of-specified-bounds";
193 this.errorMessage = "The argument is out of bounds <" + min + ", "
198 public String getDescription() {
203 public String getErrorAppTag() {
208 public String getErrorMessage() {
213 public String getReference() {
218 public Number getMin() {
223 public Number getMax() {
228 public int hashCode() {
229 final int prime = 31;
231 result = prime * result
232 + ((description == null) ? 0 : description.hashCode());
233 result = prime * result
234 + ((errorAppTag == null) ? 0 : errorAppTag.hashCode());
235 result = prime * result
236 + ((errorMessage == null) ? 0 : errorMessage.hashCode());
237 result = prime * result + ((max == null) ? 0 : max.hashCode());
238 result = prime * result + ((min == null) ? 0 : min.hashCode());
239 result = prime * result
240 + ((reference == null) ? 0 : reference.hashCode());
245 public boolean equals(final Object obj) {
252 if (getClass() != obj.getClass()) {
255 final RangeConstraintImpl other = (RangeConstraintImpl) obj;
256 if (description == null) {
257 if (other.description != null) {
260 } else if (!description.equals(other.description)) {
263 if (errorAppTag == null) {
264 if (other.errorAppTag != null) {
267 } else if (!errorAppTag.equals(other.errorAppTag)) {
270 if (errorMessage == null) {
271 if (other.errorMessage != null) {
274 } else if (!errorMessage.equals(other.errorMessage)) {
278 if (other.max != null) {
281 } else if (!max.equals(other.max)) {
285 if (other.min != null) {
288 } else if (!min.equals(other.min)) {
291 if (reference == null) {
292 if (other.reference != null) {
295 } else if (!reference.equals(other.reference)) {
302 public String toString() {
303 final StringBuilder builder = new StringBuilder();
304 builder.append("RangeConstraintImpl [min=");
306 builder.append(", max=");
308 builder.append(", description=");
309 builder.append(description);
310 builder.append(", reference=");
311 builder.append(reference);
312 builder.append(", errorAppTag=");
313 builder.append(errorAppTag);
314 builder.append(", errorMessage=");
315 builder.append(errorMessage);
317 return builder.toString();
321 private final static class PatternConstraintImpl implements
324 private final String regex;
325 private final String description;
326 private final String reference;
328 private final String errorAppTag;
329 private final String errorMessage;
331 public PatternConstraintImpl(final String regex,
332 final String description, final String reference) {
335 this.description = description;
336 this.reference = reference;
338 errorAppTag = "invalid-regular-expression";
339 // TODO: add erro message
344 public String getDescription() {
349 public String getErrorAppTag() {
354 public String getErrorMessage() {
359 public String getReference() {
364 public String getRegularExpression() {
369 public int hashCode() {
370 final int prime = 31;
372 result = prime * result
373 + ((description == null) ? 0 : description.hashCode());
374 result = prime * result
375 + ((errorAppTag == null) ? 0 : errorAppTag.hashCode());
376 result = prime * result
377 + ((errorMessage == null) ? 0 : errorMessage.hashCode());
378 result = prime * result
379 + ((reference == null) ? 0 : reference.hashCode());
380 result = prime * result + ((regex == null) ? 0 : regex.hashCode());
385 public boolean equals(final Object obj) {
392 if (getClass() != obj.getClass()) {
395 final PatternConstraintImpl other = (PatternConstraintImpl) obj;
396 if (description == null) {
397 if (other.description != null) {
400 } else if (!description.equals(other.description)) {
403 if (errorAppTag == null) {
404 if (other.errorAppTag != null) {
407 } else if (!errorAppTag.equals(other.errorAppTag)) {
410 if (errorMessage == null) {
411 if (other.errorMessage != null) {
414 } else if (!errorMessage.equals(other.errorMessage)) {
417 if (reference == null) {
418 if (other.reference != null) {
421 } else if (!reference.equals(other.reference)) {
425 if (other.regex != null) {
428 } else if (!regex.equals(other.regex)) {
435 public String toString() {
436 StringBuilder builder = new StringBuilder();
437 builder.append("PatternConstraintImpl [regex=");
438 builder.append(regex);
439 builder.append(", description=");
440 builder.append(description);
441 builder.append(", reference=");
442 builder.append(reference);
443 builder.append(", errorAppTag=");
444 builder.append(errorAppTag);
445 builder.append(", errorMessage=");
446 builder.append(errorMessage);
448 return builder.toString();