1 package org.djunits.value.vdouble.matrix.base;
2
3 import org.djunits.unit.AbsoluteLinearUnit;
4 import org.djunits.unit.Unit;
5 import org.djunits.value.base.Matrix;
6 import org.djunits.value.vdouble.matrix.data.DoubleMatrixData;
7 import org.djunits.value.vdouble.scalar.base.AbstractDoubleScalarAbs;
8 import org.djunits.value.vdouble.scalar.base.AbstractDoubleScalarRelWithAbs;
9 import org.djunits.value.vdouble.vector.base.AbstractDoubleVectorAbs;
10 import org.djunits.value.vdouble.vector.base.AbstractDoubleVectorRelWithAbs;
11 import org.djunits.value.vdouble.vector.data.DoubleVectorData;
12
13 /**
14 * AbstractMutableDoubleMatrixRelWithAbs.java.
15 * <p>
16 * Copyright (c) 2019-2022 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
17 * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
18 * <p>
19 * @author <a href="https://www.tudelft.nl/averbraeck" target="_blank">Alexander Verbraeck</a>
20 * @param <AU> the absolute unit belonging to the relative unit
21 * @param <A> the absolute scalar type belonging to the absolute matrix type
22 * @param <AV> the absolute vector type belonging to the absolute matrix type
23 * @param <AM> the (immutable or mutable) absolute matrix type
24 * @param <RU> the relative unit belonging to the absolute unit
25 * @param <R> the relative scalar type belonging to the relative matrix type
26 * @param <RV> the relative vector type belonging to the relative matrix type
27 * @param <RM> the relative (immutable or mutable) matrix type with this unit
28 */
29 // @formatter:off
30 public abstract class AbstractDoubleMatrixRelWithAbs<
31 AU extends AbsoluteLinearUnit<AU, RU>,
32 A extends AbstractDoubleScalarAbs<AU, A, RU, R>,
33 AV extends AbstractDoubleVectorAbs<AU, A, AV, RU, R, RV>,
34 AM extends AbstractDoubleMatrixAbs<AU, A, AV, AM, RU, R, RV, RM>,
35 RU extends Unit<RU>,
36 R extends AbstractDoubleScalarRelWithAbs<AU, A, RU, R>,
37 RV extends AbstractDoubleVectorRelWithAbs<AU, A, AV, RU, R, RV>,
38 RM extends AbstractDoubleMatrixRelWithAbs<AU, A, AV, AM, RU, R, RV, RM>>
39 extends AbstractDoubleMatrixRel<RU, R, RV, RM>
40 implements Matrix.RelWithAbs<AU, A, AV, AM, RU, R, RV, RM>
41 // @formatter:on
42 {
43 /** */
44 private static final long serialVersionUID = 20190908L;
45
46 /**
47 * Construct a new Relative Mutable DoubleMatrix.
48 * @param data DoubleMatrixData; an internal data object
49 * @param unit RU; the unit
50 */
51 protected AbstractDoubleMatrixRelWithAbs(final DoubleMatrixData data, final RU unit)
52 {
53 // data will be copied in AbstractMutableDoubleMatrixRel
54 super(data, unit);
55 }
56
57 /** {@inheritDoc} */
58 @Override
59 public AM plus(final AM increment)
60 {
61 return instantiateMatrixAbs(this.getData().plus(increment.getData()), increment.getDisplayUnit().getStandardUnit());
62 }
63
64 /**
65 * Instantiate a new absolute matrix of the class of this relative matrix. This can be used instead of the
66 * DoubleMatrix.instiantiate() methods in case another matrix of this relative with absolute class is known. The method is
67 * faster than DoubleMatrix.instantiate, and it will also work if the matrix is user-defined.
68 * @param dmd DoubleMatrixData; the data used to instantiate the matrix
69 * @param displayUnit AU; the display unit of the absolute matrix
70 * @return AM; an absolute matrix of the correct type, belonging to this relative matrix type
71 */
72 public abstract AM instantiateMatrixAbs(DoubleMatrixData dmd, AU displayUnit);
73
74 /**
75 * Instantiate a new absolute vector of the class of this relative matrix. This can be used instead of the
76 * DoubleVector.instiantiate() methods in case another matrix of this relative with absolute class is known. The method is
77 * faster than DoubleVector.instantiate, and it will also work if the matrix or vector is user-defined.
78 * @param dvd DoubleVectorData; the data used to instantiate the vector
79 * @param displayUnit AU; the display unit of the absolute vector
80 * @return AV; an absolute vector of the correct type, belonging to this relative matrix type
81 */
82 public abstract AV instantiateVectorAbs(DoubleVectorData dvd, AU displayUnit);
83
84 /**
85 * Instantiate a new absolute scalar for the class of this relative matrix. This can be used instead of the
86 * DoubleScalar.instiantiate() methods in case a matrix of this class is known. The method is faster than
87 * DoubleScalar.instantiate, and it will also work if the matrix and/or scalar are user-defined.
88 * @param valueSI double; the SI value of the absolute scalar
89 * @param displayUnit AU; the unit in which the absolute value will be displayed
90 * @return A; an absolute scalar of the correct type, belonging to this relative matrix type
91 */
92 public abstract A instantiateScalarAbsSI(double valueSI, AU displayUnit);
93
94 }