1 package org.djunits.value;
2
3 import java.io.Serializable;
4
5 import org.djunits.unit.Unit;
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 public abstract class Scalar<U extends Unit<U>> extends Number implements Value<U>, Serializable
22 {
23
24 private static final long serialVersionUID = 20150626L;
25
26
27 private U unit;
28
29
30
31
32
33 public Scalar(final U unit)
34 {
35 this.unit = unit;
36 }
37
38
39 @Override
40 public final U getUnit()
41 {
42 return this.unit;
43 }
44
45
46 @Override
47 public final double expressAsSIUnit(final double value)
48 {
49 if (this.unit.isBaseSIUnit())
50 {
51 return value;
52 }
53 return ValueUtil.expressAsSIUnit(value, this.unit);
54 }
55
56
57
58
59
60
61 protected final double expressAsSpecifiedUnit(final double value)
62 {
63 if (this.unit.isBaseSIUnit())
64 {
65 return value;
66 }
67 return ValueUtil.expressAsUnit(value, this.unit);
68 }
69
70
71 @Override
72 public void setDisplayUnit(final U newUnit)
73 {
74 this.unit = newUnit;
75 }
76
77
78 @Override
79 public final boolean isAbsolute()
80 {
81 return this instanceof Absolute;
82 }
83
84
85 @Override
86 public final boolean isRelative()
87 {
88 return this instanceof Relative;
89 }
90
91
92 }