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