View Javadoc
1   package org.djunits.value.vdouble.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.vdouble.scalar.ElectricalPotential;
10  
11  /**
12   * Mutable Double 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 MutableElectricalPotentialVector extends AbstractMutableDoubleVectorRel<ElectricalPotentialUnit,
23          ElectricalPotentialVector, MutableElectricalPotentialVector, ElectricalPotential>
24  {
25      /** */
26      private static final long serialVersionUID = 20151109L;
27  
28      /**
29       * Construct a new Relative Immutable Double ElectricalPotentialVector.
30       * @param values double[]; the values of the entries in the new Relative Immutable Double ElectricalPotentialVector
31       * @param unit ElectricalPotentialUnit; the unit of the new Relative Immutable Double 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 MutableElectricalPotentialVector(final double[] 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 Double ElectricalPotentialVector.
43       * @param values List&lt;Double&gt;; the values of the entries in the new Relative Immutable Double
44       *            ElectricalPotentialVector
45       * @param unit ElectricalPotentialUnit; the unit of the new Relative Immutable Double ElectricalPotentialVector
46       * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
47       * @throws ValueException when values is null
48       */
49      public MutableElectricalPotentialVector(final List<Double> values, final ElectricalPotentialUnit unit,
50              final StorageType storageType) throws ValueException
51      {
52          super(values, unit, storageType);
53      }
54  
55      /**
56       * Construct a new Relative Immutable Double ElectricalPotentialVector.
57       * @param values ElectricalPotential[]; the values of the entries in the new Relative Immutable Double
58       *            ElectricalPotentialVector
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 MutableElectricalPotentialVector(final ElectricalPotential[] values, final StorageType storageType)
63              throws ValueException
64      {
65          super(values, storageType);
66      }
67  
68      /**
69       * Construct a new Relative Immutable Double ElectricalPotentialVector.
70       * @param values List&lt;ElectricalPotential&gt;; the values of the entries in the new Relative Immutable Double
71       *            ElectricalPotentialVector
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 MutableElectricalPotentialVector(final List<ElectricalPotential> values, final StorageType storageType)
76              throws ValueException
77      {
78          super(values, storageType);
79      }
80  
81      /**
82       * Construct a new Relative Immutable Double ElectricalPotentialVector.
83       * @param values SortedMap&lt;Integer, ElectricalPotential&gt;; the values of the entries in the new Relative Sparse Mutable
84       *            Double ElectricalPotentialVector
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 MutableElectricalPotentialVector(final SortedMap<Integer, ElectricalPotential> 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 Double ElectricalPotentialVector.
97       * @param values SortedMap&lt;Integer, Double&gt;; the map of indexes to values of the Relative Sparse Mutable Double
98       *            ElectricalPotentialVector
99       * @param unit ElectricalPotentialUnit; the unit of the new Relative Sparse Mutable Double ElectricalPotentialVector
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 MutableElectricalPotentialVector(final SortedMap<Integer, Double> values, final ElectricalPotentialUnit unit,
105             final int length, final StorageType storageType) throws ValueException
106     {
107         super(values, unit, length, storageType);
108     }
109 
110     /**
111      * @param data DoubleVectorData; an internal data object
112      * @param unit ElectricalPotentialUnit; the unit
113      */
114     MutableElectricalPotentialVector(final DoubleVectorData data, final ElectricalPotentialUnit unit)
115     {
116         super(data, unit);
117     }
118 
119     /** {@inheritDoc} */
120     @Override
121     protected final ElectricalPotentialVector instantiateType(final DoubleVectorData dvd, final ElectricalPotentialUnit unit)
122     {
123         return new ElectricalPotentialVector(dvd, unit);
124     }
125 
126     /** {@inheritDoc} */
127     @Override
128     protected final MutableElectricalPotentialVector instantiateMutableType(final DoubleVectorData dvd,
129             final ElectricalPotentialUnit unit)
130     {
131         return new MutableElectricalPotentialVector(dvd, unit);
132     }
133 
134     /** {@inheritDoc} */
135     @Override
136     protected final ElectricalPotential instantiateScalar(final double value, final ElectricalPotentialUnit unit)
137     {
138         return new ElectricalPotential(value, unit);
139     }
140 
141     /** {@inheritDoc} */
142     @Override
143     public final MutableElectricalPotentialVector toDense()
144     {
145         return this.data.isDense() ? (MutableElectricalPotentialVector) this
146                 : instantiateMutableType(this.data.toDense(), getUnit());
147     }
148 
149     /** {@inheritDoc} */
150     @Override
151     public final MutableElectricalPotentialVector toSparse()
152     {
153         return this.data.isSparse() ? (MutableElectricalPotentialVector) this
154                 : instantiateMutableType(this.data.toSparse(), getUnit());
155     }
156 
157     /**
158      * Return an array of ElectricalPotential Scalars from this vector.
159      * @return ElectricalPotential[]; an array of ElectricalPotential Scalars from this vector
160      * @throws RuntimeException wrapping a ValueException on error getting one of the values
161      */
162     public ElectricalPotential[] toArray()
163     {
164         ElectricalPotential[] array = new ElectricalPotential[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 }