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 java.util.Optional;
11 import org.opendaylight.yangtools.yang.model.api.type.ModifierKind;
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.
19 * Provides static factory methods which constructs instances of
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 RangeConstraint}.
34 * Creates an instance of Range constraint based on supplied parameters
35 * with additional behaviour:
37 * <li>{@link RangeConstraint#getErrorAppTag()} returns <code>range-out-of-specified-bounds</code>
38 * <li>{@link RangeConstraint#getErrorMessage()} returns <code>The argument is out of bounds
39 * <<i>min</i>, <i>max</i> ></code>
42 * @see RangeConstraint
44 * @param <T> Type of constraint
45 * @param min value-restricting lower bound value. The value MUST NOT Be null.
46 * @param max value-restricting upper bound value. The value MUST NOT Be null.
47 * @param description Description associated with constraint. {@link Optional#empty()} if description is undefined.
48 * @param reference Reference associated with constraint. {@link Optional#empty()} if reference is undefined.
49 * @return Instance of {@link RangeConstraint}
51 public static <T extends Number> RangeConstraint newRangeConstraint(final T min, final T max,
52 final Optional<String> description, final Optional<String> reference) {
53 return new RangeConstraintImpl(min, max, description, reference);
57 * Creates a {@link RangeConstraint}.
60 * Creates an instance of Range constraint based on supplied parameters
61 * 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
65 * <<i>min</i>, <i>max</i> ></code>
68 * @see RangeConstraint
70 * @param <T> Type of constraint
71 * @param min value-restricting lower bound value. The value MUST NOT Be null.
72 * @param max value-restricting upper bound value. The value MUST NOT Be null.
73 * @param description Description associated with constraint. {@link Optional#empty()} if description is undefined.
74 * @param reference Reference associated with constraint. {@link Optional#empty()} 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 RangeConstraint}
79 public static <T extends Number> RangeConstraint newRangeConstraint(final T min, final T max,
80 final Optional<String> description, final Optional<String> reference, final String errorAppTag,
81 final String errorMessage) {
82 return new RangeConstraintImpl(min, max, description, reference, errorAppTag, errorMessage);
86 * Creates a {@link PatternConstraint}.
89 * Creates an instance of Pattern constraint based on supplied parameters
90 * with additional behaviour:
92 * <li>{@link PatternConstraint#getErrorAppTag()} returns
93 * <code>invalid-regular-expression</code>
96 * @see PatternConstraint
99 * Regular expression, MUST NOT BE null.
101 * Description associated with constraint.
103 * Reference associated with constraint.
104 * @return Instance of {@link PatternConstraint}
106 public static PatternConstraint newPatternConstraint(final String pattern, final Optional<String> description,
107 final Optional<String> reference) {
108 return new PatternConstraintImpl(pattern, description, reference);
112 * Creates a {@link PatternConstraint}.
115 * Creates an instance of Pattern constraint based on supplied parameters
116 * with additional behaviour:
118 * <li>{@link PatternConstraint#getErrorAppTag()} returns
119 * <code>invalid-regular-expression</code>
122 * @see PatternConstraint
125 * Regular expression, MUST NOT BE null.
127 * Description associated with constraint.
129 * Reference associated with constraint.
131 * error-app-tag associated with constraint.
132 * @param errorMessage
133 * error message associated with constraint.
135 * Modifier of pattern constraint.
136 * @return Instance of {@link PatternConstraint}
138 public static PatternConstraint newPatternConstraint(final String pattern, final Optional<String> description,
139 final Optional<String> reference, final String errorAppTag, final String errorMessage,
140 final Optional<ModifierKind> modifier) {
141 return new PatternConstraintImpl(pattern, description, reference, errorAppTag, errorMessage, modifier);