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.yangtools.yang.model.util;
10 import com.google.common.base.Optional;
11 import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
12 import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
13 import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
16 * Utility class which provides factory methods to construct Constraints.
18 * Provides static factory methods which constructs instances of
20 * <li>{@link LengthConstraint} - {@link #newLengthConstraint(Number, Number, Optional, Optional)}
21 * <li>{@link RangeConstraint} - {@link #newRangeConstraint(Number, Number, Optional, Optional)}
22 * <li>{@link PatternConstraint} - {@link #newPatternConstraint(String, Optional, Optional)}
25 public final class BaseConstraints {
26 private BaseConstraints() {
27 throw new UnsupportedOperationException();
31 * Creates a {@link LengthConstraint}.
33 * Creates an instance of Length constraint based on supplied parameters
34 * with additional behaviour:
37 * <li>{@link LengthConstraint#getErrorAppTag()} returns <code>length-out-of-specified-bounds</code>
38 * <li>{@link LengthConstraint#getErrorMessage()} returns <code>The argument is out of bounds <<i>min</i>, <i>max</i> ></code>
41 * @see LengthConstraint
43 * @param min length-restricting lower bound value. The value MUST NOT be negative.
44 * @param max length-restricting upper bound value. The value MUST NOT be negative.
45 * @param description Description associated with constraint. {@link Optional#absent()} if description is undefined.
46 * @param reference Reference associated with constraint. {@link Optional#absent()} if reference is undefined.
47 * @return Instance of {@link LengthConstraint}
49 public static LengthConstraint newLengthConstraint(final Number min, final Number max, final Optional<String> description,
50 final Optional<String> reference) {
51 return new LengthConstraintImpl(min, max, description, reference);
55 * Creates a {@link LengthConstraint}.
57 * Creates an instance of Length constraint based on supplied parameters
58 * with additional behaviour:
61 * <li>{@link LengthConstraint#getErrorAppTag()} returns <code>length-out-of-specified-bounds</code>
62 * <li>{@link LengthConstraint#getErrorMessage()} returns <code>The argument is out of bounds <<i>min</i>, <i>max</i> ></code>
65 * @see LengthConstraint
67 * @param min length-restricting lower bound value. The value MUST NOT be negative.
68 * @param max length-restricting upper bound value. The value MUST NOT be negative.
69 * @param description Description associated with constraint. {@link Optional#absent()} if description is undefined.
70 * @param reference Reference associated with constraint. {@link Optional#absent()} if reference is undefined.
71 * @param errorAppTag error-app-tag associated with constraint.
72 * @param errorMessage error message associated with constraint.
73 * @return Instance of {@link LengthConstraint}
75 public static LengthConstraint newLengthConstraint(final Number min, final Number max,
76 final Optional<String> description, final Optional<String> reference, final String errorAppTag,
77 final String errorMessage) {
78 return new LengthConstraintImpl(min, max, description, reference, errorAppTag, errorMessage);
82 * Creates a {@link RangeConstraint}.
84 * Creates an instance of Range constraint based on supplied parameters
85 * with additional behaviour:
88 * <li>{@link RangeConstraint#getErrorAppTag()} returns <code>range-out-of-specified-bounds</code>
89 * <li>{@link RangeConstraint#getErrorMessage()} returns <code>The argument is out of bounds <<i>min</i>, <i>max</i> ></code>
93 * @see RangeConstraint
95 * @param <T> Type of constraint
96 * @param min value-restricting lower bound value. The value MUST NOT Be null.
97 * @param max value-restricting upper bound value. The value MUST NOT Be null.
98 * @param description Description associated with constraint. {@link Optional#absent()} if description is undefined.
99 * @param reference Reference associated with constraint. {@link Optional#absent()} if reference is undefined.
100 * @return Instance of {@link RangeConstraint}
102 public static <T extends Number> RangeConstraint newRangeConstraint(final T min, final T max, final Optional<String> description,
103 final Optional<String> reference) {
104 return new RangeConstraintImpl(min, max, description, reference);
108 * Creates a {@link RangeConstraint}.
110 * Creates an instance of Range constraint based on supplied parameters
111 * with additional behaviour:
114 * <li>{@link RangeConstraint#getErrorAppTag()} returns <code>range-out-of-specified-bounds</code>
115 * <li>{@link RangeConstraint#getErrorMessage()} returns <code>The argument is out of bounds <<i>min</i>, <i>max</i> ></code>
119 * @see RangeConstraint
121 * @param <T> Type of constraint
122 * @param min value-restricting lower bound value. The value MUST NOT Be null.
123 * @param max value-restricting upper bound value. The value MUST NOT Be null.
124 * @param description Description associated with constraint. {@link Optional#absent()} if description is undefined.
125 * @param reference Reference associated with constraint. {@link Optional#absent()} if reference is undefined.
126 * @param errorAppTag error-app-tag associated with constraint.
127 * @param errorMessage error message associated with constraint.
128 * @return Instance of {@link RangeConstraint}
130 public static <T extends Number> RangeConstraint newRangeConstraint(final T min, final T max,
131 final Optional<String> description, final Optional<String> reference, final String errorAppTag,
132 final String errorMessage) {
133 return new RangeConstraintImpl(min, max, description, reference, errorAppTag, errorMessage);
137 * Creates a {@link PatternConstraint}.
139 * Creates an instance of Pattern constraint based on supplied parameters
140 * with additional behaviour:
143 * <li>{@link PatternConstraint#getErrorAppTag()} returns <code>invalid-regular-expression</code>
146 * @see PatternConstraint
148 * @param pattern Regular expression, MUST NOT BE null.
149 * @param description Description associated with constraint.
150 * @param reference Reference associated with constraint.
151 * @return Instance of {@link PatternConstraint}
153 public static PatternConstraint newPatternConstraint(final String pattern, final Optional<String> description,
154 final Optional<String> reference) {
155 return new PatternConstraintImpl(pattern, description, reference);
159 * Creates a {@link PatternConstraint}.
161 * Creates an instance of Pattern constraint based on supplied parameters
162 * with additional behaviour:
165 * <li>{@link PatternConstraint#getErrorAppTag()} returns <code>invalid-regular-expression</code>
168 * @see PatternConstraint
170 * @param pattern Regular expression, MUST NOT BE null.
171 * @param description Description associated with constraint.
172 * @param reference Reference associated with constraint.
173 * @param errorAppTag error-app-tag associated with constraint.
174 * @param errorMessage error message associated with constraint.
175 * @return Instance of {@link PatternConstraint}
177 public static PatternConstraint newPatternConstraint(final String pattern, final Optional<String> description,
178 final Optional<String> reference, final String errorAppTag, final String errorMessage) {
179 return new PatternConstraintImpl(pattern, description, reference, errorAppTag, errorMessage);