2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.model.util;
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;
16 * Utility class which provides factory methods to construct Constraints.
18 * Provides static factory methods which constructs instances of
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)}
25 public final class BaseConstraints {
26 private BaseConstraints() {
27 throw new UnsupportedOperationException();
31 * Creates a {@link LengthConstraint}.
33 * Creates an instance of Length constraint based on supplied parameters
34 * with additional behaviour:
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 <<i>min</i>, <i>max</i> ></code>
41 * @see LengthConstraint
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}
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);
55 * Creates a {@link RangeConstraint}.
57 * Creates an instance of Range constraint based on supplied parameters
58 * with additional behaviour:
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 <<i>min</i>, <i>max</i> ></code>
66 * @see RangeConstraint
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}
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);
81 * Creates a {@link PatternConstraint}.
83 * Creates an instance of Pattern constraint based on supplied parameters
84 * with additional behaviour:
87 * <li>{@link PatternConstraint#getErrorAppTag()} returns <code>invalid-regular-expression</code>
90 * @see PatternConstraint
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}
97 public static PatternConstraint newPatternConstraint(final String pattern, final Optional<String> description,
98 final Optional<String> reference) {
99 return new PatternConstraintImpl(pattern, description, reference);