package org.opentrafficsim.base.parameters.constraint; import org.djunits.value.vdouble.scalar.base.AbstractDoubleScalar; import org.djutils.exceptions.Throw; /** * Continuous constraints with a single bound. To allow both {@code Double} and {@code AbstractDoubleScalar, ?>} constraints, * the generic type is restricted to {@code Number}. However, that also allows other subclasses of {@code Number}, e.g. * {@code Integer}. Due to rounding and value limits from the type (e.g. {@code Integer.MAX_VALEU}), bounds may not function * correctly after a call to {@code Number.doubleValue()}. To restrict the usage, the constructor is private and static factory * methods for {@code Double} and {@code AbstractDoubleScalar, ?>} are supplied. *
* 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.
*
* 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 8 sep. 2017
* @author Alexander Verbraeck
* @author Peter Knoppers
* @author Wouter Schakel
*/
abstract static class Bound
{
/** Value of the bound. */
@SuppressWarnings("checkstyle:visibilitymodifier")
final Number bound;
/** Hashcode of the value class. */
@SuppressWarnings("checkstyle:visibilitymodifier")
final int classHashcode;
/** String representation of this bound with %s for the value. */
private final String stringFormat;
/**
* Constructor.
* @param bound Number; value of the bound
* @param stringFormat String; string representation of this bound with %s for the value
*/
Bound(final Number bound, final String stringFormat)
{
Throw.whenNull(bound, "Bound may not be null.");
Throw.whenNull(bound, "String format may not be null.");
Throw.when(Double.isNaN(bound.doubleValue()), IllegalArgumentException.class, "Bound value may not be NaN.");
this.bound = bound;
this.classHashcode = bound.getClass().hashCode();
this.stringFormat = stringFormat;
}
/**
* Returns true if the bound accepts the value.
* @param value Number; the value to check
* @return true if the bound accepts the value
*/
abstract boolean accept(Number value);
/** {@inheritDoc} */
@Override
public final String toString()
{
return String.format(this.stringFormat, this.bound);
}
}
/**
* Class implementing a lower inclusive bound; {@code value >= bound}.
*
* 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 8 sep. 2017
* Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
*
* @version $Revision$, $LastChangedDate$, by $Author$, initial version 8 sep. 2017
* Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
*
* @version $Revision$, $LastChangedDate$, by $Author$, initial version 8 sep. 2017
* Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
*
* @version $Revision$, $LastChangedDate$, by $Author$, initial version 8 sep. 2017
* @author Alexander Verbraeck
* @author Peter Knoppers
* @author Wouter Schakel
* @param
* BSD-style license. See OpenTrafficSim License.
*
* @author Alexander Verbraeck
* @author Peter Knoppers
* @author Wouter Schakel
* @param
* BSD-style license. See OpenTrafficSim License.
*
* @author Alexander Verbraeck
* @author Peter Knoppers
* @author Wouter Schakel
* @param
* BSD-style license. See OpenTrafficSim License.
*
* @author Alexander Verbraeck
* @author Peter Knoppers
* @author Wouter Schakel
* @param