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.
19 * Provides static factory methods which constructs instances of
21 * <li>{@link LengthConstraint} - {@link #newLengthConstraint(Number, Number, Optional, Optional)}
22 * <li>{@link RangeConstraint} - {@link #newRangeConstraint(Number, Number, Optional, Optional)}
23 * <li>{@link PatternConstraint} - {@link #newPatternConstraint(String, Optional, Optional)}
26 public final class BaseConstraints {
27 private BaseConstraints() {
28 throw new UnsupportedOperationException();
32 * Creates a {@link LengthConstraint}.
34 * Creates an instance of Length constraint based on supplied parameters
35 * with additional behaviour:
38 * <li>{@link LengthConstraint#getErrorAppTag()} returns <code>length-out-of-specified-bounds</code>
39 * <li>{@link LengthConstraint#getErrorMessage()} returns <code>The argument is out of bounds <<i>min</i>, <i>max</i> ></code>
42 * @see LengthConstraint
44 * @param min length-restricting lower bound value. The value MUST NOT be negative.
45 * @param max length-restricting upper bound value. The value MUST NOT be negative.
46 * @param description Description associated with constraint. {@link Optional#absent()} if description is undefined.
47 * @param reference Reference associated with constraint. {@link Optional#absent()} if reference is undefined.
48 * @return Instance of {@link LengthConstraint}
50 public static LengthConstraint newLengthConstraint(final Number min, final Number max, final Optional<String> description,
51 final Optional<String> reference) {
52 return new LengthConstraintImpl(min, max, description, reference);
56 * Creates a {@link LengthConstraint}.
58 * Creates an instance of Length constraint based on supplied parameters
59 * with additional behaviour:
62 * <li>{@link LengthConstraint#getErrorAppTag()} returns <code>length-out-of-specified-bounds</code>
63 * <li>{@link LengthConstraint#getErrorMessage()} returns <code>The argument is out of bounds <<i>min</i>, <i>max</i> ></code>
66 * @see LengthConstraint
68 * @param min length-restricting lower bound value. The value MUST NOT be negative.
69 * @param max length-restricting upper bound value. The value MUST NOT be negative.
70 * @param description Description associated with constraint. {@link Optional#absent()} if description is undefined.
71 * @param reference Reference associated with constraint. {@link Optional#absent()} if reference is undefined.
72 * @param errorAppTag error-app-tag associated with constraint.
73 * @param errorMessage error message associated with constraint.
74 * @return Instance of {@link LengthConstraint}
76 public static LengthConstraint newLengthConstraint(final Number min, final Number max,
77 final Optional<String> description, final Optional<String> reference, final String errorAppTag,
78 final String errorMessage) {
79 return new LengthConstraintImpl(min, max, description, reference, errorAppTag, errorMessage);
83 * Creates a {@link RangeConstraint}.
85 * Creates an instance of Range constraint based on supplied parameters
86 * with additional behaviour:
89 * <li>{@link RangeConstraint#getErrorAppTag()} returns <code>range-out-of-specified-bounds</code>
90 * <li>{@link RangeConstraint#getErrorMessage()} returns <code>The argument is out of bounds <<i>min</i>, <i>max</i> ></code>
94 * @see RangeConstraint
96 * @param <T> Type of constraint
97 * @param min value-restricting lower bound value. The value MUST NOT Be null.
98 * @param max value-restricting upper bound value. The value MUST NOT Be null.
99 * @param description Description associated with constraint. {@link Optional#absent()} if description is undefined.
100 * @param reference Reference associated with constraint. {@link Optional#absent()} if reference is undefined.
101 * @return Instance of {@link RangeConstraint}
103 public static <T extends Number> RangeConstraint newRangeConstraint(final T min, final T max, final Optional<String> description,
104 final Optional<String> reference) {
105 return new RangeConstraintImpl(min, max, description, reference);
109 * Creates a {@link RangeConstraint}.
111 * Creates an instance of Range constraint based on supplied parameters
112 * with additional behaviour:
115 * <li>{@link RangeConstraint#getErrorAppTag()} returns <code>range-out-of-specified-bounds</code>
116 * <li>{@link RangeConstraint#getErrorMessage()} returns <code>The argument is out of bounds <<i>min</i>, <i>max</i> ></code>
120 * @see RangeConstraint
122 * @param <T> Type of constraint
123 * @param min value-restricting lower bound value. The value MUST NOT Be null.
124 * @param max value-restricting upper bound value. The value MUST NOT Be null.
125 * @param description Description associated with constraint. {@link Optional#absent()} if description is undefined.
126 * @param reference Reference associated with constraint. {@link Optional#absent()} if reference is undefined.
127 * @param errorAppTag error-app-tag associated with constraint.
128 * @param errorMessage error message associated with constraint.
129 * @return Instance of {@link RangeConstraint}
131 public static <T extends Number> RangeConstraint newRangeConstraint(final T min, final T max,
132 final Optional<String> description, final Optional<String> reference, final String errorAppTag,
133 final String errorMessage) {
134 return new RangeConstraintImpl(min, max, description, reference, errorAppTag, errorMessage);
138 * Creates a {@link PatternConstraint}.
140 * Creates an instance of Pattern constraint based on supplied parameters
141 * with additional behaviour:
144 * <li>{@link PatternConstraint#getErrorAppTag()} returns
145 * <code>invalid-regular-expression</code>
148 * @see PatternConstraint
151 * Regular expression, MUST NOT BE null.
153 * Description associated with constraint.
155 * Reference associated with constraint.
156 * @return Instance of {@link PatternConstraint}
158 public static PatternConstraint newPatternConstraint(final String pattern, final Optional<String> description,
159 final Optional<String> reference) {
160 return new PatternConstraintImpl(pattern, description, reference);
164 * Creates a {@link PatternConstraint}.
166 * Creates an instance of Pattern constraint based on supplied parameters
167 * with additional behaviour:
170 * <li>{@link PatternConstraint#getErrorAppTag()} returns
171 * <code>invalid-regular-expression</code>
174 * @see PatternConstraint
177 * Regular expression, MUST NOT BE null.
179 * Description associated with constraint.
181 * Reference associated with constraint.
183 * error-app-tag associated with constraint.
184 * @param errorMessage
185 * error message associated with constraint.
187 * Modifier of pattern constraint.
188 * @return Instance of {@link PatternConstraint}
190 public static PatternConstraint newPatternConstraint(final String pattern, final Optional<String> description,
191 final Optional<String> reference, final String errorAppTag, final String errorMessage,
192 final Optional<ModifierKind> modifier) {
193 return new PatternConstraintImpl(pattern, description, reference, errorAppTag, errorMessage, modifier);