1 package org.djunits.value.vfloat.vector.base;
2
3 import org.djunits.unit.SIUnit;
4 import org.djunits.unit.Unit;
5 import org.djunits.unit.util.UnitException;
6 import org.djunits.value.Relative;
7 import org.djunits.value.ValueRuntimeException;
8 import org.djunits.value.base.Vector;
9 import org.djunits.value.vfloat.function.FloatMathFunctions;
10 import org.djunits.value.vfloat.scalar.base.AbstractFloatScalarRel;
11 import org.djunits.value.vfloat.vector.FloatSIVector;
12 import org.djunits.value.vfloat.vector.data.FloatVectorData;
13
14
15
16
17
18
19
20
21
22
23
24
25 public abstract class AbstractFloatVectorRel<U extends Unit<U>, S extends AbstractFloatScalarRel<U, S>,
26 RV extends AbstractFloatVectorRel<U, S, RV>> extends AbstractFloatVector<U, S, RV> implements Vector.Rel<U, S, RV>
27 {
28
29 private static final long serialVersionUID = 20190908L;
30
31
32
33
34
35
36 protected AbstractFloatVectorRel(final FloatVectorData data, final U unit)
37 {
38 super(data.copy(), unit);
39 }
40
41
42
43
44
45 public final S zSum()
46 {
47 return instantiateScalarSI(getData().zSum(), getDisplayUnit());
48 }
49
50
51 @Override
52 public final RV plus(final RV rel) throws ValueRuntimeException
53 {
54 return instantiateVector(this.getData().plus(rel.getData()), getDisplayUnit());
55 }
56
57
58 @Override
59 public final RV minus(final RV rel) throws ValueRuntimeException
60 {
61 return instantiateVector(this.getData().minus(rel.getData()), getDisplayUnit());
62 }
63
64
65
66
67
68
69
70 @SuppressWarnings("unchecked")
71 public RV incrementBy(final S increment)
72 {
73 checkCopyOnWrite();
74 assign(FloatMathFunctions.INC(increment.si));
75 return (RV) this;
76 }
77
78
79
80
81
82
83
84
85 @SuppressWarnings("unchecked")
86 public RV incrementBy(final RV increment)
87 {
88 checkCopyOnWrite();
89 getData().incrementBy(increment.getData());
90 return (RV) this;
91 }
92
93
94
95
96
97
98
99 @SuppressWarnings("unchecked")
100 public RV decrementBy(final S decrement)
101 {
102 checkCopyOnWrite();
103 assign(FloatMathFunctions.DEC(decrement.si));
104 return (RV) this;
105 }
106
107
108
109
110
111
112
113
114 @SuppressWarnings("unchecked")
115 public RV decrementBy(final RV decrement)
116 {
117 checkCopyOnWrite();
118 getData().decrementBy(decrement.getData());
119 return (RV) this;
120 }
121
122
123 @Override
124 public final RV multiplyBy(final double multiplier)
125 {
126 return assign(FloatMathFunctions.MULT((float) multiplier));
127 }
128
129
130 @Override
131 public RV divideBy(final double divisor)
132 {
133 return assign(FloatMathFunctions.DIV((float) divisor));
134 }
135
136
137
138
139
140
141
142
143
144
145
146
147
148 public final <UT extends Unit<UT>, ST extends AbstractFloatScalarRel<UT, ST>,
149 VT extends AbstractFloatVectorRel<UT, ST, VT> & Relative<UT, VT>> FloatSIVector times(final VT rel)
150 throws ValueRuntimeException, UnitException
151 {
152 return new FloatSIVector(this.getData().times(rel.getData()), SIUnit.of(
153 getDisplayUnit().getQuantity().getSiDimensions().plus(rel.getDisplayUnit().getQuantity().getSiDimensions())));
154 }
155
156
157
158
159
160
161
162
163
164
165
166
167
168 public final <UT extends Unit<UT>, ST extends AbstractFloatScalarRel<UT, ST>,
169 VT extends AbstractFloatVectorRel<UT, ST, VT> & Relative<UT, VT>> FloatSIVector divide(final VT rel)
170 throws ValueRuntimeException, UnitException
171 {
172 return new FloatSIVector(this.getData().divide(rel.getData()), SIUnit.of(
173 getDisplayUnit().getQuantity().getSiDimensions().minus(rel.getDisplayUnit().getQuantity().getSiDimensions())));
174 }
175
176
177 @Override
178 public RV times(final double multiplier)
179 {
180 return clone().mutable().assign(FloatMathFunctions.MULT((float) multiplier)).immutable();
181 }
182
183
184 @Override
185 public RV divide(final double divisor)
186 {
187 return clone().mutable().assign(FloatMathFunctions.DIV((float) divisor)).immutable();
188 }
189
190
191 @Override
192 public RV times(final float multiplier)
193 {
194 return times((double) multiplier);
195 }
196
197
198 @Override
199 public RV divide(final float divisor)
200 {
201 return divide((double) divisor);
202 }
203
204 }