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.DimensionlessUnit;
7   import org.djunits.value.MathFunctionsDimensionless;
8   import org.djunits.value.StorageType;
9   import org.djunits.value.ValueException;
10  import org.djunits.value.vfloat.FloatMathFunctions;
11  import org.djunits.value.vfloat.scalar.FloatDimensionless;
12  
13  /**
14   * Mutable Float DimensionlessVector, a vector of values with a DimensionlessUnit.
15   * <p>
16   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
17   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
18   * </p>
19   * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
20   * initial version Oct 9, 2015 <br>
21   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
22   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
23   */
24  public class MutableFloatDimensionlessVector extends AbstractMutableFloatVectorRel<DimensionlessUnit, FloatDimensionlessVector,
25          MutableFloatDimensionlessVector, FloatDimensionless>
26          implements MathFunctionsDimensionless<MutableFloatDimensionlessVector>
27  {
28      /** */
29      private static final long serialVersionUID = 20151109L;
30  
31      /**
32       * Construct a new Relative Immutable Float DimensionlessVector.
33       * @param values float[]; the values of the entries in the new Relative Immutable Float DimensionlessVector
34       * @param unit DimensionlessUnit; the unit of the new Relative Immutable Float DimensionlessVector
35       * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
36       * @throws ValueException when values is null
37       */
38      public MutableFloatDimensionlessVector(final float[] values, final DimensionlessUnit unit, final StorageType storageType)
39              throws ValueException
40      {
41          super(values, unit, storageType);
42      }
43  
44      /**
45       * Construct a new Relative Immutable Float DimensionlessVector.
46       * @param values List&lt;Float&gt;; the values of the entries in the new Relative Immutable Float DimensionlessVector
47       * @param unit DimensionlessUnit; the unit of the new Relative Immutable Float DimensionlessVector
48       * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
49       * @throws ValueException when values is null
50       */
51      public MutableFloatDimensionlessVector(final List<Float> values, final DimensionlessUnit unit,
52              final StorageType storageType) throws ValueException
53      {
54          super(values, unit, storageType);
55      }
56  
57      /**
58       * Construct a new Relative Immutable Float DimensionlessVector.
59       * @param values FloatDimensionless[]; the values of the entries in the new Relative Immutable Float DimensionlessVector
60       * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
61       * @throws ValueException when values has zero entries
62       */
63      public MutableFloatDimensionlessVector(final FloatDimensionless[] values, final StorageType storageType)
64              throws ValueException
65      {
66          super(values, storageType);
67      }
68  
69      /**
70       * Construct a new Relative Immutable Float DimensionlessVector.
71       * @param values List&lt;FloatDimensionless&gt;; the values of the entries in the new Relative Immutable Float
72       *            DimensionlessVector
73       * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
74       * @throws ValueException when values has zero entries
75       */
76      public MutableFloatDimensionlessVector(final List<FloatDimensionless> values, final StorageType storageType)
77              throws ValueException
78      {
79          super(values, storageType);
80      }
81  
82      /**
83       * Construct a new Relative Immutable Float DimensionlessVector.
84       * @param values SortedMap&lt;Integer, FloatDimensionless&gt;; the values of the entries in the new Relative Sparse Mutable
85       *            Float DimensionlessVector
86       * @param length int; the size of the vector
87       * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
88       * @throws ValueException when values has zero entries
89       */
90      public MutableFloatDimensionlessVector(final SortedMap<Integer, FloatDimensionless> values, final int length,
91              final StorageType storageType) throws ValueException
92      {
93          super(values, length, storageType);
94      }
95  
96      /**
97       * Construct a new Relative Immutable Float DimensionlessVector.
98       * @param values SortedMap&lt;Integer, Float&gt;; the map of indexes to values of the Relative Sparse Mutable Float
99       *            DimensionlessVector
100      * @param unit DimensionlessUnit; the unit of the new Relative Sparse Mutable Float DimensionlessVector
101      * @param length int; the size of the vector
102      * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
103      * @throws ValueException when values is null
104      */
105     public MutableFloatDimensionlessVector(final SortedMap<Integer, Float> values, final DimensionlessUnit unit,
106             final int length, final StorageType storageType) throws ValueException
107     {
108         super(values, unit, length, storageType);
109     }
110 
111     /**
112      * @param data FloatVectorData; an internal data object
113      * @param unit DimensionlessUnit; the unit
114      */
115     MutableFloatDimensionlessVector(final FloatVectorData data, final DimensionlessUnit unit)
116     {
117         super(data, unit);
118     }
119 
120     /** {@inheritDoc} */
121     @Override
122     protected final FloatDimensionlessVector instantiateType(final FloatVectorData dvd, final DimensionlessUnit unit)
123     {
124         return new FloatDimensionlessVector(dvd, unit);
125     }
126 
127     /** {@inheritDoc} */
128     @Override
129     protected final MutableFloatDimensionlessVector instantiateMutableType(final FloatVectorData dvd,
130             final DimensionlessUnit unit)
131     {
132         return new MutableFloatDimensionlessVector(dvd, unit);
133     }
134 
135     /** {@inheritDoc} */
136     @Override
137     protected final FloatDimensionless instantiateScalar(final float value, final DimensionlessUnit unit)
138     {
139         return new FloatDimensionless(value, unit);
140     }
141 
142     /** {@inheritDoc} */
143     @Override
144     public final MutableFloatDimensionlessVector toDense()
145     {
146         return this.data.isDense() ? (MutableFloatDimensionlessVector) this
147                 : instantiateMutableType(this.data.toDense(), getUnit());
148     }
149 
150     /** {@inheritDoc} */
151     @Override
152     public final MutableFloatDimensionlessVector toSparse()
153     {
154         return this.data.isSparse() ? (MutableFloatDimensionlessVector) this
155                 : instantiateMutableType(this.data.toSparse(), getUnit());
156     }
157 
158     /**
159      * Return an array of FloatDimensionless Scalars from this vector.
160      * @return FloatDimensionless[]; an array of FloatDimensionless Scalars from this vector
161      * @throws RuntimeException wrapping a ValueException on error getting one of the values
162      */
163     public FloatDimensionless[] toArray()
164     {
165         FloatDimensionless[] array = new FloatDimensionless[size()];
166         for (int i = 0; i < size(); i++)
167         {
168             try
169             {
170                 array[i] = get(i);
171             }
172             catch (ValueException exception)
173             {
174                 throw new RuntimeException(exception);
175             }
176         }
177         return array;
178     }
179 
180     /** {@inheritDoc} */
181     @Override
182     public final MutableFloatDimensionlessVector acos()
183     {
184         assign(FloatMathFunctions.ACOS);
185         return this;
186     }
187 
188     /** {@inheritDoc} */
189     @Override
190     public final MutableFloatDimensionlessVector asin()
191     {
192         assign(FloatMathFunctions.ASIN);
193         return this;
194     }
195 
196     /** {@inheritDoc} */
197     @Override
198     public final MutableFloatDimensionlessVector atan()
199     {
200         assign(FloatMathFunctions.ATAN);
201         return this;
202     }
203 
204     /** {@inheritDoc} */
205     @Override
206     public final MutableFloatDimensionlessVector cbrt()
207     {
208         assign(FloatMathFunctions.CBRT);
209         return this;
210     }
211 
212     /** {@inheritDoc} */
213     @Override
214     public final MutableFloatDimensionlessVector cos()
215     {
216         assign(FloatMathFunctions.COS);
217         return this;
218     }
219 
220     /** {@inheritDoc} */
221     @Override
222     public final MutableFloatDimensionlessVector cosh()
223     {
224         assign(FloatMathFunctions.COSH);
225         return this;
226     }
227 
228     /** {@inheritDoc} */
229     @Override
230     public final MutableFloatDimensionlessVector exp()
231     {
232         assign(FloatMathFunctions.EXP);
233         return this;
234     }
235 
236     /** {@inheritDoc} */
237     @Override
238     public final MutableFloatDimensionlessVector expm1()
239     {
240         assign(FloatMathFunctions.EXPM1);
241         return this;
242     }
243 
244     /** {@inheritDoc} */
245     @Override
246     public final MutableFloatDimensionlessVector log()
247     {
248         assign(FloatMathFunctions.LOG);
249         return this;
250     }
251 
252     /** {@inheritDoc} */
253     @Override
254     public final MutableFloatDimensionlessVector log10()
255     {
256         assign(FloatMathFunctions.LOG10);
257         return this;
258     }
259 
260     /** {@inheritDoc} */
261     @Override
262     public final MutableFloatDimensionlessVector log1p()
263     {
264         assign(FloatMathFunctions.LOG1P);
265         return this;
266     }
267 
268     /** {@inheritDoc} */
269     @Override
270     public final MutableFloatDimensionlessVector pow(final double x)
271     {
272         assign(FloatMathFunctions.POW((float) x));
273         return this;
274     }
275 
276     /** {@inheritDoc} */
277     @Override
278     public final MutableFloatDimensionlessVector signum()
279     {
280         assign(FloatMathFunctions.SIGNUM);
281         return this;
282     }
283 
284     /** {@inheritDoc} */
285     @Override
286     public final MutableFloatDimensionlessVector sin()
287     {
288         assign(FloatMathFunctions.SIN);
289         return this;
290     }
291 
292     /** {@inheritDoc} */
293     @Override
294     public final MutableFloatDimensionlessVector sinh()
295     {
296         assign(FloatMathFunctions.SINH);
297         return this;
298     }
299 
300     /** {@inheritDoc} */
301     @Override
302     public final MutableFloatDimensionlessVector sqrt()
303     {
304         assign(FloatMathFunctions.SQRT);
305         return this;
306     }
307 
308     /** {@inheritDoc} */
309     @Override
310     public final MutableFloatDimensionlessVector tan()
311     {
312         assign(FloatMathFunctions.TAN);
313         return this;
314     }
315 
316     /** {@inheritDoc} */
317     @Override
318     public final MutableFloatDimensionlessVector tanh()
319     {
320         assign(FloatMathFunctions.TANH);
321         return this;
322     }
323 
324     /** {@inheritDoc} */
325     @Override
326     public final MutableFloatDimensionlessVector inv()
327     {
328         assign(FloatMathFunctions.INV);
329         return this;
330     }
331 
332 }