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 IntegerProperty extends AbstractProperty<Integer> implements Serializable
16 {
17
18 private static final long serialVersionUID = 20150000L;
19
20
21 private Integer value;
22
23
24 private String format;
25
26
27 private Integer minimumValue;
28
29
30 private Integer maximumValue;
31
32
33
34
35
36
37
38
39
40
41
42
43
44 @SuppressWarnings("checkstyle:parameternumber")
45 public IntegerProperty(final String key, final String shortName, final String description, final Integer initialValue,
46 final Integer minimumValue, final Integer 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 Integer getValue()
60 {
61 return this.value;
62 }
63
64
65
66
67
68 public final Integer getMinimumValue()
69 {
70 return this.minimumValue;
71 }
72
73
74
75
76
77 public final Integer getMaximumValue()
78 {
79 return this.maximumValue;
80 }
81
82
83 @Override
84 public final void setValue(final Integer newValue) throws PropertyException
85 {
86 if (isReadOnly())
87 {
88 throw new PropertyException("This property is read-only");
89 }
90 if (this.minimumValue > newValue || this.maximumValue < newValue)
91 {
92 throw new PropertyException("new value " + newValue + " is out of valid range (" + this.minimumValue + ".."
93 + this.maximumValue + ")");
94 }
95 this.value = newValue;
96 }
97
98
99
100
101 public final String getFormatString()
102 {
103 return this.format;
104 }
105
106
107 @Override
108 public final String htmlStateDescription()
109 {
110 return getShortName() + ": " + String.format(getFormatString(), getValue());
111 }
112
113
114 @Override
115 public final AbstractProperty<Integer> deepCopy()
116 {
117 return new IntegerProperty(getKey(), getShortName(), getDescription(), this.value, this.maximumValue,
118 this.maximumValue, this.format, isReadOnly(), getDisplayPriority());
119 }
120
121 }