1 package org.djunits.value.vfloat.vector.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.ValueRuntimeException;
7 import org.djunits.value.vfloat.function.FloatMathFunctions;
8 import org.djunits.value.vfloat.scalar.base.FloatScalarAbs;
9 import org.djunits.value.vfloat.scalar.base.FloatScalarRelWithAbs;
10 import org.djunits.value.vfloat.vector.data.FloatVectorData;
11
12 /**
13 * AbstractMutableFloatVectorRelWithAbs.java.
14 * <p>
15 * Copyright (c) 2019-2025 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
16 * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
17 * </p>
18 * @author <a href="https://www.tudelft.nl/averbraeck" target="_blank">Alexander Verbraeck</a>
19 * @param <AU> the absolute unit belonging to the relative unit
20 * @param <A> the absolute scalar type belonging to the absolute vector type
21 * @param <AV> the (immutable or mutable) absolute vector type
22 * @param <RU> the relative unit belonging to the absolute unit
23 * @param <R> the relative scalar type belonging to the relative vector type
24 * @param <RV> the relative (immutable or mutable) vector type with this unit
25 */
26 // @formatter:off
27 public abstract class FloatVectorAbs<
28 AU extends AbsoluteLinearUnit<AU, RU>,
29 A extends FloatScalarAbs<AU, A, RU, R>,
30 AV extends FloatVectorAbs<AU, A, AV, RU, R, RV>,
31 RU extends Unit<RU>,
32 R extends FloatScalarRelWithAbs<AU, A, RU, R>,
33 RV extends FloatVectorRelWithAbs<AU, A, AV, RU, R, RV>>
34 extends FloatVector<AU, A, AV>
35 implements Absolute<AU, AV, RU, RV>
36 // @formatter:on
37 {
38 /** */
39 private static final long serialVersionUID = 20190908L;
40
41 /**
42 * Construct a new Relative Mutable FloatVector.
43 * @param data an internal data object
44 * @param unit the unit
45 */
46 protected FloatVectorAbs(final FloatVectorData data, final AU unit)
47 {
48 super(data.copy(), unit);
49 }
50
51 @Override
52 public AV plus(final RV increment) throws ValueRuntimeException
53 {
54 return instantiateVector(this.getData().plus(increment.getData()), getDisplayUnit());
55 }
56
57 @Override
58 public AV minus(final RV decrement) throws ValueRuntimeException
59 {
60 return instantiateVector(this.getData().minus(decrement.getData()), getDisplayUnit());
61 }
62
63 @Override
64 public RV minus(final AV decrement) throws ValueRuntimeException
65 {
66 return instantiateVectorRel(this.getData().minus(decrement.getData()), decrement.getDisplayUnit().getRelativeUnit());
67 }
68
69 /**
70 * Decrement all values of this vector by the decrement. This only works if the vector is mutable.
71 * @param decrement the scalar by which to decrement all values
72 * @return this modified vector
73 * @throws ValueRuntimeException in case this vector is immutable
74 */
75 @SuppressWarnings("unchecked")
76 public AV decrementBy(final R decrement)
77 {
78 checkCopyOnWrite();
79 assign(FloatMathFunctions.DEC(decrement.si));
80 return (AV) this;
81 }
82
83 /**
84 * Decrement all values of this vector by the decrement on a value by value basis. This only works if this vector is
85 * mutable.
86 * @param decrement the vector that contains the values by which to decrement the corresponding values
87 * @return this modified vector
88 * @throws ValueRuntimeException in case this vector is immutable or when the sizes of the vectors differ
89 */
90 @SuppressWarnings("unchecked")
91 public AV decrementBy(final RV decrement)
92 {
93 checkCopyOnWrite();
94 getData().decrementBy(decrement.getData());
95 return (AV) this;
96 }
97
98 /**
99 * Instantiate a new relative vector of the class of this absolute vector. This can be used instead of the
100 * FloatVector.instiantiate() methods in case another vector of this absolute vector class is known. The method is faster
101 * than FloatVector.instantiate, and it will also work if the vector is user-defined.
102 * @param dvd the data used to instantiate the vector
103 * @param displayUnit the display unit of the relative vector
104 * @return a relative vector of the correct type, belonging to this absolute vector type
105 */
106 public abstract RV instantiateVectorRel(FloatVectorData dvd, RU displayUnit);
107
108 /**
109 * Instantiate a new relative scalar for the class of this absolute vector. This can be used instead of the
110 * FloatScalar.instiantiate() methods in case a vector of this class is known. The method is faster than
111 * FloatScalar.instantiate, and it will also work if the vector and/or scalar are user-defined.
112 * @param valueSI the SI value of the relative scalar
113 * @param displayUnit the unit in which the relative value will be displayed
114 * @return a relative scalar of the correct type, belonging to this absolute vector type
115 */
116 public abstract R instantiateScalarRelSI(float valueSI, RU displayUnit);
117
118 }