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.ElectricalPotentialUnit;
7   import org.djunits.value.StorageType;
8   import org.djunits.value.ValueException;
9   import org.djunits.value.vfloat.scalar.FloatElectricalPotential;
10  
11  /**
12   * Mutable Float ElectricalPotentialVector, a vector of values with a ElectricalPotentialUnit.
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 MutableFloatElectricalPotentialVector extends AbstractMutableFloatVectorRel<ElectricalPotentialUnit,
23          FloatElectricalPotentialVector, MutableFloatElectricalPotentialVector, FloatElectricalPotential>
24  {
25      /** */
26      private static final long serialVersionUID = 20151109L;
27  
28      /**
29       * Construct a new Relative Immutable Float ElectricalPotentialVector.
30       * @param values float[]; the values of the entries in the new Relative Immutable Float ElectricalPotentialVector
31       * @param unit ElectricalPotentialUnit; the unit of the new Relative Immutable Float ElectricalPotentialVector
32       * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
33       * @throws ValueException when values is null
34       */
35      public MutableFloatElectricalPotentialVector(final float[] values, final ElectricalPotentialUnit unit,
36              final StorageType storageType) throws ValueException
37      {
38          super(values, unit, storageType);
39      }
40  
41      /**
42       * Construct a new Relative Immutable Float ElectricalPotentialVector.
43       * @param values List&lt;Float&gt;; the values of the entries in the new Relative Immutable Float ElectricalPotentialVector
44       * @param unit ElectricalPotentialUnit; the unit of the new Relative Immutable Float ElectricalPotentialVector
45       * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
46       * @throws ValueException when values is null
47       */
48      public MutableFloatElectricalPotentialVector(final List<Float> values, final ElectricalPotentialUnit unit,
49              final StorageType storageType) throws ValueException
50      {
51          super(values, unit, storageType);
52      }
53  
54      /**
55       * Construct a new Relative Immutable Float ElectricalPotentialVector.
56       * @param values FloatElectricalPotential[]; the values of the entries in the new Relative Immutable Float
57       *            ElectricalPotentialVector
58       * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
59       * @throws ValueException when values has zero entries
60       */
61      public MutableFloatElectricalPotentialVector(final FloatElectricalPotential[] values, final StorageType storageType)
62              throws ValueException
63      {
64          super(values, storageType);
65      }
66  
67      /**
68       * Construct a new Relative Immutable Float ElectricalPotentialVector.
69       * @param values List&lt;FloatElectricalPotential&gt;; the values of the entries in the new Relative Immutable Float
70       *            ElectricalPotentialVector
71       * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
72       * @throws ValueException when values has zero entries
73       */
74      public MutableFloatElectricalPotentialVector(final List<FloatElectricalPotential> values, final StorageType storageType)
75              throws ValueException
76      {
77          super(values, storageType);
78      }
79  
80      /**
81       * Construct a new Relative Immutable Float ElectricalPotentialVector.
82       * @param values SortedMap&lt;Integer, FloatElectricalPotential&gt;; the values of the entries in the new Relative Sparse
83       *            Mutable Float ElectricalPotentialVector
84       * @param length int; the size of the vector
85       * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
86       * @throws ValueException when values has zero entries
87       */
88      public MutableFloatElectricalPotentialVector(final SortedMap<Integer, FloatElectricalPotential> values, final int length,
89              final StorageType storageType) throws ValueException
90      {
91          super(values, length, storageType);
92      }
93  
94      /**
95       * Construct a new Relative Immutable Float ElectricalPotentialVector.
96       * @param values SortedMap&lt;Integer, Float&gt;; the map of indexes to values of the Relative Sparse Mutable Float
97       *            ElectricalPotentialVector
98       * @param unit ElectricalPotentialUnit; the unit of the new Relative Sparse Mutable Float ElectricalPotentialVector
99       * @param length int; the size of the vector
100      * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
101      * @throws ValueException when values is null
102      */
103     public MutableFloatElectricalPotentialVector(final SortedMap<Integer, Float> values, final ElectricalPotentialUnit unit,
104             final int length, final StorageType storageType) throws ValueException
105     {
106         super(values, unit, length, storageType);
107     }
108 
109     /**
110      * @param data FloatVectorData; an internal data object
111      * @param unit ElectricalPotentialUnit; the unit
112      */
113     MutableFloatElectricalPotentialVector(final FloatVectorData data, final ElectricalPotentialUnit unit)
114     {
115         super(data, unit);
116     }
117 
118     /** {@inheritDoc} */
119     @Override
120     protected final FloatElectricalPotentialVector instantiateType(final FloatVectorData dvd,
121             final ElectricalPotentialUnit unit)
122     {
123         return new FloatElectricalPotentialVector(dvd, unit);
124     }
125 
126     /** {@inheritDoc} */
127     @Override
128     protected final MutableFloatElectricalPotentialVector instantiateMutableType(final FloatVectorData dvd,
129             final ElectricalPotentialUnit unit)
130     {
131         return new MutableFloatElectricalPotentialVector(dvd, unit);
132     }
133 
134     /** {@inheritDoc} */
135     @Override
136     protected final FloatElectricalPotential instantiateScalar(final float value, final ElectricalPotentialUnit unit)
137     {
138         return new FloatElectricalPotential(value, unit);
139     }
140 
141     /** {@inheritDoc} */
142     @Override
143     public final MutableFloatElectricalPotentialVector toDense()
144     {
145         return this.data.isDense() ? (MutableFloatElectricalPotentialVector) this
146                 : instantiateMutableType(this.data.toDense(), getUnit());
147     }
148 
149     /** {@inheritDoc} */
150     @Override
151     public final MutableFloatElectricalPotentialVector toSparse()
152     {
153         return this.data.isSparse() ? (MutableFloatElectricalPotentialVector) this
154                 : instantiateMutableType(this.data.toSparse(), getUnit());
155     }
156 
157     /**
158      * Return an array of FloatElectricalPotential Scalars from this vector.
159      * @return FloatElectricalPotential[]; an array of FloatElectricalPotential Scalars from this vector
160      * @throws RuntimeException wrapping a ValueException on error getting one of the values
161      */
162     public FloatElectricalPotential[] toArray()
163     {
164         FloatElectricalPotential[] array = new FloatElectricalPotential[size()];
165         for (int i = 0; i < size(); i++)
166         {
167             try
168             {
169                 array[i] = get(i);
170             }
171             catch (ValueException exception)
172             {
173                 throw new RuntimeException(exception);
174             }
175         }
176         return array;
177     }
178 
179 }