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.DimensionlessUnit;
7   import org.djunits.value.MathFunctionsDimensionless;
8   import org.djunits.value.StorageType;
9   import org.djunits.value.ValueException;
10  import org.djunits.value.vdouble.DoubleMathFunctions;
11  import org.djunits.value.vdouble.scalar.Dimensionless;
12  
13  /**
14   * Mutable Double 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 MutableDimensionlessVector extends
25          AbstractMutableDoubleVectorRel<DimensionlessUnit, DimensionlessVector, MutableDimensionlessVector, Dimensionless>
26          implements MathFunctionsDimensionless<MutableDimensionlessVector>
27  {
28      /** */
29      private static final long serialVersionUID = 20151109L;
30  
31      /**
32       * Construct a new Relative Immutable Double DimensionlessVector.
33       * @param values double[]; the values of the entries in the new Relative Immutable Double DimensionlessVector
34       * @param unit DimensionlessUnit; the unit of the new Relative Immutable Double 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 MutableDimensionlessVector(final double[] 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 Double DimensionlessVector.
46       * @param values List&lt;Double&gt;; the values of the entries in the new Relative Immutable Double DimensionlessVector
47       * @param unit DimensionlessUnit; the unit of the new Relative Immutable Double 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 MutableDimensionlessVector(final List<Double> values, final DimensionlessUnit unit, final StorageType storageType)
52              throws ValueException
53      {
54          super(values, unit, storageType);
55      }
56  
57      /**
58       * Construct a new Relative Immutable Double DimensionlessVector.
59       * @param values Dimensionless[]; the values of the entries in the new Relative Immutable Double 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 MutableDimensionlessVector(final Dimensionless[] values, final StorageType storageType) throws ValueException
64      {
65          super(values, storageType);
66      }
67  
68      /**
69       * Construct a new Relative Immutable Double DimensionlessVector.
70       * @param values List&lt;Dimensionless&gt;; the values of the entries in the new Relative Immutable Double
71       *            DimensionlessVector
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 MutableDimensionlessVector(final List<Dimensionless> values, final StorageType storageType) throws ValueException
76      {
77          super(values, storageType);
78      }
79  
80      /**
81       * Construct a new Relative Immutable Double DimensionlessVector.
82       * @param values SortedMap&lt;Integer, Dimensionless&gt;; the values of the entries in the new Relative Sparse Mutable
83       *            Double DimensionlessVector
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 MutableDimensionlessVector(final SortedMap<Integer, Dimensionless> 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 Double DimensionlessVector.
96       * @param values SortedMap&lt;Integer, Double&gt;; the map of indexes to values of the Relative Sparse Mutable Double
97       *            DimensionlessVector
98       * @param unit DimensionlessUnit; the unit of the new Relative Sparse Mutable Double DimensionlessVector
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 MutableDimensionlessVector(final SortedMap<Integer, Double> values, final DimensionlessUnit unit, final int length,
104             final StorageType storageType) throws ValueException
105     {
106         super(values, unit, length, storageType);
107     }
108 
109     /**
110      * @param data DoubleVectorData; an internal data object
111      * @param unit DimensionlessUnit; the unit
112      */
113     MutableDimensionlessVector(final DoubleVectorData data, final DimensionlessUnit unit)
114     {
115         super(data, unit);
116     }
117 
118     /** {@inheritDoc} */
119     @Override
120     protected final DimensionlessVector instantiateType(final DoubleVectorData dvd, final DimensionlessUnit unit)
121     {
122         return new DimensionlessVector(dvd, unit);
123     }
124 
125     /** {@inheritDoc} */
126     @Override
127     protected final MutableDimensionlessVector instantiateMutableType(final DoubleVectorData dvd, final DimensionlessUnit unit)
128     {
129         return new MutableDimensionlessVector(dvd, unit);
130     }
131 
132     /** {@inheritDoc} */
133     @Override
134     protected final Dimensionless instantiateScalar(final double value, final DimensionlessUnit unit)
135     {
136         return new Dimensionless(value, unit);
137     }
138 
139     /** {@inheritDoc} */
140     @Override
141     public final MutableDimensionlessVector toDense()
142     {
143         return this.data.isDense() ? (MutableDimensionlessVector) this : instantiateMutableType(this.data.toDense(), getUnit());
144     }
145 
146     /** {@inheritDoc} */
147     @Override
148     public final MutableDimensionlessVector toSparse()
149     {
150         return this.data.isSparse() ? (MutableDimensionlessVector) this
151                 : instantiateMutableType(this.data.toSparse(), getUnit());
152     }
153 
154     /**
155      * Return an array of Dimensionless Scalars from this vector.
156      * @return Dimensionless[]; an array of Dimensionless Scalars from this vector
157      * @throws RuntimeException wrapping a ValueException on error getting one of the values
158      */
159     public Dimensionless[] toArray()
160     {
161         Dimensionless[] array = new Dimensionless[size()];
162         for (int i = 0; i < size(); i++)
163         {
164             try
165             {
166                 array[i] = get(i);
167             }
168             catch (ValueException exception)
169             {
170                 throw new RuntimeException(exception);
171             }
172         }
173         return array;
174     }
175 
176     /** {@inheritDoc} */
177     @Override
178     public final MutableDimensionlessVector acos()
179     {
180         assign(DoubleMathFunctions.ACOS);
181         return this;
182     }
183 
184     /** {@inheritDoc} */
185     @Override
186     public final MutableDimensionlessVector asin()
187     {
188         assign(DoubleMathFunctions.ASIN);
189         return this;
190     }
191 
192     /** {@inheritDoc} */
193     @Override
194     public final MutableDimensionlessVector atan()
195     {
196         assign(DoubleMathFunctions.ATAN);
197         return this;
198     }
199 
200     /** {@inheritDoc} */
201     @Override
202     public final MutableDimensionlessVector cbrt()
203     {
204         assign(DoubleMathFunctions.CBRT);
205         return this;
206     }
207 
208     /** {@inheritDoc} */
209     @Override
210     public final MutableDimensionlessVector cos()
211     {
212         assign(DoubleMathFunctions.COS);
213         return this;
214     }
215 
216     /** {@inheritDoc} */
217     @Override
218     public final MutableDimensionlessVector cosh()
219     {
220         assign(DoubleMathFunctions.COSH);
221         return this;
222     }
223 
224     /** {@inheritDoc} */
225     @Override
226     public final MutableDimensionlessVector exp()
227     {
228         assign(DoubleMathFunctions.EXP);
229         return this;
230     }
231 
232     /** {@inheritDoc} */
233     @Override
234     public final MutableDimensionlessVector expm1()
235     {
236         assign(DoubleMathFunctions.EXPM1);
237         return this;
238     }
239 
240     /** {@inheritDoc} */
241     @Override
242     public final MutableDimensionlessVector log()
243     {
244         assign(DoubleMathFunctions.LOG);
245         return this;
246     }
247 
248     /** {@inheritDoc} */
249     @Override
250     public final MutableDimensionlessVector log10()
251     {
252         assign(DoubleMathFunctions.LOG10);
253         return this;
254     }
255 
256     /** {@inheritDoc} */
257     @Override
258     public final MutableDimensionlessVector log1p()
259     {
260         assign(DoubleMathFunctions.LOG1P);
261         return this;
262     }
263 
264     /** {@inheritDoc} */
265     @Override
266     public final MutableDimensionlessVector pow(final double x)
267     {
268         assign(DoubleMathFunctions.POW((float) x));
269         return this;
270     }
271 
272     /** {@inheritDoc} */
273     @Override
274     public final MutableDimensionlessVector signum()
275     {
276         assign(DoubleMathFunctions.SIGNUM);
277         return this;
278     }
279 
280     /** {@inheritDoc} */
281     @Override
282     public final MutableDimensionlessVector sin()
283     {
284         assign(DoubleMathFunctions.SIN);
285         return this;
286     }
287 
288     /** {@inheritDoc} */
289     @Override
290     public final MutableDimensionlessVector sinh()
291     {
292         assign(DoubleMathFunctions.SINH);
293         return this;
294     }
295 
296     /** {@inheritDoc} */
297     @Override
298     public final MutableDimensionlessVector sqrt()
299     {
300         assign(DoubleMathFunctions.SQRT);
301         return this;
302     }
303 
304     /** {@inheritDoc} */
305     @Override
306     public final MutableDimensionlessVector tan()
307     {
308         assign(DoubleMathFunctions.TAN);
309         return this;
310     }
311 
312     /** {@inheritDoc} */
313     @Override
314     public final MutableDimensionlessVector tanh()
315     {
316         assign(DoubleMathFunctions.TANH);
317         return this;
318     }
319 
320     /** {@inheritDoc} */
321     @Override
322     public final MutableDimensionlessVector inv()
323     {
324         assign(DoubleMathFunctions.INV);
325         return this;
326     }
327 
328 }