9b904c563e53ac231b881a1ae05c79244b2e3e8c
[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 RangeConstraint}.
56      *
57      * Creates an instance of Range constraint based on supplied parameters
58      * with additional behaviour:
59      *
60      * <ul>
61      * <li>{@link RangeConstraint#getErrorAppTag()} returns <code>range-out-of-specified-bounds</code>
62      * <li>{@link RangeConstraint#getErrorMessage()} returns <code>The argument is out of bounds &lt;<i>min</i>, <i>max</i> &gt;</code>
63      * </ul>
64      *
65      *
66      * @see RangeConstraint
67      *
68      * @param <T> Type of constraint
69      * @param min value-restricting lower bound value. The value MUST NOT Be null.
70      * @param max value-restricting upper bound value. The value MUST NOT Be null.
71      * @param description Description associated with constraint. {@link Optional#absent()} if description is undefined.
72      * @param reference Reference associated with constraint. {@link Optional#absent()} if reference is undefined.
73      * @return Instance of {@link RangeConstraint}
74      */
75     public static <T extends Number> RangeConstraint newRangeConstraint(final T min, final T max, final Optional<String> description,
76             final Optional<String> reference) {
77         return new RangeConstraintImpl(min, max, description, reference);
78     }
79
80     /**
81      * Creates a {@link PatternConstraint}.
82      *
83      * Creates an instance of Pattern constraint based on supplied parameters
84      * with additional behaviour:
85      *
86      * <ul>
87      * <li>{@link PatternConstraint#getErrorAppTag()} returns <code>invalid-regular-expression</code>
88      * </ul>
89      *
90      * @see PatternConstraint
91      *
92      * @param pattern Regular expression, MUST NOT BE null.
93      * @param description Description associated with constraint.
94      * @param reference Reference associated with constraint.
95      * @return Instance of {@link PatternConstraint}
96      */
97     public static PatternConstraint newPatternConstraint(final String pattern, final Optional<String> description,
98             final Optional<String> reference) {
99         return new PatternConstraintImpl(pattern, description, reference);
100     }
101 }