1 package org.opentrafficsim.simulationengine.properties;
2
3
4
5
6
7
8
9
10
11
12
13 public class ContinuousProperty extends AbstractProperty<Double>
14 {
15
16 private Double value;
17
18
19 private String shortName;
20
21
22 private String description;
23
24
25 private String format;
26
27
28 private Double minimumValue;
29
30
31 private Double maximumValue;
32
33
34 private final Boolean readOnly;
35
36
37
38
39
40
41
42
43
44
45
46
47 @SuppressWarnings("checkstyle:parameternumber")
48 public ContinuousProperty(final String shortName, final String description, final Double initialValue,
49 final Double minimumValue, final Double maximumValue, final String formatString, final boolean readOnly,
50 final int displayPriority)
51 {
52 super(displayPriority);
53 this.shortName = shortName;
54 this.description = description;
55 this.value = initialValue;
56 this.minimumValue = minimumValue;
57 this.maximumValue = maximumValue;
58 this.format = formatString;
59 this.readOnly = readOnly;
60 }
61
62
63 @Override
64 public final Double getValue()
65 {
66 return this.value;
67 }
68
69
70
71
72 public final Double getMinimumValue()
73 {
74 return this.minimumValue;
75 }
76
77
78
79
80 public final Double getMaximumValue()
81 {
82 return this.maximumValue;
83 }
84
85
86 @Override
87 public final String getShortName()
88 {
89 return this.shortName;
90 }
91
92
93 @Override
94 public final String getDescription()
95 {
96 return this.description;
97 }
98
99
100 @Override
101 public final void setValue(final Double newValue) throws PropertyException
102 {
103 if (this.readOnly)
104 {
105 throw new PropertyException("This property is read-only");
106 }
107 if (this.minimumValue > newValue || this.maximumValue < newValue)
108 {
109 throw new PropertyException("new value " + newValue + " is out of valid range (" + this.minimumValue + ".."
110 + this.maximumValue + ")");
111 }
112 this.value = newValue;
113 }
114
115
116 @Override
117 public final boolean isReadOnly()
118 {
119 return false;
120 }
121
122
123
124
125 public final String getFormatString()
126 {
127 return this.format;
128 }
129
130
131 @Override
132 public final String htmlStateDescription()
133 {
134 return getShortName() + ": " + String.format(getFormatString(), getValue());
135 }
136
137
138 @Override
139 public final AbstractProperty<Double> deepCopy()
140 {
141 return new ContinuousProperty(this.shortName, this.description, this.value, this.minimumValue,
142 this.maximumValue, this.format, this.readOnly, getDisplayPriority());
143 }
144
145 }