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