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