Bug 5200: Yang parser doesn't fill error-app-tag and error-message in constraints
[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 com.google.common.base.Optional;
11 import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
12 import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
13 import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
14
15 /**
16  * Utility class which provides factory methods to construct Constraints.
17  *
18  * Provides static factory methods which constructs instances of
19  * <ul>
20  * <li>{@link LengthConstraint} - {@link #newLengthConstraint(Number, Number, Optional, Optional)}
21  * <li>{@link RangeConstraint} - {@link #newRangeConstraint(Number, Number, Optional, Optional)}
22  * <li>{@link PatternConstraint} - {@link #newPatternConstraint(String, Optional, Optional)}
23  * </ul>
24  */
25 public final class BaseConstraints {
26     private BaseConstraints() {
27         throw new UnsupportedOperationException();
28     }
29
30     /**
31      * Creates a {@link LengthConstraint}.
32      *
33      * Creates an instance of Length constraint based on supplied parameters
34      * with additional behaviour:
35      *
36      * <ul>
37      * <li>{@link LengthConstraint#getErrorAppTag()} returns <code>length-out-of-specified-bounds</code>
38      * <li>{@link LengthConstraint#getErrorMessage()} returns <code>The argument is out of bounds &lt;<i>min</i>, <i>max</i> &gt;</code>
39      * </ul>
40      *
41      * @see LengthConstraint
42      *
43      * @param min  length-restricting lower bound value. The value MUST NOT be negative.
44      * @param max length-restricting upper bound value. The value MUST NOT be negative.
45      * @param description Description associated with constraint. {@link Optional#absent()} if description is undefined.
46      * @param reference Reference associated with constraint. {@link Optional#absent()} if reference is undefined.
47      * @return Instance of {@link LengthConstraint}
48      */
49     public static LengthConstraint newLengthConstraint(final Number min, final Number max, final Optional<String> description,
50             final Optional<String> reference) {
51         return new LengthConstraintImpl(min, max, description, reference);
52     }
53
54     /**
55      * Creates a {@link LengthConstraint}.
56      *
57      * Creates an instance of Length constraint based on supplied parameters
58      * with additional behaviour:
59      *
60      * <ul>
61      * <li>{@link LengthConstraint#getErrorAppTag()} returns <code>length-out-of-specified-bounds</code>
62      * <li>{@link LengthConstraint#getErrorMessage()} returns <code>The argument is out of bounds &lt;<i>min</i>, <i>max</i> &gt;</code>
63      * </ul>
64      *
65      * @see LengthConstraint
66      *
67      * @param min  length-restricting lower bound value. The value MUST NOT be negative.
68      * @param max length-restricting upper bound value. The value MUST NOT be negative.
69      * @param description Description associated with constraint. {@link Optional#absent()} if description is undefined.
70      * @param reference Reference associated with constraint. {@link Optional#absent()} if reference is undefined.
71      * @param errorAppTag error-app-tag associated with constraint.
72      * @param errorMessage error message associated with constraint.
73      * @return Instance of {@link LengthConstraint}
74      */
75     public static LengthConstraint newLengthConstraint(final Number min, final Number max,
76             final Optional<String> description, final Optional<String> reference, final String errorAppTag,
77             final String errorMessage) {
78         return new LengthConstraintImpl(min, max, description, reference, errorAppTag, errorMessage);
79     }
80
81     /**
82      * Creates a {@link RangeConstraint}.
83      *
84      * Creates an instance of Range constraint based on supplied parameters
85      * with additional behaviour:
86      *
87      * <ul>
88      * <li>{@link RangeConstraint#getErrorAppTag()} returns <code>range-out-of-specified-bounds</code>
89      * <li>{@link RangeConstraint#getErrorMessage()} returns <code>The argument is out of bounds &lt;<i>min</i>, <i>max</i> &gt;</code>
90      * </ul>
91      *
92      *
93      * @see RangeConstraint
94      *
95      * @param <T> Type of constraint
96      * @param min value-restricting lower bound value. The value MUST NOT Be null.
97      * @param max value-restricting upper bound value. The value MUST NOT Be null.
98      * @param description Description associated with constraint. {@link Optional#absent()} if description is undefined.
99      * @param reference Reference associated with constraint. {@link Optional#absent()} if reference is undefined.
100      * @return Instance of {@link RangeConstraint}
101      */
102     public static <T extends Number> RangeConstraint newRangeConstraint(final T min, final T max, final Optional<String> description,
103             final Optional<String> reference) {
104         return new RangeConstraintImpl(min, max, description, reference);
105     }
106
107     /**
108      * Creates a {@link RangeConstraint}.
109      *
110      * Creates an instance of Range constraint based on supplied parameters
111      * with additional behaviour:
112      *
113      * <ul>
114      * <li>{@link RangeConstraint#getErrorAppTag()} returns <code>range-out-of-specified-bounds</code>
115      * <li>{@link RangeConstraint#getErrorMessage()} returns <code>The argument is out of bounds &lt;<i>min</i>, <i>max</i> &gt;</code>
116      * </ul>
117      *
118      *
119      * @see RangeConstraint
120      *
121      * @param <T> Type of constraint
122      * @param min value-restricting lower bound value. The value MUST NOT Be null.
123      * @param max value-restricting upper bound value. The value MUST NOT Be null.
124      * @param description Description associated with constraint. {@link Optional#absent()} if description is undefined.
125      * @param reference Reference associated with constraint. {@link Optional#absent()} if reference is undefined.
126      * @param errorAppTag error-app-tag associated with constraint.
127      * @param errorMessage error message associated with constraint.
128      * @return Instance of {@link RangeConstraint}
129      */
130     public static <T extends Number> RangeConstraint newRangeConstraint(final T min, final T max,
131             final Optional<String> description, final Optional<String> reference, final String errorAppTag,
132             final String errorMessage) {
133         return new RangeConstraintImpl(min, max, description, reference, errorAppTag, errorMessage);
134     }
135
136     /**
137      * Creates a {@link PatternConstraint}.
138      *
139      * Creates an instance of Pattern constraint based on supplied parameters
140      * with additional behaviour:
141      *
142      * <ul>
143      * <li>{@link PatternConstraint#getErrorAppTag()} returns <code>invalid-regular-expression</code>
144      * </ul>
145      *
146      * @see PatternConstraint
147      *
148      * @param pattern Regular expression, MUST NOT BE null.
149      * @param description Description associated with constraint.
150      * @param reference Reference associated with constraint.
151      * @return Instance of {@link PatternConstraint}
152      */
153     public static PatternConstraint newPatternConstraint(final String pattern, final Optional<String> description,
154             final Optional<String> reference) {
155         return new PatternConstraintImpl(pattern, description, reference);
156     }
157
158     /**
159      * Creates a {@link PatternConstraint}.
160      *
161      * Creates an instance of Pattern 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      * @see PatternConstraint
169      *
170      * @param pattern Regular expression, MUST NOT BE null.
171      * @param description Description associated with constraint.
172      * @param reference Reference associated with constraint.
173      * @param errorAppTag error-app-tag associated with constraint.
174      * @param errorMessage error message associated with constraint.
175      * @return Instance of {@link PatternConstraint}
176      */
177     public static PatternConstraint newPatternConstraint(final String pattern, final Optional<String> description,
178             final Optional<String> reference, final String errorAppTag, final String errorMessage) {
179         return new PatternConstraintImpl(pattern, description, reference, errorAppTag, errorMessage);
180     }
181 }