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