ParameterTypeDouble.java

  1. package org.opentrafficsim.base.parameters;

  2. import java.io.Serializable;

  3. import org.djunits.value.formatter.EngineeringFormatter;
  4. import org.opentrafficsim.base.parameters.constraint.Constraint;

  5. /**
  6.  * Wrapper class for double parameters.
  7.  * <p>
  8.  * Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  9.  * BSD-style license. See <a href="http://opentrafficsim.org/docs/current/license.html">OpenTrafficSim License</a>.
  10.  * <p>
  11.  * @version $Revision$, $LastChangedDate$, by $Author$, initial version Apr 13, 2016 <br>
  12.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  13.  * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
  14.  */
  15. public class ParameterTypeDouble extends ParameterTypeNumeric<Double> implements Serializable
  16. {

  17.     /** */
  18.     private static final long serialVersionUID = 120160400;

  19.     /**
  20.      * Construct a new ParameterTypeDouble without default value and check.
  21.      * @param id String; short name of the new ParameterTypeDouble
  22.      * @param description String; parameter description or full name of the new ParameterTypeDouble
  23.      */
  24.     public ParameterTypeDouble(final String id, final String description)
  25.     {
  26.         super(id, description, Double.class);
  27.     }

  28.     /**
  29.      * Construct a new ParameterTypeDouble with default value, without check.
  30.      * @param id String; short name of the new ParameterTypeDouble
  31.      * @param description String; parameter description or full name of the new ParameterTypeDouble
  32.      * @param defaultValue double; the default value of the new ParametertypeDouble
  33.      */
  34.     public ParameterTypeDouble(final String id, final String description, final double defaultValue)
  35.     {
  36.         super(id, description, Double.class, defaultValue);
  37.     }

  38.     /**
  39.      * Construct a new ParameterTypeDouble without default value, with check.
  40.      * @param id String; short name of the new ParameterTypeDouble
  41.      * @param description String; parameter description or full name of the new ParameterTypeDouble
  42.      * @param constraint Constrain&lt;? super Double&gt;; constraint for parameter values
  43.      */
  44.     public ParameterTypeDouble(final String id, final String description, final Constraint<? super Double> constraint)
  45.     {
  46.         super(id, description, Double.class, constraint);
  47.     }

  48.     /**
  49.      * Construct a new ParameterTypeDouble with default value and check.
  50.      * @param id String; short name of the new ParameterTypeDouble
  51.      * @param description String; parameter description or full name of the new ParameterTypeDouble
  52.      * @param defaultValue double; the default value of the new ParameterTypeDouble
  53.      * @param constraint Constraint&lt;? super Double&gt;; constraint for parameter values
  54.      */
  55.     public ParameterTypeDouble(final String id, final String description, final double defaultValue,
  56.             final Constraint<? super Double> constraint)
  57.     {
  58.         super(id, description, Double.class, defaultValue, constraint);
  59.     }

  60.     /**
  61.      * Construct a new ParameterTypeDouble with default value and check.
  62.      * @param id String; short name of the new ParameterTypeDouble
  63.      * @param description String; parameter description or full name of the new ParameterTypeDouble
  64.      * @param defaultValue Double; default value for the new ParameterTypeDouble
  65.      * @param constraint Constraint&lt;Number&gt;; constraint for parameter values
  66.      */
  67.     public ParameterTypeDouble(final String id, final String description, final Double defaultValue,
  68.             final Constraint<Number> constraint)
  69.     {
  70.         super(id, description, Double.class, defaultValue, constraint);
  71.     }

  72.     /** {@inheritDoc} */
  73.     @Override
  74.     public final String printValue(final Parameters parameters) throws ParameterException
  75.     {
  76.         return EngineeringFormatter.format(parameters.getParameter(this));
  77.     }

  78.     /** {@inheritDoc} */
  79.     @SuppressWarnings("checkstyle:designforextension")
  80.     @Override
  81.     public String toString()
  82.     {
  83.         return "ParameterTypeDouble [id=" + getId() + ", description=" + getDescription() + "]";
  84.     }

  85. }