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 org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
11 import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
12 import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
14 import com.google.common.base.Optional;
17 * Utility class which provides factory methods to construct Constraints.
19 * Provides static factory methods which constructs instances of
21 * <li>{@link LengthConstraint} - {@link #lengthConstraint(Number, Number, String, String)}
22 * <li>{@link RangeConstraint} - {@link #rangeConstraint(Number, Number, String, String)}
23 * <li>{@link PatternConstraint} - {@link #patternConstraint(String, String, String)}
26 public final class BaseConstraints {
28 private BaseConstraints() {
33 * Creates a {@link LengthConstraint}.
35 * Creates an instance of Length constraint based on supplied parameters
36 * 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 <<i>min</i>, <i>max</i> ></code>
43 * @see LengthConstraint
45 * @param min length-restricting lower bound value. The value MUST NOT be negative.
46 * @param max length-restricting upper bound value. The value MUST NOT be negative.
47 * @param description Description associated with constraint. {@link Optional#absent()} if description is undefined.
48 * @param reference Reference associated with constraint. {@link Optional#absent()} if reference is undefined.
49 * @return Instance of {@link LengthConstraint}
51 public static LengthConstraint newLengthConstraint(final Number min, final Number max, final Optional<String> description,
52 final Optional<String> reference) {
53 return new LengthConstraintImpl(min, max, description, reference);
57 * Creates a {@link RangeConstraint}.
59 * Creates an instance of Range constraint based on supplied parameters
60 * with additional behaviour:
63 * <li>{@link RangeConstraint#getErrorAppTag()} returns <code>range-out-of-specified-bounds</code>
64 * <li>{@link RangeConstraint#getErrorMessage()} returns <code>The argument is out of bounds <<i>min</i>, <i>max</i> ></code>
68 * @see RangeConstraint
70 * @param min value-restricting lower bound value. The value MUST NOT Be null.
71 * @param max value-restricting upper bound value. The value MUST NOT Be null.
72 * @param description Description associated with constraint. {@link Optional#absent()} if description is undefined.
73 * @param reference Reference associated with constraint. {@link Optional#absent()} if reference is undefined.
74 * @return Instance of {@link RangeConstraint}
76 public static RangeConstraint newRangeConstraint(final Number min, final Number max, final Optional<String> description,
77 final Optional<String> reference) {
78 return new RangeConstraintImpl(min, max, description, reference);
83 * Creates a {@link PatternConstraint}.
85 * Creates an instance of Pattern constraint based on supplied parameters
86 * with additional behaviour:
89 * <li>{@link PatternConstraint#getErrorAppTag()} returns <code>invalid-regular-expression</code>
92 * @see PatternConstraint
94 * @param pattern Regular expression, MUST NOT BE null.
95 * @param description Description associated with constraint.
96 * @param reference Reference associated with constraint.
97 * @return Instance of {@link PatternConstraint}
99 public static PatternConstraint newPatternConstraint(final String pattern, final Optional<String> description,
100 final Optional<String> reference) {
101 return new PatternConstraintImpl(pattern, description, reference);
106 * Creates a {@link LengthConstraint}.
108 * Creates an instance of Length constraint based on supplied parameters
109 * with additional behaviour:
112 * <li>{@link LengthConstraint#getErrorAppTag()} returns <code>length-out-of-specified-bounds</code>
113 * <li>{@link LengthConstraint#getErrorMessage()} returns <code>The argument is out of bounds <<i>min</i>, <i>max</i> ></code>
116 * @see LengthConstraint
118 * @param min length-restricting lower bound value. The value MUST NOT be negative.
119 * @param max length-restricting upper bound value. The value MUST NOT be negative.
120 * @param description Description associated with constraint.
121 * @param reference Reference associated with constraint.
122 * @return Instance of {@link LengthConstraint}
123 * @deprecated Use {@link #newLengthConstraint(Number, Number, Optional, Optional)} instead.
126 public static LengthConstraint lengthConstraint(final Number min, final Number max, final String description,
127 final String reference) {
128 return newLengthConstraint(min, max, Optional.fromNullable(description), Optional.fromNullable(reference));
132 * Creates a {@link RangeConstraint}.
134 * Creates an instance of Range constraint based on supplied parameters
135 * with additional behaviour:
138 * <li>{@link RangeConstraint#getErrorAppTag()} returns <code>range-out-of-specified-bounds</code>
139 * <li>{@link RangeConstraint#getErrorMessage()} returns <code>The argument is out of bounds <<i>min</i>, <i>max</i> ></code>
143 * @see RangeConstraint
145 * @param min value-restricting lower bound value. The value MUST NOT Be null.
146 * @param max value-restricting upper bound value. The value MUST NOT Be null.
147 * @param description Description associated with constraint.
148 * @param reference Reference associated with constraint.
149 * @return Instance of {@link RangeConstraint}
150 * @deprecated Use {@link #newRangeConstraint(Number, Number, Optional, Optional)} instead.
153 public static RangeConstraint rangeConstraint(final Number min, final Number max, final String description,
154 final String reference) {
155 return newRangeConstraint(min, max, Optional.fromNullable(description), Optional.fromNullable(reference));
159 * Creates a {@link PatternConstraint}.
161 * Creates an instance of Range constraint based on supplied parameters
162 * with additional behaviour:
165 * <li>{@link PatternConstraint#getErrorAppTag()} returns <code>invalid-regular-expression</code>
169 * @see PatternConstraint
171 * @param pattern Regular expression, MUST NOT
172 * @param description Description associated with constraint.
173 * @param reference Reference associated with constraint.
174 * @return Instance of {@link PatternConstraint}
175 * @deprecated Use {@link #newPatternConstraint(String, Optional, Optional)} Instead.
178 public static PatternConstraint patternConstraint(final String pattern, final String description,
179 final String reference) {
180 return newPatternConstraint(pattern, Optional.fromNullable(description), Optional.fromNullable(reference));