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.ModifierKind;
13 import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
14 import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
17 * Utility class which provides factory methods to construct Constraints.
20 * Provides static factory methods which constructs instances of
22 * <li>{@link LengthConstraint} - {@link #newLengthConstraint(Number, Number, Optional, Optional)}
23 * <li>{@link RangeConstraint} - {@link #newRangeConstraint(Number, Number, Optional, Optional)}
24 * <li>{@link PatternConstraint} - {@link #newPatternConstraint(String, Optional, Optional)}
27 public final class BaseConstraints {
28 private BaseConstraints() {
29 throw new UnsupportedOperationException();
33 * Creates a {@link LengthConstraint}.
36 * Creates an instance of Length constraint based on supplied parameters
37 * with additional behaviour:
39 * <li>{@link LengthConstraint#getErrorAppTag()} returns <code>length-out-of-specified-bounds</code>
40 * <li>{@link LengthConstraint#getErrorMessage()} returns <code>The argument is out of bounds
41 * <<i>min</i>, <i>max</i> ></code>
44 * @see LengthConstraint
46 * @param min length-restricting lower bound value. The value MUST NOT be negative.
47 * @param max length-restricting upper bound value. The value MUST NOT be negative.
48 * @param description Description associated with constraint. {@link Optional#absent()} if description is undefined.
49 * @param reference Reference associated with constraint. {@link Optional#absent()} if reference is undefined.
50 * @return Instance of {@link LengthConstraint}
52 public static LengthConstraint newLengthConstraint(final Number min, final Number max,
53 final Optional<String> description, final Optional<String> reference) {
54 return new LengthConstraintImpl(min, max, description, reference);
58 * Creates a {@link LengthConstraint}.
61 * Creates an instance of Length constraint based on supplied parameters
62 * with additional behaviour:
64 * <li>{@link LengthConstraint#getErrorAppTag()} returns <code>length-out-of-specified-bounds</code>
65 * <li>{@link LengthConstraint#getErrorMessage()} returns <code>The argument is out of bounds
66 * <<i>min</i>, <i>max</i> ></code>
69 * @see LengthConstraint
71 * @param min length-restricting lower bound value. The value MUST NOT be negative.
72 * @param max length-restricting upper bound value. The value MUST NOT be negative.
73 * @param description Description associated with constraint. {@link Optional#absent()} if description is undefined.
74 * @param reference Reference associated with constraint. {@link Optional#absent()} if reference is undefined.
75 * @param errorAppTag error-app-tag associated with constraint.
76 * @param errorMessage error message associated with constraint.
77 * @return Instance of {@link LengthConstraint}
79 public static LengthConstraint newLengthConstraint(final Number min, final Number max,
80 final Optional<String> description, final Optional<String> reference, final String errorAppTag,
81 final String errorMessage) {
82 return new LengthConstraintImpl(min, max, description, reference, errorAppTag, errorMessage);
86 * Creates a {@link RangeConstraint}.
89 * Creates an instance of Range constraint based on supplied parameters
90 * with additional behaviour:
92 * <li>{@link RangeConstraint#getErrorAppTag()} returns <code>range-out-of-specified-bounds</code>
93 * <li>{@link RangeConstraint#getErrorMessage()} returns <code>The argument is out of bounds
94 * <<i>min</i>, <i>max</i> ></code>
97 * @see RangeConstraint
99 * @param <T> Type of constraint
100 * @param min value-restricting lower bound value. The value MUST NOT Be null.
101 * @param max value-restricting upper bound value. The value MUST NOT Be null.
102 * @param description Description associated with constraint. {@link Optional#absent()} if description is undefined.
103 * @param reference Reference associated with constraint. {@link Optional#absent()} if reference is undefined.
104 * @return Instance of {@link RangeConstraint}
106 public static <T extends Number> RangeConstraint newRangeConstraint(final T min, final T max,
107 final Optional<String> description, final Optional<String> reference) {
108 return new RangeConstraintImpl(min, max, description, reference);
112 * Creates a {@link RangeConstraint}.
115 * Creates an instance of Range constraint based on supplied parameters
116 * with additional behaviour:
118 * <li>{@link RangeConstraint#getErrorAppTag()} returns <code>range-out-of-specified-bounds</code>
119 * <li>{@link RangeConstraint#getErrorMessage()} returns <code>The argument is out of bounds
120 * <<i>min</i>, <i>max</i> ></code>
123 * @see RangeConstraint
125 * @param <T> Type of constraint
126 * @param min value-restricting lower bound value. The value MUST NOT Be null.
127 * @param max value-restricting upper bound value. The value MUST NOT Be null.
128 * @param description Description associated with constraint. {@link Optional#absent()} if description is undefined.
129 * @param reference Reference associated with constraint. {@link Optional#absent()} if reference is undefined.
130 * @param errorAppTag error-app-tag associated with constraint.
131 * @param errorMessage error message associated with constraint.
132 * @return Instance of {@link RangeConstraint}
134 public static <T extends Number> RangeConstraint newRangeConstraint(final T min, final T max,
135 final Optional<String> description, final Optional<String> reference, final String errorAppTag,
136 final String errorMessage) {
137 return new RangeConstraintImpl(min, max, description, reference, errorAppTag, errorMessage);
141 * Creates a {@link PatternConstraint}.
144 * Creates an instance of Pattern constraint based on supplied parameters
145 * with additional behaviour:
147 * <li>{@link PatternConstraint#getErrorAppTag()} returns
148 * <code>invalid-regular-expression</code>
151 * @see PatternConstraint
154 * Regular expression, MUST NOT BE null.
156 * Description associated with constraint.
158 * Reference associated with constraint.
159 * @return Instance of {@link PatternConstraint}
161 public static PatternConstraint newPatternConstraint(final String pattern, final Optional<String> description,
162 final Optional<String> reference) {
163 return new PatternConstraintImpl(pattern, description, reference);
167 * Creates a {@link PatternConstraint}.
170 * Creates an instance of Pattern constraint based on supplied parameters
171 * with additional behaviour:
173 * <li>{@link PatternConstraint#getErrorAppTag()} returns
174 * <code>invalid-regular-expression</code>
177 * @see PatternConstraint
180 * Regular expression, MUST NOT BE null.
182 * Description associated with constraint.
184 * Reference associated with constraint.
186 * error-app-tag associated with constraint.
187 * @param errorMessage
188 * error message associated with constraint.
190 * Modifier of pattern constraint.
191 * @return Instance of {@link PatternConstraint}
193 public static PatternConstraint newPatternConstraint(final String pattern, final Optional<String> description,
194 final Optional<String> reference, final String errorAppTag, final String errorMessage,
195 final Optional<ModifierKind> modifier) {
196 return new PatternConstraintImpl(pattern, description, reference, errorAppTag, errorMessage, modifier);