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