Cleanup DocumentedNode
[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.ModifierKind;
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  * <p>
19  * Provides static factory methods which constructs instances of
20  * <ul>
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 RangeConstraint}.
32      *
33      * <p>
34      * Creates an instance of Range constraint based on supplied parameters
35      * with additional behaviour:
36      * <ul>
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      *     &lt;<i>min</i>, <i>max</i> &gt;</code>
40      * </ul>
41      *
42      * @see RangeConstraint
43      *
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}
50      */
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);
54     }
55
56     /**
57      * Creates a {@link RangeConstraint}.
58      *
59      * <p>
60      * Creates an instance of Range constraint based on supplied parameters
61      * with additional behaviour:
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
65      *     &lt;<i>min</i>, <i>max</i> &gt;</code>
66      * </ul>
67      *
68      * @see RangeConstraint
69      *
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}
78      */
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);
83     }
84
85     /**
86      * Creates a {@link PatternConstraint}.
87      *
88      * <p>
89      * Creates an instance of Pattern constraint based on supplied parameters
90      * with additional behaviour:
91      * <ul>
92      * <li>{@link PatternConstraint#getErrorAppTag()} returns
93      * <code>invalid-regular-expression</code>
94      * </ul>
95      *
96      * @see PatternConstraint
97      *
98      * @param pattern
99      *            Regular expression, MUST NOT BE null.
100      * @param description
101      *            Description associated with constraint.
102      * @param reference
103      *            Reference associated with constraint.
104      * @return Instance of {@link PatternConstraint}
105      */
106     public static PatternConstraint newPatternConstraint(final String pattern, final Optional<String> description,
107             final Optional<String> reference) {
108         return new PatternConstraintImpl(pattern, description, reference);
109     }
110
111     /**
112      * Creates a {@link PatternConstraint}.
113      *
114      * <p>
115      * Creates an instance of Pattern constraint based on supplied parameters
116      * with additional behaviour:
117      * <ul>
118      * <li>{@link PatternConstraint#getErrorAppTag()} returns
119      * <code>invalid-regular-expression</code>
120      * </ul>
121      *
122      * @see PatternConstraint
123      *
124      * @param pattern
125      *            Regular expression, MUST NOT BE null.
126      * @param description
127      *            Description associated with constraint.
128      * @param reference
129      *            Reference associated with constraint.
130      * @param errorAppTag
131      *            error-app-tag associated with constraint.
132      * @param errorMessage
133      *            error message associated with constraint.
134      * @param modifier
135      *            Modifier of pattern constraint.
136      * @return Instance of {@link PatternConstraint}
137      */
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);
142     }
143 }