API Claratity: Documented package o.o.y.yang.model.util
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / BaseConstraints.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.model.util;
9
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;
13
14 import com.google.common.base.Optional;
15
16 /**
17  * Utility class which provides factory methods to construct Constraints.
18  *
19  * Provides static factory methods which constructs instances of
20  * <ul>
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)}
24  * </ul>
25  */
26 public final class BaseConstraints {
27
28     private BaseConstraints() {
29     }
30
31
32     /**
33      * Creates a {@link LengthConstraint}.
34      *
35      * Creates an instance of Length constraint based on supplied parameters
36      * with additional behaviour:
37      *
38      * <ul>
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 &lt;<i>min</i>, <i>max</i> &gt;</code>
41      * </ul>
42      *
43      * @see LengthConstraint
44      *
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}
50      */
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);
54     }
55
56     /**
57      * Creates a {@link RangeConstraint}.
58      *
59      * Creates an instance of Range constraint based on supplied parameters
60      * with additional behaviour:
61      *
62      * <ul>
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 &lt;<i>min</i>, <i>max</i> &gt;</code>
65      * </ul>
66      *
67      *
68      * @see RangeConstraint
69      *
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}
75      */
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);
79     }
80
81
82     /**
83      * Creates a {@link PatternConstraint}.
84      *
85      * Creates an instance of Pattern constraint based on supplied parameters
86      * with additional behaviour:
87      *
88      * <ul>
89      * <li>{@link PatternConstraint#getErrorAppTag()} returns <code>invalid-regular-expression</code>
90      * </ul>
91      *
92      * @see PatternConstraint
93      *
94      * @param pattern Regular expression, MUST NOT BE null.
95      * @param description Description associated with constraint.
96      * @param reference Reference associated with constraint.
97      * @returnInstance of {@link PatternConstraint}
98      */
99     public static PatternConstraint newPatternConstraint(final String pattern, final Optional<String> description,
100             final Optional<String> reference) {
101         return new PatternConstraintImpl(pattern, description, reference);
102     }
103
104
105     /**
106      * Creates a {@link LengthConstraint}.
107      *
108      * Creates an instance of Length constraint based on supplied parameters
109      * with additional behaviour:
110      *
111      * <ul>
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 &lt;<i>min</i>, <i>max</i> &gt;</code>
114      * </ul>
115      *
116      * @see LengthConstraint
117      *
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.
124      */
125     @Deprecated
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));
129     }
130
131     /**
132      * Creates a {@link RangeConstraint}.
133      *
134      * Creates an instance of Range constraint based on supplied parameters
135      * with additional behaviour:
136      *
137      * <ul>
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 &lt;<i>min</i>, <i>max</i> &gt;</code>
140      * </ul>
141      *
142      *
143      * @see RangeConstraint
144      *
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.
151      */
152     @Deprecated
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));
156     }
157
158     /**
159      * Creates a {@link PatternConstraint}.
160      *
161      * Creates an instance of Range constraint based on supplied parameters
162      * with additional behaviour:
163      *
164      * <ul>
165      * <li>{@link PatternConstraint#getErrorAppTag()} returns <code>invalid-regular-expression</code>
166      * </ul>
167      *
168      *
169      * @see PatternConstraint
170      *
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.
176      */
177     @Deprecated
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));
181     }
182 }