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.LengthUnit;
7   import org.djunits.unit.PositionUnit;
8   import org.djunits.value.StorageType;
9   import org.djunits.value.ValueException;
10  import org.djunits.value.vfloat.scalar.FloatPosition;
11  
12  /**
13   * Mutable Absolute FloatPosition Vector a vector of values with a PositionUnit.
14   * <p>
15   * Copyright (c) 2013-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: 2015-09-29 14:14:28 +0200 (Tue, 29 Sep 2015) $, @version $Revision: 73 $, by $Author: pknoppers $, initial
19   * version Sep 5, 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 class MutableFloatPositionVector extends AbstractMutableFloatVectorAbs<PositionUnit, LengthUnit, FloatPositionVector,
24          FloatLengthVector, MutableFloatPositionVector, FloatPosition>
25  {
26      /** */
27      private static final long serialVersionUID = 20151003L;
28  
29      /**
30       * Construct a new Absolute Mutable FloatPositionVector.
31       * @param values float[]; the values of the entries in the new Absolute Mutable FloatPositionVector
32       * @param unit PositionUnit; the unit of the new Absolute Mutable FloatPositionVector
33       * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
34       * @throws ValueException when values is null
35       */
36      public MutableFloatPositionVector(final float[] values, final PositionUnit unit, final StorageType storageType)
37              throws ValueException
38      {
39          super(values, unit, storageType);
40      }
41  
42      /**
43       * Construct a new Absolute Mutable FloatPositionVector.
44       * @param values List&lt;Float&gt;; the values of the entries in the new Absolute Mutable FloatPositionVector
45       * @param unit PositionUnit; the unit of the new Absolute Mutable FloatPositionVector
46       * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
47       * @throws ValueException when values is null
48       */
49      public MutableFloatPositionVector(final List<Float> values, final PositionUnit unit, final StorageType storageType)
50              throws ValueException
51      {
52          super(values, unit, storageType);
53      }
54  
55      /**
56       * Construct a new Absolute Mutable FloatPositionVector.
57       * @param values FloatPosition[]; the values of the entries in the new Absolute Mutable FloatPositionVector
58       * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
59       * @throws ValueException when values has zero entries
60       */
61      public MutableFloatPositionVector(final FloatPosition[] values, final StorageType storageType) throws ValueException
62      {
63          super(values, storageType);
64      }
65  
66      /**
67       * Construct a new Absolute Mutable FloatPositionVector.
68       * @param values List&lt;FloatPosition&gt;; the values of the entries in the new Absolute Mutable FloatPositionVector
69       * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
70       * @throws ValueException when values has zero entries
71       */
72      public MutableFloatPositionVector(final List<FloatPosition> values, final StorageType storageType) throws ValueException
73      {
74          super(values, storageType);
75      }
76  
77      /**
78       * Construct a new Absolute Mutable FloatPositionVector.
79       * @param values SortedMap&lt;Integer, FloatPosition&gt;; the values of the entries in the new Absolute Sparse Mutable
80       *            FloatPositionVector
81       * @param length int; the size of the vector
82       * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
83       * @throws ValueException when values has zero entries
84       */
85      public MutableFloatPositionVector(final SortedMap<Integer, FloatPosition> values, final int length,
86              final StorageType storageType) throws ValueException
87      {
88          super(values, length, storageType);
89      }
90  
91      /**
92       * Construct a new Absolute Mutable FloatPositionVector.
93       * @param values SortedMap&lt;Integer, Float&gt;; the map of indexes to values of the Absolute Sparse Mutable
94       *            FloatPositionVector
95       * @param unit PositionUnit; the unit of the new Absolute Sparse Mutable FloatPositionVector
96       * @param length int; the size of the vector
97       * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
98       * @throws ValueException when values is null
99       */
100     public MutableFloatPositionVector(final SortedMap<Integer, Float> values, final PositionUnit unit, final int length,
101             final StorageType storageType) throws ValueException
102     {
103         super(values, unit, length, storageType);
104     }
105 
106     /**
107      * Construct a new Absolute Mutable FloatPositionVector.
108      * @param data FloatVectorData; an internal data object
109      * @param unit PositionUnit; the unit
110      */
111     MutableFloatPositionVector(final FloatVectorData data, final PositionUnit unit)
112     {
113         super(data, unit);
114     }
115 
116     /** {@inheritDoc} */
117     @Override
118     protected final FloatPositionVector instantiateTypeAbs(final FloatVectorData dvd, final PositionUnit unit)
119     {
120         return new FloatPositionVector(dvd, unit);
121     }
122 
123     /** {@inheritDoc} */
124     @Override
125     protected final FloatLengthVector instantiateTypeRel(final FloatVectorData dvd, final LengthUnit unit)
126     {
127         return new FloatLengthVector(dvd, unit);
128     }
129 
130     /** {@inheritDoc} */
131     @Override
132     protected final MutableFloatPositionVector instantiateMutableType(final FloatVectorData dvd, final PositionUnit unit)
133     {
134         return new MutableFloatPositionVector(dvd, unit);
135     }
136 
137     /** {@inheritDoc} */
138     @Override
139     protected final FloatPosition instantiateScalar(final float value, final PositionUnit unit)
140     {
141         return new FloatPosition(value, unit);
142     }
143 
144     /** {@inheritDoc} */
145     @Override
146     public final MutableFloatPositionVector toDense()
147     {
148         return this.data.isDense() ? (MutableFloatPositionVector) this : instantiateMutableType(this.data.toDense(), getUnit());
149     }
150 
151     /** {@inheritDoc} */
152     @Override
153     public final MutableFloatPositionVector toSparse()
154     {
155         return this.data.isSparse() ? (MutableFloatPositionVector) this
156                 : instantiateMutableType(this.data.toSparse(), getUnit());
157     }
158 
159     /**
160      * Return an array of FloatPosition Scalars from this vector.
161      * @return FloatPosition[]; an array of FloatPosition Scalars from this vector
162      * @throws RuntimeException wrapping a ValueException on error getting one of the values
163      */
164     public FloatPosition[] toArray()
165     {
166         FloatPosition[] array = new FloatPosition[size()];
167         for (int i = 0; i < size(); i++)
168         {
169             try
170             {
171                 array[i] = get(i);
172             }
173             catch (ValueException exception)
174             {
175                 throw new RuntimeException(exception);
176             }
177         }
178         return array;
179     }
180 
181 }