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   * Absolute FloatDirection Vector.
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 FloatDirectionVector extends AbstractFloatVectorAbs<DirectionUnit, AngleUnit, FloatDirectionVector,
24          FloatAngleVector, MutableFloatDirectionVector, FloatDirection>
25  {
26      /** */
27      private static final long serialVersionUID = 20151003L;
28  
29      /**
30       * Construct a new Absolute Immutable FloatDirectionVector.
31       * @param values float[]; the values of the entries in the new Absolute Immutable FloatDirectionVector
32       * @param unit DirectionUnit; the unit of the new Absolute Immutable FloatDirectionVector
33       * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
34       * @throws ValueException when values is null
35       */
36      public FloatDirectionVector(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 Immutable FloatDirectionVector.
44       * @param values List&lt;Float&gt;; the values of the entries in the new Absolute Immutable FloatDirectionVector
45       * @param unit DirectionUnit; the unit of the new Absolute Immutable FloatDirectionVector
46       * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
47       * @throws ValueException when values is null
48       */
49      public FloatDirectionVector(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 Immutable FloatDirectionVector.
57       * @param values FloatDirection[]; the values of the entries in the new Absolute Immutable FloatDirectionVector
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 FloatDirectionVector(final FloatDirection[] values, final StorageType storageType) throws ValueException
62      {
63          super(values, storageType);
64      }
65  
66      /**
67       * Construct a new Absolute Immutable FloatDirectionVector.
68       * @param values List&lt;FloatDirection&gt;; the values of the entries in the new Absolute Immutable FloatDirectionVector
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 FloatDirectionVector(final List<FloatDirection> values, final StorageType storageType) throws ValueException
73      {
74          super(values, storageType);
75      }
76  
77      /**
78       * Construct a new Absolute Immutable FloatDirectionVector.
79       * @param values SortedMap&lt;Integer, FloatDirection&gt;; the values of the entries in the new Absolute Sparse Mutable
80       *            FloatDirectionVector
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 FloatDirectionVector(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 Immutable FloatDirectionVector.
93       * @param values SortedMap&lt;Integer, Float&gt;; the map of indexes to values of the Absolute Sparse Mutable
94       *            FloatDirectionVector
95       * @param unit DirectionUnit; the unit of the new Absolute Sparse Mutable FloatDirectionVector
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 FloatDirectionVector(final SortedMap<Integer, Float> values, final DirectionUnit 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 Immutable FloatDirectionVector.
108      * @param data FloatVectorData; an internal data object
109      * @param unit DirectionUnit; the unit
110      */
111     FloatDirectionVector(final FloatVectorData data, final DirectionUnit unit)
112     {
113         super(data, unit);
114     }
115 
116     /** {@inheritDoc} */
117     @Override
118     protected final FloatDirectionVector instantiateTypeAbs(final FloatVectorData dvd, final DirectionUnit unit)
119     {
120         return new FloatDirectionVector(dvd, unit);
121     }
122 
123     /** {@inheritDoc} */
124     @Override
125     protected final FloatAngleVector instantiateTypeRel(final FloatVectorData dvd, final AngleUnit unit)
126     {
127         return new FloatAngleVector(dvd, unit);
128     }
129 
130     /** {@inheritDoc} */
131     @Override
132     protected final MutableFloatDirectionVector instantiateMutableType(final FloatVectorData dvd, final DirectionUnit unit)
133     {
134         return new MutableFloatDirectionVector(dvd, unit);
135     }
136 
137     /** {@inheritDoc} */
138     @Override
139     protected final FloatDirection instantiateScalar(final float value, final DirectionUnit unit)
140     {
141         return new FloatDirection(value, unit);
142     }
143 
144     /** {@inheritDoc} */
145     @Override
146     public final FloatDirectionVector toDense()
147     {
148         return this.data.isDense() ? (FloatDirectionVector) this : instantiateTypeAbs(this.data.toDense(), getUnit());
149     }
150 
151     /** {@inheritDoc} */
152     @Override
153     public final FloatDirectionVector toSparse()
154     {
155         return this.data.isSparse() ? (FloatDirectionVector) this : instantiateTypeAbs(this.data.toSparse(), getUnit());
156     }
157 
158     /**
159      * Return an array of FloatDirection Scalars from this vector.
160      * @return FloatDirection[]; an array of FloatDirection Scalars from this vector
161      * @throws RuntimeException wrapping a ValueException on error getting one of the values
162      */
163     public FloatDirection[] toArray()
164     {
165         FloatDirection[] array = new FloatDirection[size()];
166         for (int i = 0; i < size(); i++)
167         {
168             try
169             {
170                 array[i] = get(i);
171             }
172             catch (ValueException exception)
173             {
174                 throw new RuntimeException(exception);
175             }
176         }
177         return array;
178     }
179 
180 }