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.LengthUnit;
7   import org.djunits.value.StorageType;
8   import org.djunits.value.ValueException;
9   import org.djunits.value.vdouble.scalar.Length;
10  
11  /**
12   * Mutable Relative Length Vector.
13   * <p>
14   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15   * BSD-style license. See <a href="http://djunits.org/docs/license.html">DJUNITS License</a>.
16   * <p>
17   * $LastChangedDate: 2015-09-29 14:14:28 +0200 (Tue, 29 Sep 2015) $, @version $Revision: 73 $, by $Author: pknoppers $, initial
18   * version Sep 5, 2015 <br>
19   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
20   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
21   */
22  public class MutableLengthVector extends AbstractMutableDoubleVectorRel<LengthUnit, LengthVector, MutableLengthVector, Length>
23  {
24      /** */
25      private static final long serialVersionUID = 20151006L;
26  
27      /**
28       * Construct a new Relative Mutable Double LengthVector.
29       * @param values double[]; the values of the entries in the new Relative Mutable Double LengthVector
30       * @param unit LengthUnit; the unit of the new Relative Mutable Double LengthVector
31       * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
32       * @throws ValueException when values is null
33       */
34      public MutableLengthVector(final double[] values, final LengthUnit unit, final StorageType storageType)
35              throws ValueException
36      {
37          super(values, unit, storageType);
38      }
39  
40      /**
41       * Construct a new Relative Mutable Double LengthVector.
42       * @param values List&lt;Double&gt;; the values of the entries in the new Relative Mutable Double LengthVector
43       * @param unit LengthUnit; the unit of the new Relative Mutable Double LengthVector
44       * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
45       * @throws ValueException when values is null
46       */
47      public MutableLengthVector(final List<Double> values, final LengthUnit unit, final StorageType storageType)
48              throws ValueException
49      {
50          super(values, unit, storageType);
51      }
52  
53      /**
54       * Construct a new Relative Mutable Double LengthVector.
55       * @param values Length[]; the values of the entries in the new Relative Mutable Double LengthVector
56       * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
57       * @throws ValueException when values has zero entries
58       */
59      public MutableLengthVector(final Length[] values, final StorageType storageType) throws ValueException
60      {
61          super(values, storageType);
62      }
63  
64      /**
65       * Construct a new Relative Mutable Double LengthVector.
66       * @param values List&lt;Length&gt;; the values of the entries in the new Relative Mutable Double LengthVector
67       * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
68       * @throws ValueException when values has zero entries
69       */
70      public MutableLengthVector(final List<Length> values, final StorageType storageType) throws ValueException
71      {
72          super(values, storageType);
73      }
74  
75      /**
76       * Construct a new Relative Mutable Double LengthVector.
77       * @param values SortedMap&lt;Integer, Length&gt;; the values of the entries in the new Relative Sparse Mutable Double
78       *            LengthVector
79       * @param length int; the size of the vector
80       * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
81       * @throws ValueException when values has zero entries
82       */
83      public MutableLengthVector(final SortedMap<Integer, Length> values, final int length, final StorageType storageType)
84              throws ValueException
85      {
86          super(values, length, storageType);
87      }
88  
89      /**
90       * Construct a new Relative Mutable Double LengthVector.
91       * @param values SortedMap&lt;Integer, Double&gt;; the map of indexes to values of the Relative Sparse Mutable Double
92       *            LengthVector
93       * @param unit LengthUnit; the unit of the new Relative Sparse Mutable Double LengthVector
94       * @param length int; the size of the vector
95       * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE)
96       * @throws ValueException when values is null
97       */
98      public MutableLengthVector(final SortedMap<Integer, Double> values, final LengthUnit unit, final int length,
99              final StorageType storageType) throws ValueException
100     {
101         super(values, unit, length, storageType);
102     }
103 
104     /**
105      * Construct a new Relative Mutable Double LengthVector.
106      * @param data DoubleVectorData; an internal data object
107      * @param unit LengthUnit; the unit
108      */
109     MutableLengthVector(final DoubleVectorData data, final LengthUnit unit)
110     {
111         super(data, unit);
112     }
113 
114     /** {@inheritDoc} */
115     @Override
116     protected final LengthVector instantiateType(final DoubleVectorData dvd, final LengthUnit unit)
117     {
118         return new LengthVector(dvd, unit);
119     }
120 
121     /** {@inheritDoc} */
122     @Override
123     protected final MutableLengthVector instantiateMutableType(final DoubleVectorData dvd, final LengthUnit unit)
124     {
125         return new MutableLengthVector(dvd, unit);
126     }
127 
128     /** {@inheritDoc} */
129     @Override
130     protected final Length instantiateScalar(final double value, final LengthUnit unit)
131     {
132         return new Length(value, unit);
133     }
134 
135     /** {@inheritDoc} */
136     @Override
137     public final MutableLengthVector toDense()
138     {
139         return this.data.isDense() ? (MutableLengthVector) this : instantiateMutableType(this.data.toDense(), getUnit());
140     }
141 
142     /** {@inheritDoc} */
143     @Override
144     public final MutableLengthVector toSparse()
145     {
146         return this.data.isSparse() ? (MutableLengthVector) this : instantiateMutableType(this.data.toSparse(), getUnit());
147     }
148 
149     /**
150      * Return an array of Length Scalars from this vector.
151      * @return Length[]; an array of Length Scalars from this vector
152      * @throws RuntimeException wrapping a ValueException on error getting one of the values
153      */
154     public Length[] toArray()
155     {
156         Length[] array = new Length[size()];
157         for (int i = 0; i < size(); i++)
158         {
159             try
160             {
161                 array[i] = get(i);
162             }
163             catch (ValueException exception)
164             {
165                 throw new RuntimeException(exception);
166             }
167         }
168         return array;
169     }
170 
171 }