View Javadoc
1   package org.djunits.value.vfloat.vector;
2   
3   import java.util.List;
4   import java.util.SortedMap;
5   
6   import org.djunits.unit.ElectricalChargeUnit;
7   import org.djunits.value.StorageType;
8   import org.djunits.value.ValueException;
9   import org.djunits.value.vfloat.scalar.FloatElectricalCharge;
10  
11  /**
12   * Immutable Float FloatElectricalChargeVector, a vector of values with a ElectricalChargeUnit.
13   * <p>
14   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
16   * </p>
17   * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
18   * initial version Oct 9, 2015 <br>
19   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
20   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
21   */
22  public class FloatElectricalChargeVector extends AbstractFloatVectorRel<ElectricalChargeUnit, FloatElectricalChargeVector,
23          MutableFloatElectricalChargeVector, FloatElectricalCharge>
24  {
25      /** */
26      private static final long serialVersionUID = 20151109L;
27  
28      /**
29       * Construct a new Relative Immutable Float FloatElectricalChargeVector.
30       * @param values float[]; the values of the entries in the new Relative Immutable Float FloatElectricalChargeVector
31       * @param unit ElectricalChargeUnit; the unit of the new Relative Immutable Float FloatElectricalChargeVector
32       * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
33       * @throws ValueException when values is null
34       */
35      public FloatElectricalChargeVector(final float[] values, final ElectricalChargeUnit unit, final StorageType storageType)
36              throws ValueException
37      {
38          super(values, unit, storageType);
39      }
40  
41      /**
42       * Construct a new Relative Immutable Float FloatElectricalChargeVector.
43       * @param values List&lt;Float&gt;; the values of the entries in the new Relative Immutable Float
44       *            FloatElectricalChargeVector
45       * @param unit ElectricalChargeUnit; the unit of the new Relative Immutable Float FloatElectricalChargeVector
46       * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
47       * @throws ValueException when values is null
48       */
49      public FloatElectricalChargeVector(final List<Float> values, final ElectricalChargeUnit unit, final StorageType storageType)
50              throws ValueException
51      {
52          super(values, unit, storageType);
53      }
54  
55      /**
56       * Construct a new Relative Immutable Float FloatElectricalChargeVector.
57       * @param values FloatElectricalCharge[]; the values of the entries in the new Relative Immutable Float
58       *            FloatElectricalChargeVector
59       * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
60       * @throws ValueException when values has zero entries
61       */
62      public FloatElectricalChargeVector(final FloatElectricalCharge[] values, final StorageType storageType)
63              throws ValueException
64      {
65          super(values, storageType);
66      }
67  
68      /**
69       * Construct a new Relative Immutable Float FloatElectricalChargeVector.
70       * @param values List&lt;FloatElectricalCharge&gt;; the values of the entries in the new Relative Immutable Float
71       *            FloatElectricalChargeVector
72       * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
73       * @throws ValueException when values has zero entries
74       */
75      public FloatElectricalChargeVector(final List<FloatElectricalCharge> values, final StorageType storageType)
76              throws ValueException
77      {
78          super(values, storageType);
79      }
80  
81      /**
82       * Construct a new Relative Immutable Float FloatElectricalChargeVector.
83       * @param values SortedMap&lt;Integer, FloatElectricalCharge&gt;; the values of the entries in the new Relative Sparse
84       *            Mutable Float FloatElectricalChargeVector
85       * @param length int; the size of the vector
86       * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
87       * @throws ValueException when values has zero entries
88       */
89      public FloatElectricalChargeVector(final SortedMap<Integer, FloatElectricalCharge> values, final int length,
90              final StorageType storageType) throws ValueException
91      {
92          super(values, length, storageType);
93      }
94  
95      /**
96       * Construct a new Relative Immutable Float FloatElectricalChargeVector.
97       * @param values SortedMap&lt;Integer, Float&gt;; the map of indexes to values of the Relative Sparse Mutable Float
98       *            FloatElectricalChargeVector
99       * @param unit ElectricalChargeUnit; the unit of the new Relative Sparse Mutable Float FloatElectricalChargeVector
100      * @param length int; the size of the vector
101      * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
102      * @throws ValueException when values is null
103      */
104     public FloatElectricalChargeVector(final SortedMap<Integer, Float> values, final ElectricalChargeUnit unit,
105             final int length, final StorageType storageType) throws ValueException
106     {
107         super(values, unit, length, storageType);
108     }
109 
110     /**
111      * @param data FloatVectorData; an internal data object
112      * @param unit ElectricalChargeUnit; the unit
113      */
114     FloatElectricalChargeVector(final FloatVectorData data, final ElectricalChargeUnit unit)
115     {
116         super(data, unit);
117     }
118 
119     /** {@inheritDoc} */
120     @Override
121     protected final FloatElectricalChargeVector instantiateType(final FloatVectorData dvd, final ElectricalChargeUnit unit)
122     {
123         return new FloatElectricalChargeVector(dvd, unit);
124     }
125 
126     /** {@inheritDoc} */
127     @Override
128     protected final MutableFloatElectricalChargeVector instantiateMutableType(final FloatVectorData dvd,
129             final ElectricalChargeUnit unit)
130     {
131         return new MutableFloatElectricalChargeVector(dvd, unit);
132     }
133 
134     /** {@inheritDoc} */
135     @Override
136     protected final FloatElectricalCharge instantiateScalar(final float value, final ElectricalChargeUnit unit)
137     {
138         return new FloatElectricalCharge(value, unit);
139     }
140 
141     /** {@inheritDoc} */
142     @Override
143     public final FloatElectricalChargeVector toDense()
144     {
145         return this.data.isDense() ? (FloatElectricalChargeVector) this : instantiateType(this.data.toDense(), getUnit());
146     }
147 
148     /** {@inheritDoc} */
149     @Override
150     public final FloatElectricalChargeVector toSparse()
151     {
152         return this.data.isSparse() ? (FloatElectricalChargeVector) this : instantiateType(this.data.toSparse(), getUnit());
153     }
154 
155     /**
156      * Return an array of FloatElectricalCharge Scalars from this vector.
157      * @return FloatElectricalCharge[]; an array of FloatElectricalCharge Scalars from this vector
158      * @throws RuntimeException wrapping a ValueException on error getting one of the values
159      */
160     public FloatElectricalCharge[] toArray()
161     {
162         FloatElectricalCharge[] array = new FloatElectricalCharge[size()];
163         for (int i = 0; i < size(); i++)
164         {
165             try
166             {
167                 array[i] = get(i);
168             }
169             catch (ValueException exception)
170             {
171                 throw new RuntimeException(exception);
172             }
173         }
174         return array;
175     }
176 
177 }