1 package org.djunits.value.vdouble.scalar.base;
2
3 import org.djunits.unit.AbsoluteLinearUnit;
4 import org.djunits.unit.Unit;
5 import org.djunits.value.Absolute;
6 import org.djunits.value.util.ValueUtil;
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 public abstract class DoubleScalarAbs<AU extends AbsoluteLinearUnit<AU, RU>,
23 A extends DoubleScalarAbs<AU, A, RU, R>, RU extends Unit<RU>,
24 R extends DoubleScalarRelWithAbs<AU, A, RU, R>> extends DoubleScalar<AU, A>
25 implements Absolute<AU, A, RU, R>
26 {
27
28 private static final long serialVersionUID = 20150626L;
29
30
31
32
33
34
35 public DoubleScalarAbs(final double value, final AU unit)
36 {
37 super(unit, unit.isBaseSIUnit() ? value : ValueUtil.expressAsSIUnit(value, unit));
38 }
39
40
41
42
43
44 public DoubleScalarAbs(final A value)
45 {
46 super(value.getDisplayUnit(), value.getSI());
47 }
48
49
50
51
52
53
54
55 public abstract R instantiateRel(double value, RU unit);
56
57
58
59
60
61
62
63 public abstract A instantiateAbs(double value, AU unit);
64
65 @Override
66 public final A plus(final R increment)
67 {
68 AU targetUnit = getDisplayUnit();
69 return instantiateAbs(getInUnit() + increment.getInUnit(targetUnit.getRelativeUnit()), targetUnit);
70 }
71
72 @Override
73 public final A minus(final R decrement)
74 {
75 AU targetUnit = getDisplayUnit();
76 return instantiateAbs(getInUnit() - decrement.getInUnit(targetUnit.getRelativeUnit()), targetUnit);
77 }
78
79 @Override
80 public final R minus(final A decrement)
81 {
82 RU targetUnit = getDisplayUnit().getRelativeUnit();
83 return instantiateRel(getInUnit() - decrement.getInUnit(getDisplayUnit()), targetUnit);
84 }
85
86
87
88
89
90 @Override
91 public A abs()
92 {
93 return instantiateAbs(Math.abs(getInUnit()), getDisplayUnit());
94 }
95
96 @Override
97 public A ceil()
98 {
99 return instantiateAbs(Math.ceil(getInUnit()), getDisplayUnit());
100 }
101
102 @Override
103 public A floor()
104 {
105 return instantiateAbs(Math.floor(getInUnit()), getDisplayUnit());
106 }
107
108 @Override
109 public A neg()
110 {
111 return instantiateAbs(-getInUnit(), getDisplayUnit());
112 }
113
114 @Override
115 public A rint()
116 {
117 return instantiateAbs(Math.rint(getInUnit()), getDisplayUnit());
118 }
119
120 }