1 package org.opentrafficsim.simulationengine.properties;
2
3
4
5
6
7
8
9
10
11
12
13 public class IntegerProperty extends AbstractProperty<Integer>
14 {
15
16 private Integer value;
17
18
19 private String shortName;
20
21
22 private String description;
23
24
25 private String format;
26
27
28 private Integer minimumValue;
29
30
31 private Integer 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 IntegerProperty(final String shortName, final String description, final Integer initialValue,
49 final Integer minimumValue, final Integer 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 Integer getValue()
65 {
66 return this.value;
67 }
68
69
70
71
72
73 public final Integer getMinimumValue()
74 {
75 return this.minimumValue;
76 }
77
78
79
80
81
82 public final Integer getMaximumValue()
83 {
84 return this.maximumValue;
85 }
86
87
88 @Override
89 public final String getShortName()
90 {
91 return this.shortName;
92 }
93
94
95 @Override
96 public final String getDescription()
97 {
98 return this.description;
99 }
100
101
102 @Override
103 public final void setValue(final Integer newValue) throws PropertyException
104 {
105 if (this.readOnly)
106 {
107 throw new PropertyException("This property is read-only");
108 }
109 if (this.minimumValue > newValue || this.maximumValue < newValue)
110 {
111 throw new PropertyException("new value " + newValue + " is out of valid range (" + this.minimumValue + ".."
112 + this.maximumValue + ")");
113 }
114 this.value = newValue;
115 }
116
117
118 @Override
119 public final boolean isReadOnly()
120 {
121 return this.readOnly;
122 }
123
124
125
126
127 public final String getFormatString()
128 {
129 return this.format;
130 }
131
132
133 @Override
134 public final String htmlStateDescription()
135 {
136 return getShortName() + ": " + String.format(getFormatString(), getValue());
137 }
138
139
140 @Override
141 public final AbstractProperty<Integer> deepCopy()
142 {
143 return new IntegerProperty(this.shortName, this.description, this.value, this.maximumValue, this.maximumValue,
144 this.format, this.readOnly, getDisplayPriority());
145 }
146
147 }