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