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