1 package org.opentrafficsim.base.modelproperties;
2
3 import nl.tudelft.simulation.language.Throw;
4
5
6
7
8
9
10
11
12
13
14
15
16 public class LongProperty extends AbstractProperty<Long>
17 {
18
19
20 private static final long serialVersionUID = 20180409L;
21
22
23 private long value;
24
25
26 private long minValue;
27
28
29 private long maxValue;
30
31
32 private final String formatString;
33
34
35
36
37
38
39
40
41
42
43
44
45
46 public LongProperty(final String key, final int displayPriority, final String shortName, final String description,
47 final long initialValue, final long minValue, final long maxValue, final String formatString,
48 final boolean readOnly)
49 {
50 super(key, displayPriority, shortName, description);
51 this.value = initialValue;
52 this.minValue = minValue;
53 this.maxValue = maxValue;
54 this.formatString = formatString;
55 setReadOnly(readOnly);
56 }
57
58
59 @Override
60 public Long getValue()
61 {
62 return this.value;
63 }
64
65
66 @Override
67 public void setValue(final Long newValue) throws PropertyException
68 {
69 Throw.when(isReadOnly(), PropertyException.class, "Cannot set read-only property.");
70 Throw.when(newValue < this.minValue || newValue > this.maxValue, PropertyException.class,
71 "Value %d is not in the range %d through %d.", newValue, this.minValue, this.maxValue);
72 this.value = newValue;
73 }
74
75
76 @Override
77 public AbstractProperty<Long> deepCopy()
78 {
79 return new LongProperty(getKey(), getDisplayPriority(), getShortName(), getDescription(), this.value, this.minValue,
80 this.maxValue, this.formatString, isReadOnly());
81 }
82
83
84 @Override
85 public final String htmlStateDescription()
86 {
87 return getShortName() + ": " + String.format(this.formatString, getValue());
88 }
89
90 }