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
34
35
36
37
38
39
40
41
42
43
44 @SuppressWarnings("checkstyle:parameternumber")
45 public ContinuousProperty(final String key, final String shortName, final String description, final Double initialValue,
46 final Double minimumValue, final Double maximumValue, final String formatString, final boolean readOnly,
47 final int displayPriority)
48 {
49 super(key, displayPriority, shortName, description);
50 this.value = initialValue;
51 this.minimumValue = minimumValue;
52 this.maximumValue = maximumValue;
53 this.format = formatString;
54 setReadOnly(readOnly);
55 }
56
57
58 @Override
59 public final Double getValue()
60 {
61 return this.value;
62 }
63
64
65
66
67 public final Double getMinimumValue()
68 {
69 return this.minimumValue;
70 }
71
72
73
74
75 public final Double getMaximumValue()
76 {
77 return this.maximumValue;
78 }
79
80
81 @Override
82 public final void setValue(final Double newValue) throws PropertyException
83 {
84 if (isReadOnly())
85 {
86 throw new PropertyException("This property is read-only");
87 }
88 if (this.minimumValue > newValue || this.maximumValue < newValue)
89 {
90 throw new PropertyException("new value " + newValue + " is out of valid range (" + this.minimumValue + ".."
91 + this.maximumValue + ")");
92 }
93 this.value = newValue;
94 }
95
96
97
98
99 public final String getFormatString()
100 {
101 return this.format;
102 }
103
104
105 @Override
106 public final String htmlStateDescription()
107 {
108 return getShortName() + ": " + String.format(getFormatString(), getValue());
109 }
110
111
112 @Override
113 public final AbstractProperty<Double> deepCopy()
114 {
115 return new ContinuousProperty(getKey(), getShortName(), getDescription(), this.value, this.minimumValue,
116 this.maximumValue, this.format, isReadOnly(), getDisplayPriority());
117 }
118
119 }