/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.yangtools.yang.model.util;
import com.google.common.base.Optional;
import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
/**
* Utility class which provides factory methods to construct Constraints.
*
* Provides static factory methods which constructs instances of
*
* - {@link LengthConstraint} - {@link #newLengthConstraint(Number, Number, Optional, Optional)}
*
- {@link RangeConstraint} - {@link #newRangeConstraint(Number, Number, Optional, Optional)}
*
- {@link PatternConstraint} - {@link #newPatternConstraint(String, Optional, Optional)}
*
*/
public final class BaseConstraints {
private BaseConstraints() {
throw new UnsupportedOperationException();
}
/**
* Creates a {@link LengthConstraint}.
*
* Creates an instance of Length constraint based on supplied parameters
* with additional behaviour:
*
*
* - {@link LengthConstraint#getErrorAppTag()} returns
length-out-of-specified-bounds
* - {@link LengthConstraint#getErrorMessage()} returns
The argument is out of bounds <min, max >
*
*
* @see LengthConstraint
*
* @param min length-restricting lower bound value. The value MUST NOT be negative.
* @param max length-restricting upper bound value. The value MUST NOT be negative.
* @param description Description associated with constraint. {@link Optional#absent()} if description is undefined.
* @param reference Reference associated with constraint. {@link Optional#absent()} if reference is undefined.
* @return Instance of {@link LengthConstraint}
*/
public static LengthConstraint newLengthConstraint(final Number min, final Number max, final Optional description,
final Optional reference) {
return new LengthConstraintImpl(min, max, description, reference);
}
/**
* Creates a {@link RangeConstraint}.
*
* Creates an instance of Range constraint based on supplied parameters
* with additional behaviour:
*
*
* - {@link RangeConstraint#getErrorAppTag()} returns
range-out-of-specified-bounds
* - {@link RangeConstraint#getErrorMessage()} returns
The argument is out of bounds <min, max >
*
*
*
* @see RangeConstraint
*
* @param Type of constraint
* @param min value-restricting lower bound value. The value MUST NOT Be null.
* @param max value-restricting upper bound value. The value MUST NOT Be null.
* @param description Description associated with constraint. {@link Optional#absent()} if description is undefined.
* @param reference Reference associated with constraint. {@link Optional#absent()} if reference is undefined.
* @return Instance of {@link RangeConstraint}
*/
public static RangeConstraint newRangeConstraint(final T min, final T max, final Optional description,
final Optional reference) {
return new RangeConstraintImpl(min, max, description, reference);
}
/**
* Creates a {@link PatternConstraint}.
*
* Creates an instance of Pattern constraint based on supplied parameters
* with additional behaviour:
*
*
* - {@link PatternConstraint#getErrorAppTag()} returns
invalid-regular-expression
*
*
* @see PatternConstraint
*
* @param pattern Regular expression, MUST NOT BE null.
* @param description Description associated with constraint.
* @param reference Reference associated with constraint.
* @return Instance of {@link PatternConstraint}
*/
public static PatternConstraint newPatternConstraint(final String pattern, final Optional description,
final Optional reference) {
return new PatternConstraintImpl(pattern, description, reference);
}
}