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.DimensionlessUnit;
7   import org.djunits.unit.scale.IdentityScale;
8   import org.djunits.value.function.DimensionlessFunctions;
9   import org.djunits.value.storage.StorageType;
10  import org.djunits.value.vdouble.function.DoubleMathFunctions;
11  import org.djunits.value.vdouble.scalar.Dimensionless;
12  import org.djunits.value.vdouble.vector.base.DoubleVectorRel;
13  import org.djunits.value.vdouble.vector.data.DoubleVectorData;
14  
15  import jakarta.annotation.Generated;
16  
17  /**
18   * Double DimensionlessVector, a vector of values with a DimensionlessUnit.
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 DimensionlessVector extends DoubleVectorRel<DimensionlessUnit, Dimensionless, DimensionlessVector>
28          implements DoubleMathFunctions, DimensionlessFunctions<DimensionlessUnit, DimensionlessVector>
29  {
30      /** */
31      private static final long serialVersionUID = 20190905L;
32  
33      /**
34       * Construct an DimensionlessVector from an internal data object.
35       * @param data DoubleVectorData; the internal data object for the vector
36       * @param displayUnit DimensionlessUnit; the display unit of the vector data
37       */
38      public DimensionlessVector(final DoubleVectorData data, final DimensionlessUnit displayUnit)
39      {
40          super(data, displayUnit);
41      }
42  
43      /* CONSTRUCTORS WITH double[] */
44  
45      /**
46       * Construct an DimensionlessVector from a double[] object. The double values are expressed in the displayUnit, and will be
47       * printed using the displayUnit.
48       * @param data double[]; the data for the vector, expressed in the displayUnit
49       * @param displayUnit DimensionlessUnit; 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 DimensionlessVector(final double[] data, final DimensionlessUnit displayUnit, final StorageType storageType)
53      {
54          this(DoubleVectorData.instantiate(data, displayUnit.getScale(), storageType), displayUnit);
55      }
56  
57      /**
58       * Construct an DimensionlessVector from a double[] object. The double values are expressed in the displayUnit. Assume that
59       * the StorageType is DENSE since we offer the data as an array.
60       * @param data double[]; the data for the vector
61       * @param displayUnit DimensionlessUnit; the unit of the values in the data array, and display unit when printing
62       */
63      public DimensionlessVector(final double[] data, final DimensionlessUnit displayUnit)
64      {
65          this(data, displayUnit, StorageType.DENSE);
66      }
67  
68      /**
69       * Construct an DimensionlessVector 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 DimensionlessVector(final double[] data, final StorageType storageType)
74      {
75          this(data, DimensionlessUnit.SI, storageType);
76      }
77  
78      /**
79       * Construct an DimensionlessVector from a double[] object with SI-unit values. Assume that the StorageType is DENSE since
80       * we offer the data as an array.
81       * @param data double[]; the data for the vector, in SI units
82       */
83      public DimensionlessVector(final double[] data)
84      {
85          this(data, StorageType.DENSE);
86      }
87  
88      /* CONSTRUCTORS WITH Dimensionless[] */
89  
90      /**
91       * Construct an DimensionlessVector from an array of Dimensionless objects. The Dimensionless values are each expressed in
92       * their own unit, but will be internally stored as SI values, all expressed in the displayUnit when printing.
93       * @param data Dimensionless[]; the data for the vector
94       * @param displayUnit DimensionlessUnit; 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 DimensionlessVector(final Dimensionless[] data, final DimensionlessUnit displayUnit, final StorageType storageType)
98      {
99          this(DoubleVectorData.instantiate(data, storageType), displayUnit);
100     }
101 
102     /**
103      * Construct an DimensionlessVector from an array of Dimensionless objects. The Dimensionless values are each expressed in
104      * their own unit, but will be internally stored as SI values, all expressed in the displayUnit when printing. Assume that
105      * the StorageType is DENSE since we offer the data as an array.
106      * @param data Dimensionless[]; the data for the vector
107      * @param displayUnit DimensionlessUnit; the display unit of the values when printing
108      */
109     public DimensionlessVector(final Dimensionless[] data, final DimensionlessUnit displayUnit)
110     {
111         this(data, displayUnit, StorageType.DENSE);
112     }
113 
114     /**
115      * Construct an DimensionlessVector from an array of Dimensionless objects. The Dimensionless values are each expressed in
116      * their own unit, but will be internally stored as SI values, and expressed using SI units when printing. since we offer
117      * the data as an array.
118      * @param data Dimensionless[]; the data for the vector
119      * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Vector
120      */
121     public DimensionlessVector(final Dimensionless[] data, final StorageType storageType)
122     {
123         this(data, DimensionlessUnit.SI, storageType);
124     }
125 
126     /**
127      * Construct an DimensionlessVector from an array of Dimensionless objects. The Dimensionless values are each expressed in
128      * their own unit, but will be internally stored as SI values, and expressed using SI units when printing. Assume that the
129      * StorageType is DENSE since we offer the data as an array.
130      * @param data Dimensionless[]; the data for the vector
131      */
132     public DimensionlessVector(final Dimensionless[] data)
133     {
134         this(data, StorageType.DENSE);
135     }
136 
137     /* CONSTRUCTORS WITH List<Double> or List<Dimensionless> */
138 
139     /**
140      * Construct an DimensionlessVector from a list of Number objects or a list of Dimensionless objects. Note that the
141      * displayUnit has a different meaning depending on whether the list contains Number objects (e.g., Double objects) or
142      * Dimensionless objects. In case the list contains Number objects, the displayUnit indicates the unit in which the values
143      * in the list are expressed, as well as the unit in which they will be printed. In case the list contains Dimensionless
144      * objects, each Dimensionless has its own unit, and the displayUnit is just used for printing. The values but will always
145      * be internally stored as SI values or base values, and expressed using the display unit or base unit when printing.
146      * @param data List&lt;Double&gt; or List&lt;Dimensionless&gt;; the data for the vector
147      * @param displayUnit DimensionlessUnit; the display unit of the vector data, and the unit of the data points when the data
148      *            is expressed as List&lt;Double&gt; or List&lt;Number&gt; in general
149      * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Vector
150      */
151     public DimensionlessVector(final List<? extends Number> data, final DimensionlessUnit displayUnit,
152             final StorageType storageType)
153     {
154         this(data.size() == 0 ? DoubleVectorData.instantiate(new double[] {}, IdentityScale.SCALE, storageType)
155                 : data.get(0) instanceof Dimensionless ? DoubleVectorData.instantiate(data, IdentityScale.SCALE, storageType)
156                         : DoubleVectorData.instantiate(data, displayUnit.getScale(), storageType),
157                 displayUnit);
158     }
159 
160     /**
161      * Construct an DimensionlessVector from a list of Number objects or a list of Dimensionless objects. Note that the
162      * displayUnit has a different meaning depending on whether the list contains Number objects (e.g., Double objects) or
163      * Dimensionless objects. In case the list contains Number objects, the displayUnit indicates the unit in which the values
164      * in the list are expressed, as well as the unit in which they will be printed. In case the list contains Dimensionless
165      * objects, each Dimensionless has its own unit, and the displayUnit is just used for printing. The values but will always
166      * be internally stored as SI values or base values, and expressed using the display unit or base unit when printing. Assume
167      * the storage type is DENSE since we offer the data as a List.
168      * @param data List&lt;Double&gt; or List&lt;Dimensionless&gt;; the data for the vector
169      * @param displayUnit DimensionlessUnit; the display unit of the vector data, and the unit of the data points when the data
170      *            is expressed as List&lt;Double&gt; or List&lt;Number&gt; in general
171      */
172     public DimensionlessVector(final List<? extends Number> data, final DimensionlessUnit displayUnit)
173     {
174         this(data, displayUnit, StorageType.DENSE);
175     }
176 
177     /**
178      * Construct an DimensionlessVector from a list of Number objects or a list of Dimensionless objects. When data contains
179      * numbers such as Double, assume that they are expressed using SI units. When the data consists of Dimensionless objects,
180      * they each have their own unit, but will be printed using SI units or base units. The values but will always be internally
181      * stored as SI values or base values, and expressed using the display unit or base unit when printing.
182      * @param data List&lt;Double&gt; or List&lt;Dimensionless&gt;; the data for the vector
183      * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Vector
184      */
185     public DimensionlessVector(final List<? extends Number> data, final StorageType storageType)
186     {
187         this(data, DimensionlessUnit.SI, storageType);
188     }
189 
190     /**
191      * Construct an DimensionlessVector from a list of Number objects or a list of Dimensionless objects. When data contains
192      * numbers such as Double, assume that they are expressed using SI units. When the data consists of Dimensionless objects,
193      * they each have their own unit, but will be printed using SI units or base units. The values but will always be internally
194      * stored as SI values or base values, and expressed using the display unit or base unit when printing. Assume the storage
195      * type is DENSE since we offer the data as a List.
196      * @param data List&lt;Double&gt; or List&lt;Dimensionless&gt;; the data for the vector
197      */
198     public DimensionlessVector(final List<? extends Number> data)
199     {
200         this(data, StorageType.DENSE);
201     }
202 
203     /* CONSTRUCTORS WITH Map<Integer, Double> or Map<Integer, Dimensionless> */
204 
205     /**
206      * Construct an DimensionlessVector from a (sparse) map of index values to Number objects or a (sparse) map of index values
207      * to of Dimensionless objects. Using index values is particularly useful for sparse vectors. The size parameter indicates
208      * the size of the vector, since the largest index does not have to be part of the map. Note that the displayUnit has a
209      * different meaning depending on whether the map contains Number objects (e.g., Double objects) or Dimensionless objects.
210      * In case the map contains Number objects, the displayUnit indicates the unit in which the values in the map are expressed,
211      * as well as the unit in which they will be printed. In case the map contains Dimensionless objects, each Dimensionless has
212      * its own unit, and the displayUnit is just used for printing. The values but will always be internally stored as SI values
213      * or base values, and expressed using the display unit or base unit when printing.
214      * @param data Map&lt;Integer, Double&gt; or Map&lt;Integer, Dimensionless&gt;; the data for the vector
215      * @param size int; the size off the vector, i.e., the highest index
216      * @param displayUnit DimensionlessUnit; the display unit of the vector data, and the unit of the data points when the data
217      *            is expressed as List&lt;Double&gt; or List&lt;Number&gt; in general
218      * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Vector
219      */
220     public DimensionlessVector(final Map<Integer, ? extends Number> data, final int size, final DimensionlessUnit displayUnit,
221             final StorageType storageType)
222     {
223         this(data.size() == 0 ? DoubleVectorData.instantiate(data, size, IdentityScale.SCALE, storageType)
224                 : data.values().iterator().next() instanceof Dimensionless
225                         ? DoubleVectorData.instantiate(data, size, IdentityScale.SCALE, storageType)
226                         : DoubleVectorData.instantiate(data, size, displayUnit.getScale(), storageType),
227                 displayUnit);
228     }
229 
230     /**
231      * Construct an DimensionlessVector from a (sparse) map of index values to Number objects or a (sparse) map of index values
232      * to of Dimensionless objects. Using index values is particularly useful for sparse vectors. The size parameter indicates
233      * the size of the vector, since the largest index does not have to be part of the map. Note that the displayUnit has a
234      * different meaning depending on whether the map contains Number objects (e.g., Double objects) or Dimensionless objects.
235      * In case the map contains Number objects, the displayUnit indicates the unit in which the values in the map are expressed,
236      * as well as the unit in which they will be printed. In case the map contains Dimensionless objects, each Dimensionless has
237      * its own unit, and the displayUnit is just used for printing. The values but will always be internally stored as SI values
238      * or base values, and expressed using the display unit or base unit when printing. Assume the storage type is SPARSE since
239      * we offer the data as a Map.
240      * @param data Map&lt;Integer, Double&gt; or Map&lt;Integer, Dimensionless&gt;; the data for the vector
241      * @param size int; the size off the vector, i.e., the highest index
242      * @param displayUnit DimensionlessUnit; the display unit of the vector data, and the unit of the data points when the data
243      *            is expressed as List&lt;Double&gt; or List&lt;Number&gt; in general
244      */
245     public DimensionlessVector(final Map<Integer, ? extends Number> data, final int size, final DimensionlessUnit displayUnit)
246     {
247         this(data, size, displayUnit, StorageType.SPARSE);
248     }
249 
250     /**
251      * Construct an DimensionlessVector from a (sparse) map of index values to Number objects or a (sparse) map of index values
252      * to of Dimensionless objects. Using index values is particularly useful for sparse vectors. The size parameter indicates
253      * the size of the vector, since the largest index does not have to be part of the map. When data contains numbers such as
254      * Double, assume that they are expressed using SI units. When the data consists of Dimensionless objects, they each have
255      * their own unit, but will be printed using SI units or base units. The values but will always be internally stored as SI
256      * values or base values, and expressed using the display unit or base unit when printing.
257      * @param data Map&lt;Integer, Double&gt; or Map&lt;Integer, Dimensionless&gt;; the data for the vector
258      * @param size int; the size off the vector, i.e., the highest index
259      * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Vector
260      */
261     public DimensionlessVector(final Map<Integer, ? extends Number> data, final int size, final StorageType storageType)
262     {
263         this(data, size, DimensionlessUnit.SI, storageType);
264     }
265 
266     /**
267      * Construct an DimensionlessVector from a (sparse) map of index values to Number objects or a (sparse) map of index values
268      * to of Dimensionless objects. Using index values is particularly useful for sparse vectors. The size parameter indicates
269      * the size of the vector, since the largest index does not have to be part of the map. When data contains numbers such as
270      * Double, assume that they are expressed using SI units. When the data consists of Dimensionless objects, they each have
271      * their own unit, but will be printed using SI units or base units. The values but will always be internally stored as SI
272      * values or base values, and expressed using the display unit or base unit when printing. Assume the storage type is SPARSE
273      * since we offer the data as a Map.
274      * @param data Map&lt;Integer, Double&gt; or Map&lt;Integer, Dimensionless&gt;; the data for the vector
275      * @param size int; the size off the vector, i.e., the highest index
276      */
277     public DimensionlessVector(final Map<Integer, ? extends Number> data, final int size)
278     {
279         this(data, size, StorageType.SPARSE);
280     }
281 
282     /* ****************************** Other methods ****************************** */
283 
284     @Override
285     public Class<Dimensionless> getScalarClass()
286     {
287         return Dimensionless.class;
288     }
289 
290     @Override
291     public DimensionlessVector instantiateVector(final DoubleVectorData dvd, final DimensionlessUnit displayUnit)
292     {
293         return new DimensionlessVector(dvd, displayUnit);
294     }
295 
296     @Override
297     public Dimensionless instantiateScalarSI(final double valueSI, final DimensionlessUnit displayUnit)
298     {
299         Dimensionless result = Dimensionless.instantiateSI(valueSI);
300         result.setDisplayUnit(displayUnit);
301         return result;
302     }
303 
304     @Override
305     public final DimensionlessVector acos()
306     {
307         assign(DoubleMathFunctions.ACOS);
308         return this;
309     }
310 
311     @Override
312     public final DimensionlessVector asin()
313     {
314         assign(DoubleMathFunctions.ASIN);
315         return this;
316     }
317 
318     @Override
319     public final DimensionlessVector atan()
320     {
321         assign(DoubleMathFunctions.ATAN);
322         return this;
323     }
324 
325     @Override
326     public final DimensionlessVector cbrt()
327     {
328         assign(DoubleMathFunctions.CBRT);
329         return this;
330     }
331 
332     @Override
333     public final DimensionlessVector cos()
334     {
335         assign(DoubleMathFunctions.COS);
336         return this;
337     }
338 
339     @Override
340     public final DimensionlessVector cosh()
341     {
342         assign(DoubleMathFunctions.COSH);
343         return this;
344     }
345 
346     @Override
347     public final DimensionlessVector exp()
348     {
349         assign(DoubleMathFunctions.EXP);
350         return this;
351     }
352 
353     @Override
354     public final DimensionlessVector expm1()
355     {
356         assign(DoubleMathFunctions.EXPM1);
357         return this;
358     }
359 
360     @Override
361     public final DimensionlessVector log()
362     {
363         assign(DoubleMathFunctions.LOG);
364         return this;
365     }
366 
367     @Override
368     public final DimensionlessVector log10()
369     {
370         assign(DoubleMathFunctions.LOG10);
371         return this;
372     }
373 
374     @Override
375     public final DimensionlessVector log1p()
376     {
377         assign(DoubleMathFunctions.LOG1P);
378         return this;
379     }
380 
381     @Override
382     public final DimensionlessVector pow(final double x)
383     {
384         assign(DoubleMathFunctions.POW((float) x));
385         return this;
386     }
387 
388     @Override
389     public final DimensionlessVector signum()
390     {
391         assign(DoubleMathFunctions.SIGNUM);
392         return this;
393     }
394 
395     @Override
396     public final DimensionlessVector sin()
397     {
398         assign(DoubleMathFunctions.SIN);
399         return this;
400     }
401 
402     @Override
403     public final DimensionlessVector sinh()
404     {
405         assign(DoubleMathFunctions.SINH);
406         return this;
407     }
408 
409     @Override
410     public final DimensionlessVector sqrt()
411     {
412         assign(DoubleMathFunctions.SQRT);
413         return this;
414     }
415 
416     @Override
417     public final DimensionlessVector tan()
418     {
419         assign(DoubleMathFunctions.TAN);
420         return this;
421     }
422 
423     @Override
424     public final DimensionlessVector tanh()
425     {
426         assign(DoubleMathFunctions.TANH);
427         return this;
428     }
429 
430     @Override
431     public final DimensionlessVector inv()
432     {
433         assign(DoubleMathFunctions.INV);
434         return this;
435     }
436 
437 }