package org.opentrafficsim.base.parameters.constraint;
/**
* In order to define default constraints within a Parameter Type, an enum is available. This interface supplies easy
* access to the values of this enum. To use this interface, simply implement it as below. The value POSITIVE
* is a property of this interface pointing to the enum field POSITIVE. As a result, the value that is set for
* X is checked to be above zero. Note that model and parameterType do not have to be defined in the same class.
*
*
* public class myModel implements ConstraintInterface
* {
*
* public static final ParameterTypeLength X = new ParameterTypeLength("x", "My x parameter.", POSITIVE);
*
* // ... model that uses parameter of type X.
*
* }
*
*
* Another way to access the enum fields is to import them, e.g.:
*
* * import static org.opentrafficsim.core.gtu.drivercharacteristics.AbstractParameterType.Constraint.POSITIVE; ** *
check method of its super. An example
* is given below. The method should throw a ParameterException whenever a constraint is not met. The static
* throwIf method is used to do this. The first check is a simple check on the SI value being above 2. The second check
* compares the value with the value of another parameter in the Parameters. These checks can only be performed if the
* other parameter is present in the Parameters. Checks with other parameter type values should always check whether
* Parameters contains the other parameter type. i.e. params.contains().
* public static final ParameterTypeLength X = new ParameterTypeLength("x", "My x parameter.")
* {
* public void check(Length value, Parameters params) throws ParameterException
* {
* Throw.when(value.si <= 2, ParameterException.class, "Value of X is not above 2.");
* Throw.when(params.contains(Y) && value.si > params.getParameter(Y).si, ParameterException.class,
* "Value of X is larger than value of Y.");
* }
* };
*
*
* Checks are invoked on default values (if given), in which case an empty Parameters is forwarded. At construction of
* a Parameter Type, no Parameters is available. Checks are also invoked when value are set into Parameters,
* in which case that Parameters forwards itself. Even still, if in the above case X is set before Y, the check is
* never performed. Therefore, Y should also compare itself to X. Two parameters that are checked with each other, should
* both implement a check which is consistent with and mirrored to the the others' check. check() method depends on the super Parameter Type. For example:double for ParameterTypeDoubleint for ParameterTypeIntegerSpeed for ParameterTypeSpeedLength for ParameterTypeLengthT for ParameterType<T>ParameterTypeBoolean has no check method as checks on booleans are senseless.
* Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
* BSD-style license. See OpenTrafficSim License.
*
* @version $Revision$, $LastChangedDate$, by $Author$, initial version Apr 13, 2016
* @author Alexander Verbraeck
* @author Wouter Schakel
*/
@SuppressWarnings({"checkstyle:interfaceistype", "checkstyle:javadoctype", "checkstyle:javadocvariable", "javadoc"})
public interface ConstraintInterface
{
// @formatter:off
Constraint