View Javadoc
1   package org.djunits.value.vdouble.vector;
2   
3   import java.util.List;
4   import java.util.Map;
5   
6   import org.djunits.unit.LengthUnit;
7   import org.djunits.unit.PositionUnit;
8   import org.djunits.unit.scale.IdentityScale;
9   import org.djunits.value.storage.StorageType;
10  import org.djunits.value.vdouble.scalar.Length;
11  import org.djunits.value.vdouble.scalar.Position;
12  import org.djunits.value.vdouble.vector.base.DoubleVectorRelWithAbs;
13  import org.djunits.value.vdouble.vector.data.DoubleVectorData;
14  
15  import jakarta.annotation.Generated;
16  
17  /**
18   * Double LengthVector, a vector of values with a LengthUnit.
19   * <p>
20   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
21   * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
22   * </p>
23   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
24   * @author <a href="https://www.tudelft.nl/staff/p.knoppers/">Peter Knoppers</a>
25   */
26  @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2023-07-23T14:06:38.224104100Z")
27  public class LengthVector
28          extends DoubleVectorRelWithAbs<PositionUnit, Position, PositionVector, LengthUnit, Length, LengthVector>
29  {
30      /** */
31      private static final long serialVersionUID = 20190905L;
32  
33      /**
34       * Construct an LengthVector from an internal data object.
35       * @param data DoubleVectorData; the internal data object for the vector
36       * @param displayUnit LengthUnit; the display unit of the vector data
37       */
38      public LengthVector(final DoubleVectorData data, final LengthUnit displayUnit)
39      {
40          super(data, displayUnit);
41      }
42  
43      /* CONSTRUCTORS WITH double[] */
44  
45      /**
46       * Construct an LengthVector from a double[] object. The double values are expressed in the displayUnit, and will be printed
47       * using the displayUnit.
48       * @param data double[]; the data for the vector, expressed in the displayUnit
49       * @param displayUnit LengthUnit; the unit of the values in the data array, and display unit when printing
50       * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Vector
51       */
52      public LengthVector(final double[] data, final LengthUnit displayUnit, final StorageType storageType)
53      {
54          this(DoubleVectorData.instantiate(data, displayUnit.getScale(), storageType), displayUnit);
55      }
56  
57      /**
58       * Construct an LengthVector from a double[] object. The double values are expressed in the displayUnit. Assume that the
59       * StorageType is DENSE since we offer the data as an array.
60       * @param data double[]; the data for the vector
61       * @param displayUnit LengthUnit; the unit of the values in the data array, and display unit when printing
62       */
63      public LengthVector(final double[] data, final LengthUnit displayUnit)
64      {
65          this(data, displayUnit, StorageType.DENSE);
66      }
67  
68      /**
69       * Construct an LengthVector from a double[] object with SI-unit values.
70       * @param data double[]; the data for the vector, in SI units
71       * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Vector
72       */
73      public LengthVector(final double[] data, final StorageType storageType)
74      {
75          this(data, LengthUnit.SI, storageType);
76      }
77  
78      /**
79       * Construct an LengthVector from a double[] object with SI-unit values. Assume that the StorageType is DENSE since we offer
80       * the data as an array.
81       * @param data double[]; the data for the vector, in SI units
82       */
83      public LengthVector(final double[] data)
84      {
85          this(data, StorageType.DENSE);
86      }
87  
88      /* CONSTRUCTORS WITH Length[] */
89  
90      /**
91       * Construct an LengthVector from an array of Length objects. The Length values are each expressed in their own unit, but
92       * will be internally stored as SI values, all expressed in the displayUnit when printing.
93       * @param data Length[]; the data for the vector
94       * @param displayUnit LengthUnit; the display unit of the values when printing
95       * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Vector
96       */
97      public LengthVector(final Length[] data, final LengthUnit displayUnit, final StorageType storageType)
98      {
99          this(DoubleVectorData.instantiate(data, storageType), displayUnit);
100     }
101 
102     /**
103      * Construct an LengthVector from an array of Length objects. The Length values are each expressed in their own unit, but
104      * will be internally stored as SI values, all expressed in the displayUnit when printing. Assume that the StorageType is
105      * DENSE since we offer the data as an array.
106      * @param data Length[]; the data for the vector
107      * @param displayUnit LengthUnit; the display unit of the values when printing
108      */
109     public LengthVector(final Length[] data, final LengthUnit displayUnit)
110     {
111         this(data, displayUnit, StorageType.DENSE);
112     }
113 
114     /**
115      * Construct an LengthVector from an array of Length objects. The Length values are each expressed in their own unit, but
116      * will be internally stored as SI values, and expressed using SI units when printing. since we offer the data as an array.
117      * @param data Length[]; the data for the vector
118      * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Vector
119      */
120     public LengthVector(final Length[] data, final StorageType storageType)
121     {
122         this(data, LengthUnit.SI, storageType);
123     }
124 
125     /**
126      * Construct an LengthVector from an array of Length objects. The Length values are each expressed in their own unit, but
127      * will be internally stored as SI values, and expressed using SI units when printing. Assume that the StorageType is DENSE
128      * since we offer the data as an array.
129      * @param data Length[]; the data for the vector
130      */
131     public LengthVector(final Length[] data)
132     {
133         this(data, StorageType.DENSE);
134     }
135 
136     /* CONSTRUCTORS WITH List<Double> or List<Length> */
137 
138     /**
139      * Construct an LengthVector from a list of Number objects or a list of Length objects. Note that the displayUnit has a
140      * different meaning depending on whether the list contains Number objects (e.g., Double objects) or Length objects. In case
141      * the list contains Number objects, the displayUnit indicates the unit in which the values in the list are expressed, as
142      * well as the unit in which they will be printed. In case the list contains Length objects, each Length has its own unit,
143      * and the displayUnit is just used for printing. The values but will always be internally stored as SI values or base
144      * values, and expressed using the display unit or base unit when printing.
145      * @param data List&lt;Double&gt; or List&lt;Length&gt;; the data for the vector
146      * @param displayUnit LengthUnit; the display unit of the vector data, and the unit of the data points when the data is
147      *            expressed as List&lt;Double&gt; or List&lt;Number&gt; in general
148      * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Vector
149      */
150     public LengthVector(final List<? extends Number> data, final LengthUnit displayUnit, final StorageType storageType)
151     {
152         this(data.size() == 0 ? DoubleVectorData.instantiate(new double[] {}, IdentityScale.SCALE, storageType)
153                 : data.get(0) instanceof Length ? DoubleVectorData.instantiate(data, IdentityScale.SCALE, storageType)
154                         : DoubleVectorData.instantiate(data, displayUnit.getScale(), storageType),
155                 displayUnit);
156     }
157 
158     /**
159      * Construct an LengthVector from a list of Number objects or a list of Length objects. Note that the displayUnit has a
160      * different meaning depending on whether the list contains Number objects (e.g., Double objects) or Length objects. In case
161      * the list contains Number objects, the displayUnit indicates the unit in which the values in the list are expressed, as
162      * well as the unit in which they will be printed. In case the list contains Length objects, each Length has its own unit,
163      * and the displayUnit is just used for printing. The values but will always be internally stored as SI values or base
164      * values, and expressed using the display unit or base unit when printing. Assume the storage type is DENSE since we offer
165      * the data as a List.
166      * @param data List&lt;Double&gt; or List&lt;Length&gt;; the data for the vector
167      * @param displayUnit LengthUnit; the display unit of the vector data, and the unit of the data points when the data is
168      *            expressed as List&lt;Double&gt; or List&lt;Number&gt; in general
169      */
170     public LengthVector(final List<? extends Number> data, final LengthUnit displayUnit)
171     {
172         this(data, displayUnit, StorageType.DENSE);
173     }
174 
175     /**
176      * Construct an LengthVector from a list of Number objects or a list of Length objects. When data contains numbers such as
177      * Double, assume that they are expressed using SI units. When the data consists of Length objects, they each have their own
178      * unit, but will be printed using SI units or base units. The values but will always be internally stored as SI values or
179      * base values, and expressed using the display unit or base unit when printing.
180      * @param data List&lt;Double&gt; or List&lt;Length&gt;; the data for the vector
181      * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Vector
182      */
183     public LengthVector(final List<? extends Number> data, final StorageType storageType)
184     {
185         this(data, LengthUnit.SI, storageType);
186     }
187 
188     /**
189      * Construct an LengthVector from a list of Number objects or a list of Length objects. When data contains numbers such as
190      * Double, assume that they are expressed using SI units. When the data consists of Length objects, they each have their own
191      * unit, but will be printed using SI units or base units. The values but will always be internally stored as SI values or
192      * base values, and expressed using the display unit or base unit when printing. Assume the storage type is DENSE since we
193      * offer the data as a List.
194      * @param data List&lt;Double&gt; or List&lt;Length&gt;; the data for the vector
195      */
196     public LengthVector(final List<? extends Number> data)
197     {
198         this(data, StorageType.DENSE);
199     }
200 
201     /* CONSTRUCTORS WITH Map<Integer, Double> or Map<Integer, Length> */
202 
203     /**
204      * Construct an LengthVector from a (sparse) map of index values to Number objects or a (sparse) map of index values to of
205      * Length objects. Using index values is particularly useful for sparse vectors. The size parameter indicates the size of
206      * the vector, since the largest index does not have to be part of the map. Note that the displayUnit has a different
207      * meaning depending on whether the map contains Number objects (e.g., Double objects) or Length objects. In case the map
208      * contains Number objects, the displayUnit indicates the unit in which the values in the map are expressed, as well as the
209      * unit in which they will be printed. In case the map contains Length objects, each Length has its own unit, and the
210      * displayUnit is just used for printing. The values but will always be internally stored as SI values or base values, and
211      * expressed using the display unit or base unit when printing.
212      * @param data Map&lt;Integer, Double&gt; or Map&lt;Integer, Length&gt;; the data for the vector
213      * @param size int; the size off the vector, i.e., the highest index
214      * @param displayUnit LengthUnit; the display unit of the vector data, and the unit of the data points when the data is
215      *            expressed as List&lt;Double&gt; or List&lt;Number&gt; in general
216      * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Vector
217      */
218     public LengthVector(final Map<Integer, ? extends Number> data, final int size, final LengthUnit displayUnit,
219             final StorageType storageType)
220     {
221         this(data.size() == 0 ? DoubleVectorData.instantiate(data, size, IdentityScale.SCALE, storageType)
222                 : data.values().iterator().next() instanceof Length
223                         ? DoubleVectorData.instantiate(data, size, IdentityScale.SCALE, storageType)
224                         : DoubleVectorData.instantiate(data, size, displayUnit.getScale(), storageType),
225                 displayUnit);
226     }
227 
228     /**
229      * Construct an LengthVector from a (sparse) map of index values to Number objects or a (sparse) map of index values to of
230      * Length objects. Using index values is particularly useful for sparse vectors. The size parameter indicates the size of
231      * the vector, since the largest index does not have to be part of the map. Note that the displayUnit has a different
232      * meaning depending on whether the map contains Number objects (e.g., Double objects) or Length objects. In case the map
233      * contains Number objects, the displayUnit indicates the unit in which the values in the map are expressed, as well as the
234      * unit in which they will be printed. In case the map contains Length objects, each Length has its own unit, and the
235      * displayUnit is just used for printing. The values but will always be internally stored as SI values or base values, and
236      * expressed using the display unit or base unit when printing. Assume the storage type is SPARSE since we offer the data as
237      * a Map.
238      * @param data Map&lt;Integer, Double&gt; or Map&lt;Integer, Length&gt;; the data for the vector
239      * @param size int; the size off the vector, i.e., the highest index
240      * @param displayUnit LengthUnit; the display unit of the vector data, and the unit of the data points when the data is
241      *            expressed as List&lt;Double&gt; or List&lt;Number&gt; in general
242      */
243     public LengthVector(final Map<Integer, ? extends Number> data, final int size, final LengthUnit displayUnit)
244     {
245         this(data, size, displayUnit, StorageType.SPARSE);
246     }
247 
248     /**
249      * Construct an LengthVector from a (sparse) map of index values to Number objects or a (sparse) map of index values to of
250      * Length objects. Using index values is particularly useful for sparse vectors. The size parameter indicates the size of
251      * the vector, since the largest index does not have to be part of the map. When data contains numbers such as Double,
252      * assume that they are expressed using SI units. When the data consists of Length objects, they each have their own unit,
253      * but will be printed using SI units or base units. The values but will always be internally stored as SI values or base
254      * values, and expressed using the display unit or base unit when printing.
255      * @param data Map&lt;Integer, Double&gt; or Map&lt;Integer, Length&gt;; the data for the vector
256      * @param size int; the size off the vector, i.e., the highest index
257      * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Vector
258      */
259     public LengthVector(final Map<Integer, ? extends Number> data, final int size, final StorageType storageType)
260     {
261         this(data, size, LengthUnit.SI, storageType);
262     }
263 
264     /**
265      * Construct an LengthVector from a (sparse) map of index values to Number objects or a (sparse) map of index values to of
266      * Length objects. Using index values is particularly useful for sparse vectors. The size parameter indicates the size of
267      * the vector, since the largest index does not have to be part of the map. When data contains numbers such as Double,
268      * assume that they are expressed using SI units. When the data consists of Length objects, they each have their own unit,
269      * but will be printed using SI units or base units. The values but will always be internally stored as SI values or base
270      * values, and expressed using the display unit or base unit when printing. Assume the storage type is SPARSE since we offer
271      * the data as a Map.
272      * @param data Map&lt;Integer, Double&gt; or Map&lt;Integer, Length&gt;; the data for the vector
273      * @param size int; the size off the vector, i.e., the highest index
274      */
275     public LengthVector(final Map<Integer, ? extends Number> data, final int size)
276     {
277         this(data, size, StorageType.SPARSE);
278     }
279 
280     /* ****************************** Other methods ****************************** */
281 
282     @Override
283     public Class<Length> getScalarClass()
284     {
285         return Length.class;
286     }
287 
288     @Override
289     public LengthVector instantiateVector(final DoubleVectorData dvd, final LengthUnit displayUnit)
290     {
291         return new LengthVector(dvd, displayUnit);
292     }
293 
294     @Override
295     public Length instantiateScalarSI(final double valueSI, final LengthUnit displayUnit)
296     {
297         Length result = Length.instantiateSI(valueSI);
298         result.setDisplayUnit(displayUnit);
299         return result;
300     }
301 
302     @Override
303     public PositionVector instantiateVectorAbs(final DoubleVectorData dvd, final PositionUnit displayUnit)
304     {
305         return new PositionVector(dvd, displayUnit);
306     }
307 
308     @Override
309     public Position instantiateScalarAbsSI(final double valueSI, final PositionUnit displayUnit)
310     {
311         Position result = Position.instantiateSI(valueSI);
312         result.setDisplayUnit(displayUnit);
313         return result;
314     }
315 
316 }