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