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