1 package org.opentrafficsim.core.gtu.behavioralcharacteristics;
2
3 import java.io.Serializable;
4
5 import org.djunits.unit.DimensionlessUnit;
6 import org.djunits.value.vdouble.scalar.Dimensionless;
7
8 import nl.tudelft.simulation.language.Throw;
9
10
11
12
13
14
15
16
17
18
19
20 public class ParameterTypeBoolean extends AbstractParameterType<Dimensionless> implements Serializable
21 {
22
23 private static final long serialVersionUID = 20160400L;
24
25
26
27
28
29
30 public ParameterTypeBoolean(final String id, final String description)
31 {
32 this(id, description, false, false);
33 }
34
35
36
37
38
39
40
41 public ParameterTypeBoolean(final String id, final String description, final boolean defaultValue)
42 {
43 this(id, description, defaultValue, true);
44 }
45
46
47
48
49
50
51
52
53 public ParameterTypeBoolean(final String id, final String description, final boolean defaultValue,
54 final boolean hasDefaultValue)
55 {
56 super(id, description, Dimensionless.class,
57 hasDefaultValue ? new Dimensionless(defaultValue ? 1.0 : 0.0, DimensionlessUnit.SI) : null, null,
58 hasDefaultValue);
59 }
60
61
62 public final Boolean getDefaultValue() throws ParameterException
63 {
64 Throw.when(null == this.defaultValue, ParameterException.class, "No default value was set for '%s'.", getId());
65 return super.defaultValue.si != 0.0;
66 }
67
68
69 public final String printValue(final BehavioralCharacteristics behavioralCharacteristics) throws ParameterException
70 {
71 return Boolean.toString(behavioralCharacteristics.getParameter(this));
72 }
73
74
75 @SuppressWarnings("checkstyle:designforextension")
76 @Override
77 public String toString()
78 {
79 return "ParameterTypeBoolean [id=" + getId() + ", description=" + getDescription() + "]";
80 }
81
82 }