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