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 ParameterTypeInteger extends AbstractParameterType<Dimensionless> implements Serializable
21 {
22
23 private static final long serialVersionUID = 20160400L;
24
25
26
27
28
29
30 public ParameterTypeInteger(final String id, final String description)
31 {
32 this(id, description, 0, null, false);
33 }
34
35
36
37
38
39
40
41 public ParameterTypeInteger(final String id, final String description, final int defaultValue)
42 {
43 this(id, description, defaultValue, null, true);
44 }
45
46
47
48
49
50
51
52 public ParameterTypeInteger(final String id, final String description, final Check check)
53 {
54 this(id, description, 0, check, false);
55 }
56
57
58
59
60
61
62
63
64 public ParameterTypeInteger(final String id, final String description, final int defaultValue, final Check check)
65 {
66 super(id, description, Dimensionless.class, new Dimensionless(defaultValue, DimensionlessUnit.SI), check, true);
67 }
68
69
70
71
72
73
74
75
76
77 private ParameterTypeInteger(final String id, final String description, final int defaultValue, final Check check,
78 final boolean hasDefaultValue)
79 {
80 super(id, description, Dimensionless.class,
81 hasDefaultValue ? new Dimensionless(defaultValue, DimensionlessUnit.SI) : null, check, hasDefaultValue);
82 try
83 {
84
85
86 check(defaultValue, new BehavioralCharacteristics());
87 }
88 catch (ParameterException exception)
89 {
90 throw new RuntimeException("Default value does not comply with constraints.", exception);
91 }
92 }
93
94
95 public final Integer getDefaultValue() throws ParameterException
96 {
97 Throw.when(null == this.defaultValue, ParameterException.class, "No default value was set for '%s'.", getId());
98 return (int) super.defaultValue.si;
99 }
100
101
102 public final String printValue(final BehavioralCharacteristics behavioralCharacteristics) throws ParameterException
103 {
104 return Integer.toString(behavioralCharacteristics.getParameter(this));
105 }
106
107
108
109
110
111
112
113 public void check(final int value, final BehavioralCharacteristics bc) throws ParameterException
114 {
115
116 }
117
118
119 @SuppressWarnings("checkstyle:designforextension")
120 @Override
121 public String toString()
122 {
123 return "ParameterTypeInteger [id=" + getId() + ", description=" + getDescription() + "]";
124 }
125
126 }