View Javadoc
1   package org.djunits.value.vdouble.matrix;
2   
3   import java.util.Collection;
4   
5   import org.djunits.unit.LengthUnit;
6   import org.djunits.unit.PositionUnit;
7   import org.djunits.value.storage.StorageType;
8   import org.djunits.value.vdouble.matrix.base.DoubleMatrixRelWithAbs;
9   import org.djunits.value.vdouble.matrix.base.DoubleSparseValue;
10  import org.djunits.value.vdouble.matrix.data.DoubleMatrixData;
11  import org.djunits.value.vdouble.scalar.Length;
12  import org.djunits.value.vdouble.scalar.Position;
13  import org.djunits.value.vdouble.vector.LengthVector;
14  import org.djunits.value.vdouble.vector.PositionVector;
15  import org.djunits.value.vdouble.vector.data.DoubleVectorData;
16  
17  import jakarta.annotation.Generated;
18  
19  /**
20   * Immutable Length Matrix.
21   * <p>
22   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
23   * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
24   * </p>
25   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
26   * @author <a href="https://www.tudelft.nl/staff/p.knoppers/">Peter Knoppers</a>
27   */
28  @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2023-07-23T14:06:38.224104100Z")
29  public class LengthMatrix extends DoubleMatrixRelWithAbs<PositionUnit, Position, PositionVector, PositionMatrix, LengthUnit,
30          Length, LengthVector, LengthMatrix>
31  {
32      /** */
33      private static final long serialVersionUID = 20151006L;
34  
35      /**
36       * Construct a LengthMatrix from an internal data object.
37       * @param data DoubleMatrixData; the internal data object for the matrix
38       * @param displayUnit LengthUnit; the display unit of the matrix data
39       */
40      public LengthMatrix(final DoubleMatrixData data, final LengthUnit displayUnit)
41      {
42          super(data, displayUnit);
43      }
44  
45      /* CONSTRUCTORS WITH double[][] */
46  
47      /**
48       * Construct a LengthMatrix from a double[][] object. The double values are expressed in the displayUnit, and will be
49       * printed using the displayUnit.
50       * @param data double[][]; the data for the matrix, expressed in the displayUnit
51       * @param displayUnit LengthUnit; the unit of the values in the data array, and display unit when printing
52       * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Matrix
53       */
54      public LengthMatrix(final double[][] data, final LengthUnit displayUnit, final StorageType storageType)
55      {
56          this(DoubleMatrixData.instantiate(data, displayUnit.getScale(), storageType), displayUnit);
57      }
58  
59      /**
60       * Construct a LengthMatrix from a double[][] object. The double values are expressed in the displayUnit. Assume that the
61       * StorageType is DENSE since we offer the data as an array of an array.
62       * @param data double[][]; the data for the matrix
63       * @param displayUnit LengthUnit; the unit of the values in the data array, and display unit when printing
64       */
65      public LengthMatrix(final double[][] data, final LengthUnit displayUnit)
66      {
67          this(data, displayUnit, StorageType.DENSE);
68      }
69  
70      /**
71       * Construct a LengthMatrix from a double[][] object with SI-unit values.
72       * @param data double[][]; the data for the matrix, in SI units
73       * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Matrix
74       */
75      public LengthMatrix(final double[][] data, final StorageType storageType)
76      {
77          this(data, LengthUnit.SI, storageType);
78      }
79  
80      /**
81       * Construct a LengthMatrix from a double[][] object with SI-unit values. Assume that the StorageType is DENSE since we
82       * offer the data as an array of an array.
83       * @param data double[][]; the data for the matrix, in SI units
84       */
85      public LengthMatrix(final double[][] data)
86      {
87          this(data, StorageType.DENSE);
88      }
89  
90      /* CONSTRUCTORS WITH Length[][] */
91  
92      /**
93       * Construct a LengthMatrix from an array of an array of Length objects. The Length values are each expressed in their own
94       * unit, but will be internally stored as SI values, all expressed in the displayUnit when printing.
95       * @param data Length[][]; the data for the matrix
96       * @param displayUnit LengthUnit; the display unit of the values when printing
97       * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Matrix
98       */
99      public LengthMatrix(final Length[][] data, final LengthUnit displayUnit, final StorageType storageType)
100     {
101         this(DoubleMatrixData.instantiate(data, storageType), displayUnit);
102     }
103 
104     /**
105      * Construct a LengthMatrix from an array of an array of Length objects. The Length values are each expressed in their own
106      * unit, but will be internally stored as SI values, all expressed in the displayUnit when printing. Assume that the
107      * StorageType is DENSE since we offer the data as an array of an array.
108      * @param data Length[][]; the data for the matrix
109      * @param displayUnit LengthUnit; the display unit of the values when printing
110      */
111     public LengthMatrix(final Length[][] data, final LengthUnit displayUnit)
112     {
113         this(data, displayUnit, StorageType.DENSE);
114     }
115 
116     /**
117      * Construct a LengthMatrix from an array of an array of Length objects. The Length values are each expressed in their own
118      * unit, but will be internally stored as SI values, and expressed using SI units when printing. since we offer the data as
119      * an array of an array.
120      * @param data Length[][]; the data for the matrix
121      * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Matrix
122      */
123     public LengthMatrix(final Length[][] data, final StorageType storageType)
124     {
125         this(data, LengthUnit.SI, storageType);
126     }
127 
128     /**
129      * Construct a LengthMatrix from an array of an array of Length objects. The Length values are each expressed in their own
130      * unit, but will be internally stored as SI values, and expressed using SI units when printing. Assume that the StorageType
131      * is DENSE since we offer the data as an array of an array.
132      * @param data Length[][]; the data for the matrix
133      */
134     public LengthMatrix(final Length[][] data)
135     {
136         this(data, StorageType.DENSE);
137     }
138 
139     /* CONSTRUCTORS WITH Collection<DoubleSparseValue> */
140 
141     /**
142      * Construct a LengthMatrix from a (sparse) collection of DoubleSparseValue objects. The displayUnit indicates the unit in
143      * which the values in the collection are expressed, as well as the unit in which they will be printed.
144      * @param data Collection&lt;DoubleSparseValue&gt;; the data for the matrix
145      * @param displayUnit LengthUnit; the display unit of the matrix data, and the unit of the data points
146      * @param rows int; the number of rows of the matrix
147      * @param cols int; the number of columns of the matrix
148      * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Matrix
149      */
150     public LengthMatrix(final Collection<DoubleSparseValue<LengthUnit, Length>> data, final LengthUnit displayUnit,
151             final int rows, final int cols, final StorageType storageType)
152     {
153         this(DoubleMatrixData.instantiate(data, rows, cols, storageType), displayUnit);
154     }
155 
156     /**
157      * Construct a LengthMatrix from a (sparse) collection of DoubleSparseValue objects. The displayUnit indicates the unit in
158      * which the values in the collection are expressed, as well as the unit in which they will be printed. Assume the storage
159      * type is SPARSE, since we offer the data as a collection.
160      * @param data Collection&lt;DoubleSparseValue&gt;; the data for the matrix
161      * @param displayUnit LengthUnit; the display unit of the matrix data, and the unit of the data points
162      * @param rows int; the number of rows of the matrix
163      * @param cols int; the number of columns of the matrix
164      */
165     public LengthMatrix(final Collection<DoubleSparseValue<LengthUnit, Length>> data, final LengthUnit displayUnit,
166             final int rows, final int cols)
167     {
168         this(data, displayUnit, rows, cols, StorageType.SPARSE);
169     }
170 
171     /**
172      * Construct a LengthMatrix from a (sparse) collection of DoubleSparseValue objects. The displayUnit indicates the unit in
173      * which the values in the collection are expressed, as well as the unit in which they will be printed. Use the SI unit or
174      * base unit as the displayUnit.
175      * @param data Collection&lt;DoubleSparseValue&gt;; the data for the matrix
176      * @param rows int; the number of rows of the matrix
177      * @param cols int; the number of columns of the matrix
178      * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Matrix
179      */
180     public LengthMatrix(final Collection<DoubleSparseValue<LengthUnit, Length>> data, final int rows, final int cols,
181             final StorageType storageType)
182     {
183         this(data, LengthUnit.SI, rows, cols, storageType);
184     }
185 
186     /**
187      * Construct a LengthMatrix from a (sparse) collection of DoubleSparseValue objects. The displayUnit indicates the unit in
188      * which the values in the collection are expressed, as well as the unit in which they will be printed. Use the SI unit or
189      * base unit as the displayUnit. Assume the storage type is SPARSE, since we offer the data as a collection.
190      * @param data Collection&lt;DoubleSparseValue&gt;; the data for the matrix
191      * @param rows int; the number of rows of the matrix
192      * @param cols int; the number of columns of the matrix
193      */
194     public LengthMatrix(final Collection<DoubleSparseValue<LengthUnit, Length>> data, final int rows, final int cols)
195     {
196         this(data, LengthUnit.SI, rows, cols, StorageType.SPARSE);
197     }
198 
199     /** {@inheritDoc} */
200     @Override
201     public Class<Length> getScalarClass()
202     {
203         return Length.class;
204     }
205 
206     /** {@inheritDoc} */
207     @Override
208     public Class<LengthVector> getVectorClass()
209     {
210         return LengthVector.class;
211     }
212 
213     /** {@inheritDoc} */
214     @Override
215     public LengthMatrix instantiateMatrix(final DoubleMatrixData dmd, final LengthUnit displayUnit)
216     {
217         return new LengthMatrix(dmd, displayUnit);
218     }
219 
220     /** {@inheritDoc} */
221     @Override
222     public LengthVector instantiateVector(final DoubleVectorData dvd, final LengthUnit displayUnit)
223     {
224         return new LengthVector(dvd, displayUnit);
225     }
226 
227     /** {@inheritDoc} */
228     @Override
229     public Length instantiateScalarSI(final double valueSI, final LengthUnit displayUnit)
230     {
231         Length result = Length.instantiateSI(valueSI);
232         result.setDisplayUnit(displayUnit);
233         return result;
234     }
235 
236     /** {@inheritDoc} */
237     @Override
238     public PositionMatrix instantiateMatrixAbs(final DoubleMatrixData dmd, final PositionUnit displayUnit)
239     {
240         return new PositionMatrix(dmd, displayUnit);
241     }
242 
243     /** {@inheritDoc} */
244     @Override
245     public PositionVector instantiateVectorAbs(final DoubleVectorData dvd, final PositionUnit displayUnit)
246     {
247         return new PositionVector(dvd, displayUnit);
248     }
249 
250     /** {@inheritDoc} */
251     @Override
252     public Position instantiateScalarAbsSI(final double valueSI, final PositionUnit displayUnit)
253     {
254         Position result = Position.instantiateSI(valueSI);
255         result.setDisplayUnit(displayUnit);
256         return result;
257     }
258 
259 }