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