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