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-2018 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 U; the unit of the new Relative Immutable Float DimensionlessVector
35       * @param 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; the values of the entries in the new Relative Immutable Float DimensionlessVector
47       * @param unit U; the unit of the new Relative Immutable Float DimensionlessVector
48       * @param 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 FloatScalar.Rel&lt;U&gt;[]; the values of the entries in the new Relative Immutable Float
60       *            DimensionlessVector
61       * @param storageType the data type to use (e.g., DENSE or SPARSE)
62       * @throws ValueException when values has zero entries
63       */
64      public MutableFloatDimensionlessVector(final FloatDimensionless[] values, final StorageType storageType)
65              throws ValueException
66      {
67          super(values, storageType);
68      }
69  
70      /**
71       * Construct a new Relative Immutable Float DimensionlessVector.
72       * @param values List; the values of the entries in the new Relative Immutable Float DimensionlessVector
73       * @param 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 FloatScalar.Rel&lt;U&gt;[]; the values of the entries in the new Relative Sparse Mutable Float
85       *            DimensionlessVector
86       * @param length the size of the vector
87       * @param 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 Map; the map of indexes to values of the Relative Sparse Mutable Float DimensionlessVector
99       * @param unit U; the unit of the new Relative Sparse Mutable Float DimensionlessVector
100      * @param length the size of the vector
101      * @param storageType the data type to use (e.g., DENSE or SPARSE)
102      * @throws ValueException when values is null
103      */
104     public MutableFloatDimensionlessVector(final SortedMap<Integer, Float> values, final DimensionlessUnit unit,
105             final int length, final StorageType storageType) throws ValueException
106     {
107         super(values, unit, length, storageType);
108     }
109 
110     /**
111      * @param data an internal data object
112      * @param unit the unit
113      */
114     MutableFloatDimensionlessVector(final FloatVectorData data, final DimensionlessUnit unit)
115     {
116         super(data, unit);
117     }
118 
119     /** {@inheritDoc} */
120     @Override
121     protected final FloatDimensionlessVector instantiateType(final FloatVectorData dvd, final DimensionlessUnit unit)
122     {
123         return new FloatDimensionlessVector(dvd, unit);
124     }
125 
126     /** {@inheritDoc} */
127     @Override
128     protected final MutableFloatDimensionlessVector instantiateMutableType(final FloatVectorData dvd,
129             final DimensionlessUnit unit)
130     {
131         return new MutableFloatDimensionlessVector(dvd, unit);
132     }
133 
134     /** {@inheritDoc} */
135     @Override
136     protected final FloatDimensionless instantiateScalar(final float value, final DimensionlessUnit unit)
137     {
138         return new FloatDimensionless(value, unit);
139     }
140 
141     /** {@inheritDoc} */
142     @Override
143     public final MutableFloatDimensionlessVector toDense()
144     {
145         return this.data.isDense() ? (MutableFloatDimensionlessVector) this
146                 : instantiateMutableType(this.data.toDense(), getUnit());
147     }
148 
149     /** {@inheritDoc} */
150     @Override
151     public final MutableFloatDimensionlessVector toSparse()
152     {
153         return this.data.isSparse() ? (MutableFloatDimensionlessVector) this
154                 : instantiateMutableType(this.data.toSparse(), getUnit());
155     }
156 
157     /**
158      * Return an array of FloatDimensionless Scalars from this vector.
159      * @return FloatDimensionless[]; an array of FloatDimensionless Scalars from this vector
160      * @throws RuntimeException wrapping a ValueException on error getting one of the values
161      */
162     public FloatDimensionless[] toArray()
163     {
164         FloatDimensionless[] array = new FloatDimensionless[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     /** {@inheritDoc} */
180     @Override
181     public final MutableFloatDimensionlessVector acos()
182     {
183         assign(FloatMathFunctions.ACOS);
184         return this;
185     }
186 
187     /** {@inheritDoc} */
188     @Override
189     public final MutableFloatDimensionlessVector asin()
190     {
191         assign(FloatMathFunctions.ASIN);
192         return this;
193     }
194 
195     /** {@inheritDoc} */
196     @Override
197     public final MutableFloatDimensionlessVector atan()
198     {
199         assign(FloatMathFunctions.ATAN);
200         return this;
201     }
202 
203     /** {@inheritDoc} */
204     @Override
205     public final MutableFloatDimensionlessVector cbrt()
206     {
207         assign(FloatMathFunctions.CBRT);
208         return this;
209     }
210 
211     /** {@inheritDoc} */
212     @Override
213     public final MutableFloatDimensionlessVector cos()
214     {
215         assign(FloatMathFunctions.COS);
216         return this;
217     }
218 
219     /** {@inheritDoc} */
220     @Override
221     public final MutableFloatDimensionlessVector cosh()
222     {
223         assign(FloatMathFunctions.COSH);
224         return this;
225     }
226 
227     /** {@inheritDoc} */
228     @Override
229     public final MutableFloatDimensionlessVector exp()
230     {
231         assign(FloatMathFunctions.EXP);
232         return this;
233     }
234 
235     /** {@inheritDoc} */
236     @Override
237     public final MutableFloatDimensionlessVector expm1()
238     {
239         assign(FloatMathFunctions.EXPM1);
240         return this;
241     }
242 
243     /** {@inheritDoc} */
244     @Override
245     public final MutableFloatDimensionlessVector log()
246     {
247         assign(FloatMathFunctions.LOG);
248         return this;
249     }
250 
251     /** {@inheritDoc} */
252     @Override
253     public final MutableFloatDimensionlessVector log10()
254     {
255         assign(FloatMathFunctions.LOG10);
256         return this;
257     }
258 
259     /** {@inheritDoc} */
260     @Override
261     public final MutableFloatDimensionlessVector log1p()
262     {
263         assign(FloatMathFunctions.LOG1P);
264         return this;
265     }
266 
267     /** {@inheritDoc} */
268     @Override
269     public final MutableFloatDimensionlessVector pow(final double x)
270     {
271         assign(FloatMathFunctions.POW((float) x));
272         return this;
273     }
274 
275     /** {@inheritDoc} */
276     @Override
277     public final MutableFloatDimensionlessVector signum()
278     {
279         assign(FloatMathFunctions.SIGNUM);
280         return this;
281     }
282 
283     /** {@inheritDoc} */
284     @Override
285     public final MutableFloatDimensionlessVector sin()
286     {
287         assign(FloatMathFunctions.SIN);
288         return this;
289     }
290 
291     /** {@inheritDoc} */
292     @Override
293     public final MutableFloatDimensionlessVector sinh()
294     {
295         assign(FloatMathFunctions.SINH);
296         return this;
297     }
298 
299     /** {@inheritDoc} */
300     @Override
301     public final MutableFloatDimensionlessVector sqrt()
302     {
303         assign(FloatMathFunctions.SQRT);
304         return this;
305     }
306 
307     /** {@inheritDoc} */
308     @Override
309     public final MutableFloatDimensionlessVector tan()
310     {
311         assign(FloatMathFunctions.TAN);
312         return this;
313     }
314 
315     /** {@inheritDoc} */
316     @Override
317     public final MutableFloatDimensionlessVector tanh()
318     {
319         assign(FloatMathFunctions.TANH);
320         return this;
321     }
322 
323     /** {@inheritDoc} */
324     @Override
325     public final MutableFloatDimensionlessVector inv()
326     {
327         assign(FloatMathFunctions.INV);
328         return this;
329     }
330 
331 }