Cleanup use of Guava library
[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 java.util.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;
15
16 /**
17  * Utility class which provides factory methods to construct Constraints.
18  *
19  * <p>
20  * Provides static factory methods which constructs instances of
21  * <ul>
22  * <li>{@link LengthConstraint} - {@link #newLengthConstraint(Number, Number, Optional, Optional)}
23  * <li>{@link RangeConstraint} - {@link #newRangeConstraint(Number, Number, Optional, Optional)}
24  * <li>{@link PatternConstraint} - {@link #newPatternConstraint(String, Optional, Optional)}
25  * </ul>
26  */
27 public final class BaseConstraints {
28     private BaseConstraints() {
29         throw new UnsupportedOperationException();
30     }
31
32     /**
33      * Creates a {@link LengthConstraint}.
34      *
35      * <p>
36      * Creates an instance of Length constraint based on supplied parameters
37      * with additional behaviour:
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
41      *     &lt;<i>min</i>, <i>max</i> &gt;</code>
42      * </ul>
43      *
44      * @see LengthConstraint
45      *
46      * @param min  length-restricting lower bound value. The value MUST NOT be negative.
47      * @param max length-restricting upper bound value. The value MUST NOT be negative.
48      * @param description Description associated with constraint. {@link Optional#empty()} if description is undefined.
49      * @param reference Reference associated with constraint. {@link Optional#empty()} if reference is undefined.
50      * @return Instance of {@link LengthConstraint}
51      */
52     public static LengthConstraint newLengthConstraint(final Number min, final Number max,
53             final Optional<String> description, final Optional<String> reference) {
54         return new LengthConstraintImpl(min, max, description, reference);
55     }
56
57     /**
58      * Creates a {@link LengthConstraint}.
59      *
60      * <p>
61      * Creates an instance of Length constraint based on supplied parameters
62      * with additional behaviour:
63      * <ul>
64      * <li>{@link LengthConstraint#getErrorAppTag()} returns <code>length-out-of-specified-bounds</code>
65      * <li>{@link LengthConstraint#getErrorMessage()} returns <code>The argument is out of bounds
66      *     &lt;<i>min</i>, <i>max</i> &gt;</code>
67      * </ul>
68      *
69      * @see LengthConstraint
70      *
71      * @param min  length-restricting lower bound value. The value MUST NOT be negative.
72      * @param max length-restricting upper bound value. The value MUST NOT be negative.
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 LengthConstraint}
78      */
79     public static LengthConstraint newLengthConstraint(final Number min, final Number max,
80             final Optional<String> description, final Optional<String> reference, final String errorAppTag,
81             final String errorMessage) {
82         return new LengthConstraintImpl(min, max, description, reference, errorAppTag, errorMessage);
83     }
84
85     /**
86      * Creates a {@link RangeConstraint}.
87      *
88      * <p>
89      * Creates an instance of Range constraint based on supplied parameters
90      * with additional behaviour:
91      * <ul>
92      * <li>{@link RangeConstraint#getErrorAppTag()} returns <code>range-out-of-specified-bounds</code>
93      * <li>{@link RangeConstraint#getErrorMessage()} returns <code>The argument is out of bounds
94      *     &lt;<i>min</i>, <i>max</i> &gt;</code>
95      * </ul>
96      *
97      * @see RangeConstraint
98      *
99      * @param <T> Type of constraint
100      * @param min value-restricting lower bound value. The value MUST NOT Be null.
101      * @param max value-restricting upper bound value. The value MUST NOT Be null.
102      * @param description Description associated with constraint. {@link Optional#empty()} if description is undefined.
103      * @param reference Reference associated with constraint. {@link Optional#empty()} if reference is undefined.
104      * @return Instance of {@link RangeConstraint}
105      */
106     public static <T extends Number> RangeConstraint newRangeConstraint(final T min, final T max,
107             final Optional<String> description, final Optional<String> reference) {
108         return new RangeConstraintImpl(min, max, description, reference);
109     }
110
111     /**
112      * Creates a {@link RangeConstraint}.
113      *
114      * <p>
115      * Creates an instance of Range constraint based on supplied parameters
116      * with additional behaviour:
117      * <ul>
118      * <li>{@link RangeConstraint#getErrorAppTag()} returns <code>range-out-of-specified-bounds</code>
119      * <li>{@link RangeConstraint#getErrorMessage()} returns <code>The argument is out of bounds
120      *     &lt;<i>min</i>, <i>max</i> &gt;</code>
121      * </ul>
122      *
123      * @see RangeConstraint
124      *
125      * @param <T> Type of constraint
126      * @param min value-restricting lower bound value. The value MUST NOT Be null.
127      * @param max value-restricting upper bound value. The value MUST NOT Be null.
128      * @param description Description associated with constraint. {@link Optional#empty()} if description is undefined.
129      * @param reference Reference associated with constraint. {@link Optional#empty()} if reference is undefined.
130      * @param errorAppTag error-app-tag associated with constraint.
131      * @param errorMessage error message associated with constraint.
132      * @return Instance of {@link RangeConstraint}
133      */
134     public static <T extends Number> RangeConstraint newRangeConstraint(final T min, final T max,
135             final Optional<String> description, final Optional<String> reference, final String errorAppTag,
136             final String errorMessage) {
137         return new RangeConstraintImpl(min, max, description, reference, errorAppTag, errorMessage);
138     }
139
140     /**
141      * Creates a {@link PatternConstraint}.
142      *
143      * <p>
144      * Creates an instance of Pattern constraint based on supplied parameters
145      * with additional behaviour:
146      * <ul>
147      * <li>{@link PatternConstraint#getErrorAppTag()} returns
148      * <code>invalid-regular-expression</code>
149      * </ul>
150      *
151      * @see PatternConstraint
152      *
153      * @param pattern
154      *            Regular expression, MUST NOT BE null.
155      * @param description
156      *            Description associated with constraint.
157      * @param reference
158      *            Reference associated with constraint.
159      * @return Instance of {@link PatternConstraint}
160      */
161     public static PatternConstraint newPatternConstraint(final String pattern, final Optional<String> description,
162             final Optional<String> reference) {
163         return new PatternConstraintImpl(pattern, description, reference);
164     }
165
166     /**
167      * Creates a {@link PatternConstraint}.
168      *
169      * <p>
170      * Creates an instance of Pattern constraint based on supplied parameters
171      * with additional behaviour:
172      * <ul>
173      * <li>{@link PatternConstraint#getErrorAppTag()} returns
174      * <code>invalid-regular-expression</code>
175      * </ul>
176      *
177      * @see PatternConstraint
178      *
179      * @param pattern
180      *            Regular expression, MUST NOT BE null.
181      * @param description
182      *            Description associated with constraint.
183      * @param reference
184      *            Reference associated with constraint.
185      * @param errorAppTag
186      *            error-app-tag associated with constraint.
187      * @param errorMessage
188      *            error message associated with constraint.
189      * @param modifier
190      *            Modifier of pattern constraint.
191      * @return Instance of {@link PatternConstraint}
192      */
193     public static PatternConstraint newPatternConstraint(final String pattern, final Optional<String> description,
194             final Optional<String> reference, final String errorAppTag, final String errorMessage,
195             final Optional<ModifierKind> modifier) {
196         return new PatternConstraintImpl(pattern, description, reference, errorAppTag, errorMessage, modifier);
197     }
198 }