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