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