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