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