FloatSpeedVector.java

  1. package org.djunits.value.vfloat.vector;

  2. import java.util.List;
  3. import java.util.Map;

  4. import org.djunits.unit.SpeedUnit;
  5. import org.djunits.unit.scale.IdentityScale;
  6. import org.djunits.value.storage.StorageType;
  7. import org.djunits.value.vfloat.scalar.FloatSpeed;
  8. import org.djunits.value.vfloat.vector.base.FloatVectorRel;
  9. import org.djunits.value.vfloat.vector.data.FloatVectorData;

  10. import jakarta.annotation.Generated;

  11. /**
  12.  * Immutable Float FloatSpeedVector, a vector of values with a SpeedUnit.
  13.  * <p>
  14.  * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  15.  * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
  16.  * </p>
  17.  * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  18.  * @author <a href="https://www.tudelft.nl/staff/p.knoppers/">Peter Knoppers</a>
  19.  */
  20. @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2023-07-23T14:06:38.224104100Z")
  21. public class FloatSpeedVector extends FloatVectorRel<SpeedUnit, FloatSpeed, FloatSpeedVector>

  22. {
  23.     /** */
  24.     private static final long serialVersionUID = 20190905L;

  25.     /**
  26.      * Construct a FloatSpeedVector from an internal data object.
  27.      * @param data FloatVectorData; the internal data object for the vector
  28.      * @param displayUnit SpeedUnit; the display unit of the vector data
  29.      */
  30.     public FloatSpeedVector(final FloatVectorData data, final SpeedUnit displayUnit)
  31.     {
  32.         super(data, displayUnit);
  33.     }

  34.     /* CONSTRUCTORS WITH float[] */

  35.     /**
  36.      * Construct a FloatSpeedVector from a float[] object. The Float values are expressed in the displayUnit, and will be
  37.      * printed using the displayUnit.
  38.      * @param data float[]; the data for the vector, expressed in the displayUnit
  39.      * @param displayUnit SpeedUnit; the unit of the values in the data array, and display unit when printing
  40.      * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Vector
  41.      */
  42.     public FloatSpeedVector(final float[] data, final SpeedUnit displayUnit, final StorageType storageType)
  43.     {
  44.         this(FloatVectorData.instantiate(data, displayUnit.getScale(), storageType), displayUnit);
  45.     }

  46.     /**
  47.      * Construct a FloatSpeedVector from a float[] object. The Float values are expressed in the displayUnit. Assume that the
  48.      * StorageType is DENSE since we offer the data as an array.
  49.      * @param data float[]; the data for the vector
  50.      * @param displayUnit SpeedUnit; the unit of the values in the data array, and display unit when printing
  51.      */
  52.     public FloatSpeedVector(final float[] data, final SpeedUnit displayUnit)
  53.     {
  54.         this(data, displayUnit, StorageType.DENSE);
  55.     }

  56.     /**
  57.      * Construct a FloatSpeedVector from a float[] object with SI-unit values.
  58.      * @param data float[]; the data for the vector, in SI units
  59.      * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Vector
  60.      */
  61.     public FloatSpeedVector(final float[] data, final StorageType storageType)
  62.     {
  63.         this(data, SpeedUnit.SI, storageType);
  64.     }

  65.     /**
  66.      * Construct a FloatSpeedVector from a float[] object with SI-unit values. Assume that the StorageType is DENSE since we
  67.      * offer the data as an array.
  68.      * @param data float[]; the data for the vector, in SI units
  69.      */
  70.     public FloatSpeedVector(final float[] data)
  71.     {
  72.         this(data, StorageType.DENSE);
  73.     }

  74.     /* CONSTRUCTORS WITH FloatSpeed[] */

  75.     /**
  76.      * Construct a FloatSpeedVector from an array of FloatSpeed objects. The FloatSpeed values are each expressed in their own
  77.      * unit, but will be internally stored as SI values, all expressed in the displayUnit when printing.
  78.      * @param data FloatSpeed[]; the data for the vector
  79.      * @param displayUnit SpeedUnit; the display unit of the values when printing
  80.      * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Vector
  81.      */
  82.     public FloatSpeedVector(final FloatSpeed[] data, final SpeedUnit displayUnit, final StorageType storageType)
  83.     {
  84.         this(FloatVectorData.instantiate(data, storageType), displayUnit);
  85.     }

  86.     /**
  87.      * Construct a FloatSpeedVector from an array of FloatSpeed objects. The FloatSpeed values are each expressed in their own
  88.      * unit, but will be internally stored as SI values, all expressed in the displayUnit when printing. Assume that the
  89.      * StorageType is DENSE since we offer the data as an array.
  90.      * @param data FloatSpeed[]; the data for the vector
  91.      * @param displayUnit SpeedUnit; the display unit of the values when printing
  92.      */
  93.     public FloatSpeedVector(final FloatSpeed[] data, final SpeedUnit displayUnit)
  94.     {
  95.         this(data, displayUnit, StorageType.DENSE);
  96.     }

  97.     /**
  98.      * Construct a FloatSpeedVector from an array of FloatSpeed objects. The FloatSpeed values are each expressed in their own
  99.      * unit, but will be internally stored as SI values, and expressed using SI units when printing. since we offer the data as
  100.      * an array.
  101.      * @param data FloatSpeed[]; the data for the vector
  102.      * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Vector
  103.      */
  104.     public FloatSpeedVector(final FloatSpeed[] data, final StorageType storageType)
  105.     {
  106.         this(data, SpeedUnit.SI, storageType);
  107.     }

  108.     /**
  109.      * Construct a FloatSpeedVector from an array of FloatSpeed objects. The FloatSpeed values are each expressed in their own
  110.      * unit, but will be internally stored as SI values, and expressed using SI units when printing. Assume that the StorageType
  111.      * is DENSE since we offer the data as an array.
  112.      * @param data FloatSpeed[]; the data for the vector
  113.      */
  114.     public FloatSpeedVector(final FloatSpeed[] data)
  115.     {
  116.         this(data, StorageType.DENSE);
  117.     }

  118.     /* CONSTRUCTORS WITH List<Float> or List<Speed> */

  119.     /**
  120.      * Construct a FloatSpeedVector from a list of Number objects or a list of FloatSpeed objects. Note that the displayUnit has
  121.      * a different meaning depending on whether the list contains Number objects (e.g., Float objects) or FloatSpeed objects. In
  122.      * case the list contains Number objects, the displayUnit indicates the unit in which the values in the list are expressed,
  123.      * as well as the unit in which they will be printed. In case the list contains FloatSpeed objects, each FloatSpeed has its
  124.      * own unit, and the displayUnit is just used for printing. The values but will always be internally stored as SI values or
  125.      * base values, and expressed using the display unit or base unit when printing.
  126.      * @param data List&lt;Float&gt; or List&lt;Speed&gt;; the data for the vector
  127.      * @param displayUnit SpeedUnit; the display unit of the vector data, and the unit of the data points when the data is
  128.      *            expressed as List&lt;Float&gt; or List&lt;Number&gt; in general
  129.      * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Vector
  130.      */
  131.     public FloatSpeedVector(final List<? extends Number> data, final SpeedUnit displayUnit, final StorageType storageType)
  132.     {
  133.         this(data.size() == 0 ? FloatVectorData.instantiate(new float[] {}, IdentityScale.SCALE, storageType)
  134.                 : data.get(0) instanceof FloatSpeed ? FloatVectorData.instantiate(data, IdentityScale.SCALE, storageType)
  135.                         : FloatVectorData.instantiate(data, displayUnit.getScale(), storageType),
  136.                 displayUnit);
  137.     }

  138.     /**
  139.      * Construct a FloatSpeedVector from a list of Number objects or a list of FloatSpeed objects. Note that the displayUnit has
  140.      * a different meaning depending on whether the list contains Number objects (e.g., Float objects) or FloatSpeed 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 FloatSpeed objects, each FloatSpeed 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. Assume the storage type is DENSE since we
  145.      * offer the data as a List.
  146.      * @param data List&lt;Float&gt; or List&lt;Speed&gt;; the data for the vector
  147.      * @param displayUnit SpeedUnit; 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.      */
  150.     public FloatSpeedVector(final List<? extends Number> data, final SpeedUnit displayUnit)
  151.     {
  152.         this(data, displayUnit, StorageType.DENSE);
  153.     }

  154.     /**
  155.      * Construct a FloatSpeedVector from a list of Number objects or a list of FloatSpeed objects. When data contains numbers
  156.      * such as Float, assume that they are expressed using SI units. When the data consists of FloatSpeed objects, they each
  157.      * have their own unit, but will be printed using SI units or base units. The values but will always be internally stored as
  158.      * SI values or base values, and expressed using the display unit or base unit when printing.
  159.      * @param data List&lt;Float&gt; or List&lt;Speed&gt;; the data for the vector
  160.      * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Vector
  161.      */
  162.     public FloatSpeedVector(final List<? extends Number> data, final StorageType storageType)
  163.     {
  164.         this(data, SpeedUnit.SI, storageType);
  165.     }

  166.     /**
  167.      * Construct a FloatSpeedVector from a list of Number objects or a list of FloatSpeed objects. When data contains numbers
  168.      * such as Float, assume that they are expressed using SI units. When the data consists of FloatSpeed objects, they each
  169.      * have their own unit, but will be printed using SI units or base units. The values but will always be internally stored as
  170.      * SI values or base values, and expressed using the display unit or base unit when printing. Assume the storage type is
  171.      * DENSE since we offer the data as a List.
  172.      * @param data List&lt;Float&gt; or List&lt;Speed&gt;; the data for the vector
  173.      */
  174.     public FloatSpeedVector(final List<? extends Number> data)
  175.     {
  176.         this(data, StorageType.DENSE);
  177.     }

  178.     /* CONSTRUCTORS WITH Map<Integer, Float> or Map<Integer, FloatSpeed> */

  179.     /**
  180.      * Construct a FloatSpeedVector from a (sparse) map of index values to Number objects or a (sparse) map of index values to
  181.      * of FloatSpeed objects. Using index values is particularly useful for sparse vectors. The size parameter indicates the
  182.      * size of the vector, since the largest index does not have to be part of the map. Note that the displayUnit has a
  183.      * different meaning depending on whether the map contains Number objects (e.g., Float objects) or FloatSpeed objects. In
  184.      * case the map contains Number objects, the displayUnit indicates the unit in which the values in the map are expressed, as
  185.      * well as the unit in which they will be printed. In case the map contains FloatSpeed objects, each FloatSpeed has its own
  186.      * unit, and the displayUnit is just used for printing. The values but will always be internally stored as SI values or base
  187.      * values, and expressed using the display unit or base unit when printing.
  188.      * @param data Map&lt;Integer, Float&gt; or Map&lt;Integer, FloatSpeed&gt;; the data for the vector
  189.      * @param size int; the size off the vector, i.e., the highest index
  190.      * @param displayUnit SpeedUnit; the display unit of the vector data, and the unit of the data points when the data is
  191.      *            expressed as List&lt;Float&gt; or List&lt;Number&gt; in general
  192.      * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Vector
  193.      */
  194.     public FloatSpeedVector(final Map<Integer, ? extends Number> data, final int size, final SpeedUnit displayUnit,
  195.             final StorageType storageType)
  196.     {
  197.         this(data.size() == 0 ? FloatVectorData.instantiate(data, size, IdentityScale.SCALE, storageType)
  198.                 : data.values().iterator().next() instanceof FloatSpeed
  199.                         ? FloatVectorData.instantiate(data, size, IdentityScale.SCALE, storageType)
  200.                         : FloatVectorData.instantiate(data, size, displayUnit.getScale(), storageType),
  201.                 displayUnit);
  202.     }

  203.     /**
  204.      * Construct a FloatSpeedVector from a (sparse) map of index values to Number objects or a (sparse) map of index values to
  205.      * of FloatSpeed objects. Using index values is particularly useful for sparse vectors. The size parameter indicates the
  206.      * size of the vector, since the largest index does not have to be part of the map. Note that the displayUnit has a
  207.      * different meaning depending on whether the map contains Number objects (e.g., Float objects) or FloatSpeed objects. In
  208.      * case the map contains Number objects, the displayUnit indicates the unit in which the values in the map are expressed, as
  209.      * well as the unit in which they will be printed. In case the map contains FloatSpeed objects, each FloatSpeed has its own
  210.      * unit, and the displayUnit is just used for printing. The values but will always be internally stored as SI values or base
  211.      * values, and expressed using the display unit or base unit when printing. Assume the storage type is SPARSE since we offer
  212.      * the data as a Map.
  213.      * @param data Map&lt;Integer, Float&gt; or Map&lt;Integer, FloatSpeed&gt;; the data for the vector
  214.      * @param size int; the size off the vector, i.e., the highest index
  215.      * @param displayUnit SpeedUnit; 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.      */
  218.     public FloatSpeedVector(final Map<Integer, ? extends Number> data, final int size, final SpeedUnit displayUnit)
  219.     {
  220.         this(data, size, displayUnit, StorageType.SPARSE);
  221.     }

  222.     /**
  223.      * Construct a FloatSpeedVector from a (sparse) map of index values to Number objects or a (sparse) map of index values to
  224.      * of FloatSpeed objects. Using index values is particularly useful for sparse vectors. The size parameter indicates the
  225.      * size of the vector, since the largest index does not have to be part of the map. When data contains numbers such as
  226.      * Float, assume that they are expressed using SI units. When the data consists of FloatSpeed objects, they each have their
  227.      * own unit, but will be printed using SI units or base units. The values but will always be internally stored as SI values
  228.      * or base values, and expressed using the display unit or base unit when printing.
  229.      * @param data Map&lt;Integer, Float&gt; or Map&lt;Integer, FloatSpeed&gt;; the data for the vector
  230.      * @param size int; the size off the vector, i.e., the highest index
  231.      * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Vector
  232.      */
  233.     public FloatSpeedVector(final Map<Integer, ? extends Number> data, final int size, final StorageType storageType)
  234.     {
  235.         this(data, size, SpeedUnit.SI, storageType);
  236.     }

  237.     /**
  238.      * Construct a FloatSpeedVector from a (sparse) map of index values to Number objects or a (sparse) map of index values to
  239.      * of FloatSpeed objects. Using index values is particularly useful for sparse vectors. The size parameter indicates the
  240.      * size of the vector, since the largest index does not have to be part of the map. When data contains numbers such as
  241.      * Float, assume that they are expressed using SI units. When the data consists of FloatSpeed objects, they each have their
  242.      * own unit, but will be printed using SI units or base units. The values but will always be internally stored as SI values
  243.      * or base values, and expressed using the display unit or base unit when printing. Assume the storage type is SPARSE since
  244.      * we offer the data as a Map.
  245.      * @param data Map&lt;Integer, Float&gt; or Map&lt;Integer, FloatSpeed&gt;; the data for the vector
  246.      * @param size int; the size off the vector, i.e., the highest index
  247.      */
  248.     public FloatSpeedVector(final Map<Integer, ? extends Number> data, final int size)
  249.     {
  250.         this(data, size, StorageType.SPARSE);
  251.     }

  252.     /* ****************************** Other methods ****************************** */

  253.     @Override
  254.     public Class<FloatSpeed> getScalarClass()
  255.     {
  256.         return FloatSpeed.class;
  257.     }

  258.     @Override
  259.     public FloatSpeedVector instantiateVector(final FloatVectorData fvd, final SpeedUnit displayUnit)
  260.     {
  261.         return new FloatSpeedVector(fvd, displayUnit);
  262.     }

  263.     @Override
  264.     public FloatSpeed instantiateScalarSI(final float valueSI, final SpeedUnit displayUnit)
  265.     {
  266.         FloatSpeed result = FloatSpeed.instantiateSI(valueSI);
  267.         result.setDisplayUnit(displayUnit);
  268.         return result;
  269.     }

  270. }