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.AbsoluteLinearUnit;
7   import org.djunits.unit.Unit;
8   import org.djunits.value.StorageType;
9   import org.djunits.value.ValueException;
10  import org.djunits.value.vdouble.scalar.DoubleScalar;
11  
12  /**
13   * Immutable DoubleVector.
14   * <p>
15   * Copyright (c) 2015-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
16   * BSD-style license. See <a href="http://djunits.org/docs/license.html">DJUNITS License</a>.
17   * <p>
18   * $LastChangedDate: 2019-01-18 00:35:01 +0100 (Fri, 18 Jan 2019) $, @version $Revision: 324 $, by $Author: averbraeck $,
19   * initial version 30 Oct, 2015 <br>
20   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
21   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
22   */
23  public abstract class DoubleVector
24  {
25      /**
26       * Absolute Immutable DoubleVector.
27       * @param <AU> Absolute unit
28       * @param <RU> Relative unit
29       */
30      public static class Abs<AU extends AbsoluteLinearUnit<AU, RU>, RU extends Unit<RU>> extends AbstractDoubleVectorAbs<AU, RU,
31              DoubleVector.Abs<AU, RU>, DoubleVector.Rel<RU>, MutableDoubleVector.Abs<AU, RU>, DoubleScalar.Abs<AU, RU>>
32      {
33          /**  */
34          private static final long serialVersionUID = 20150626L;
35  
36          /**
37           * Construct a new Absolute Mutable DoubleVector.
38           * @param values double[]; the values of the entries in the new Absolute Mutable DoubleVector
39           * @param unit AU; the unit of the new Absolute Mutable DoubleVector
40           * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
41           * @throws ValueException when values is null
42           */
43          public Abs(final double[] values, final AU unit, final StorageType storageType) throws ValueException
44          {
45              super(values, unit, storageType);
46          }
47  
48          /**
49           * Construct a new Absolute Mutable DoubleVector.
50           * @param values List&lt;Double&gt;; the values of the entries in the new Absolute Mutable DoubleVector
51           * @param unit AU; the unit of the new Absolute Mutable DoubleVector
52           * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
53           * @throws ValueException when values is null
54           */
55          public Abs(final List<Double> values, final AU unit, final StorageType storageType) throws ValueException
56          {
57              super(values, unit, storageType);
58          }
59  
60          /**
61           * Construct a new Absolute Mutable DoubleVector.
62           * @param values DoubleScalar.Abs&lt;AU, RU&gt;[]; the values of the entries in the new Absolute Mutable DoubleVector
63           * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
64           * @throws ValueException when values has zero entries
65           */
66          public Abs(final DoubleScalar.Abs<AU, RU>[] values, final StorageType storageType) throws ValueException
67          {
68              super(values, storageType);
69          }
70  
71          /**
72           * Construct a new Absolute Mutable DoubleVector.
73           * @param values List&lt;DoubleScalar.Abs&lt;AU, RU&gt;&gt;; the values of the entries in the new Absolute Mutable
74           *            DoubleVector
75           * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
76           * @throws ValueException when values has zero entries
77           */
78          public Abs(final List<DoubleScalar.Abs<AU, RU>> values, final StorageType storageType) throws ValueException
79          {
80              super(values, storageType);
81          }
82  
83          /**
84           * Construct a new Absolute Mutable DoubleVector.
85           * @param values SortedMap&lt;Integer, DoubleScalar.Abs&lt;AU, RU&gt;&gt;; the values of the entries in the new Absolute
86           *            Sparse Mutable DoubleVector
87           * @param length int; the size of the vector
88           * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
89           * @throws ValueException when values has zero entries
90           */
91          public Abs(final SortedMap<Integer, DoubleScalar.Abs<AU, RU>> values, final int length, final StorageType storageType)
92                  throws ValueException
93          {
94              super(values, length, storageType);
95          }
96  
97          /**
98           * Construct a new Absolute Mutable DoubleVector.
99           * @param values SortedMap&lt;Integer, Double&gt;; the map of indexes to values of the Absolute Sparse Mutable
100          *            DoubleVector
101          * @param unit AU; the unit of the new Absolute Sparse Mutable DoubleVector
102          * @param length int; the size of the vector
103          * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
104          * @throws ValueException when values is null
105          */
106         public Abs(final SortedMap<Integer, Double> values, final AU unit, final int length, final StorageType storageType)
107                 throws ValueException
108         {
109             super(values, unit, length, storageType);
110         }
111 
112         /**
113          * Construct a new Absolute Mutable DoubleVector.
114          * @param data DoubleVectorData; an internal data object
115          * @param unit AU; the unit
116          */
117         public Abs(final DoubleVectorData data, final AU unit)
118         {
119             super(data, unit);
120         }
121 
122         /** {@inheritDoc} */
123         @Override
124         protected final DoubleVector.Abs<AU, RU> instantiateTypeAbs(final DoubleVectorData dvd, final AU unit)
125         {
126             return new DoubleVector.Abs<AU, RU>(dvd, unit);
127         }
128 
129         /** {@inheritDoc} */
130         @Override
131         protected final DoubleVector.Rel<RU> instantiateTypeRel(final DoubleVectorData dvd, final RU unit)
132         {
133             return new DoubleVector.Rel<RU>(dvd, unit);
134         }
135 
136         /** {@inheritDoc} */
137         @Override
138         protected final MutableDoubleVector.Abs<AU, RU> instantiateMutableType(final DoubleVectorData dvd, final AU unit)
139         {
140             return new MutableDoubleVector.Abs<AU, RU>(dvd, unit);
141         }
142 
143         /** {@inheritDoc} */
144         @Override
145         protected final DoubleScalar.Abs<AU, RU> instantiateScalar(final double value, final AU unit)
146         {
147             return new DoubleScalar.Abs<AU, RU>(value, unit);
148         }
149 
150         /** {@inheritDoc} */
151         @Override
152         public final DoubleVector.Abs<AU, RU> toDense()
153         {
154             return this.data.isDense() ? (DoubleVector.Abs<AU, RU>) this : instantiateTypeAbs(this.data.toDense(), getUnit());
155         }
156 
157         /** {@inheritDoc} */
158         @Override
159         public final DoubleVector.Abs<AU, RU> toSparse()
160         {
161             return this.data.isSparse() ? (DoubleVector.Abs<AU, RU>) this : instantiateTypeAbs(this.data.toSparse(), getUnit());
162         }
163 
164     }
165 
166     /**
167      * Relative Immutable DoubleVector.
168      * @param <U> Unit
169      */
170     public static class Rel<U extends Unit<U>>
171             extends AbstractDoubleVectorRel<U, DoubleVector.Rel<U>, MutableDoubleVector.Rel<U>, DoubleScalar.Rel<U>>
172     {
173         /**  */
174         private static final long serialVersionUID = 20150626L;
175 
176         /**
177          * Construct a new Relative Mutable DoubleVector.
178          * @param values double[]; the values of the entries in the new Relative Mutable DoubleVector
179          * @param unit U; the unit of the new Relative Mutable DoubleVector
180          * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
181          * @throws ValueException when values is null
182          */
183         public Rel(final double[] values, final U unit, final StorageType storageType) throws ValueException
184         {
185             super(values, unit, storageType);
186         }
187 
188         /**
189          * Construct a new Relative Mutable DoubleVector.
190          * @param values List&lt;Double&gt;; the values of the entries in the new Relative Mutable DoubleVector
191          * @param unit U; the unit of the new Relative Mutable DoubleVector
192          * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
193          * @throws ValueException when values is null
194          */
195         public Rel(final List<Double> values, final U unit, final StorageType storageType) throws ValueException
196         {
197             super(values, unit, storageType);
198         }
199 
200         /**
201          * Construct a new Relative Mutable DoubleVector.
202          * @param values DoubleScalar.Rel&lt;U&gt;[]; the values of the entries in the new Relative Mutable DoubleVector
203          * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
204          * @throws ValueException when values has zero entries
205          */
206         public Rel(final DoubleScalar.Rel<U>[] values, final StorageType storageType) throws ValueException
207         {
208             super(values, storageType);
209         }
210 
211         /**
212          * Construct a new Relative Mutable DoubleVector.
213          * @param values List&lt;DoubleScalar.Rel&lt;U&gt;&gt;; the values of the entries in the new Relative Mutable
214          *            DoubleVector
215          * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
216          * @throws ValueException when values has zero entries
217          */
218         public Rel(final List<DoubleScalar.Rel<U>> values, final StorageType storageType) throws ValueException
219         {
220             super(values, storageType);
221         }
222 
223         /**
224          * Construct a new Relative Mutable DoubleVector.
225          * @param values SortedMap&lt;Integer, DoubleScalar.Rel&lt;U&gt;&gt;; the values of the entries in the new Relative
226          *            Sparse Mutable DoubleVector
227          * @param length int; the size of the vector
228          * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
229          * @throws ValueException when values has zero entries
230          */
231         public Rel(final SortedMap<Integer, DoubleScalar.Rel<U>> values, final int length, final StorageType storageType)
232                 throws ValueException
233         {
234             super(values, length, storageType);
235         }
236 
237         /**
238          * Construct a new Relative Mutable DoubleVector.
239          * @param values SortedMap&lt;Integer, Double&gt;; the map of indexes to values of the Relative Sparse Mutable
240          *            DoubleVector
241          * @param unit U; the unit of the new Relative Sparse Mutable DoubleVector
242          * @param length int; the size of the vector
243          * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
244          * @throws ValueException when values is null
245          */
246         public Rel(final SortedMap<Integer, Double> values, final U unit, final int length, final StorageType storageType)
247                 throws ValueException
248         {
249             super(values, unit, length, storageType);
250         }
251 
252         /**
253          * Construct a new Relative Mutable DoubleVector.
254          * @param data DoubleVectorData; an internal data object
255          * @param unit U; the unit
256          */
257         public Rel(final DoubleVectorData data, final U unit)
258         {
259             super(data, unit);
260         }
261 
262         /** {@inheritDoc} */
263         @Override
264         protected final DoubleVector.Rel<U> instantiateType(final DoubleVectorData dvd, final U unit)
265         {
266             return new DoubleVector.Rel<U>(dvd, unit);
267         }
268 
269         /** {@inheritDoc} */
270         @Override
271         protected final MutableDoubleVector.Rel<U> instantiateMutableType(final DoubleVectorData dvd, final U unit)
272         {
273             return new MutableDoubleVector.Rel<U>(dvd, unit);
274         }
275 
276         /** {@inheritDoc} */
277         @Override
278         protected final DoubleScalar.Rel<U> instantiateScalar(final double value, final U unit)
279         {
280             return new DoubleScalar.Rel<U>(value, unit);
281         }
282 
283         /** {@inheritDoc} */
284         @Override
285         public final DoubleVector.Rel<U> toDense()
286         {
287             return this.data.isDense() ? (DoubleVector.Rel<U>) this : instantiateType(this.data.toDense(), getUnit());
288         }
289 
290         /** {@inheritDoc} */
291         @Override
292         public final DoubleVector.Rel<U> toSparse()
293         {
294             return this.data.isSparse() ? (DoubleVector.Rel<U>) this : instantiateType(this.data.toSparse(), getUnit());
295         }
296 
297     }
298 }