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