1 package org.djunits.value.vdouble.vector; 2 3 import java.util.List; 4 import java.util.Map; 5 6 import org.djunits.unit.DensityUnit; 7 import org.djunits.unit.scale.IdentityScale; 8 import org.djunits.value.storage.StorageType; 9 import org.djunits.value.vdouble.scalar.Density; 10 import org.djunits.value.vdouble.vector.base.DoubleVectorRel; 11 import org.djunits.value.vdouble.vector.data.DoubleVectorData; 12 13 import jakarta.annotation.Generated; 14 15 /** 16 * Double DensityVector, a vector of values with a DensityUnit. 17 * <p> 18 * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br> 19 * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>. 20 * </p> 21 * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a> 22 * @author <a href="https://www.tudelft.nl/staff/p.knoppers/">Peter Knoppers</a> 23 */ 24 @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2023-07-23T14:06:38.224104100Z") 25 public class DensityVector extends DoubleVectorRel<DensityUnit, Density, DensityVector> 26 27 { 28 /** */ 29 private static final long serialVersionUID = 20190905L; 30 31 /** 32 * Construct an DensityVector from an internal data object. 33 * @param data DoubleVectorData; the internal data object for the vector 34 * @param displayUnit DensityUnit; the display unit of the vector data 35 */ 36 public DensityVector(final DoubleVectorData data, final DensityUnit displayUnit) 37 { 38 super(data, displayUnit); 39 } 40 41 /* CONSTRUCTORS WITH double[] */ 42 43 /** 44 * Construct an DensityVector from a double[] object. The double values are expressed in the displayUnit, and will be 45 * printed using the displayUnit. 46 * @param data double[]; the data for the vector, expressed in the displayUnit 47 * @param displayUnit DensityUnit; the unit of the values in the data array, and display unit when printing 48 * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Vector 49 */ 50 public DensityVector(final double[] data, final DensityUnit displayUnit, final StorageType storageType) 51 { 52 this(DoubleVectorData.instantiate(data, displayUnit.getScale(), storageType), displayUnit); 53 } 54 55 /** 56 * Construct an DensityVector from a double[] object. The double values are expressed in the displayUnit. Assume that the 57 * StorageType is DENSE since we offer the data as an array. 58 * @param data double[]; the data for the vector 59 * @param displayUnit DensityUnit; the unit of the values in the data array, and display unit when printing 60 */ 61 public DensityVector(final double[] data, final DensityUnit displayUnit) 62 { 63 this(data, displayUnit, StorageType.DENSE); 64 } 65 66 /** 67 * Construct an DensityVector from a double[] object with SI-unit values. 68 * @param data double[]; the data for the vector, in SI units 69 * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Vector 70 */ 71 public DensityVector(final double[] data, final StorageType storageType) 72 { 73 this(data, DensityUnit.SI, storageType); 74 } 75 76 /** 77 * Construct an DensityVector from a double[] object with SI-unit values. Assume that the StorageType is DENSE since we 78 * offer the data as an array. 79 * @param data double[]; the data for the vector, in SI units 80 */ 81 public DensityVector(final double[] data) 82 { 83 this(data, StorageType.DENSE); 84 } 85 86 /* CONSTRUCTORS WITH Density[] */ 87 88 /** 89 * Construct an DensityVector from an array of Density objects. The Density values are each expressed in their own unit, but 90 * will be internally stored as SI values, all expressed in the displayUnit when printing. 91 * @param data Density[]; the data for the vector 92 * @param displayUnit DensityUnit; the display unit of the values when printing 93 * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Vector 94 */ 95 public DensityVector(final Density[] data, final DensityUnit displayUnit, final StorageType storageType) 96 { 97 this(DoubleVectorData.instantiate(data, storageType), displayUnit); 98 } 99 100 /** 101 * Construct an DensityVector from an array of Density objects. The Density values are each expressed in their own unit, but 102 * will be internally stored as SI values, all expressed in the displayUnit when printing. Assume that the StorageType is 103 * DENSE since we offer the data as an array. 104 * @param data Density[]; the data for the vector 105 * @param displayUnit DensityUnit; the display unit of the values when printing 106 */ 107 public DensityVector(final Density[] data, final DensityUnit displayUnit) 108 { 109 this(data, displayUnit, StorageType.DENSE); 110 } 111 112 /** 113 * Construct an DensityVector from an array of Density objects. The Density values are each expressed in their own unit, but 114 * will be internally stored as SI values, and expressed using SI units when printing. since we offer the data as an array. 115 * @param data Density[]; the data for the vector 116 * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Vector 117 */ 118 public DensityVector(final Density[] data, final StorageType storageType) 119 { 120 this(data, DensityUnit.SI, storageType); 121 } 122 123 /** 124 * Construct an DensityVector from an array of Density objects. The Density values are each expressed in their own unit, but 125 * will be internally stored as SI values, and expressed using SI units when printing. Assume that the StorageType is DENSE 126 * since we offer the data as an array. 127 * @param data Density[]; the data for the vector 128 */ 129 public DensityVector(final Density[] data) 130 { 131 this(data, StorageType.DENSE); 132 } 133 134 /* CONSTRUCTORS WITH List<Double> or List<Density> */ 135 136 /** 137 * Construct an DensityVector from a list of Number objects or a list of Density objects. Note that the displayUnit has a 138 * different meaning depending on whether the list contains Number objects (e.g., Double objects) or Density objects. In 139 * case the list contains Number objects, the displayUnit indicates the unit in which the values in the list are expressed, 140 * as well as the unit in which they will be printed. In case the list contains Density objects, each Density has its own 141 * unit, and the displayUnit is just used for printing. The values but will always be internally stored as SI values or base 142 * values, and expressed using the display unit or base unit when printing. 143 * @param data List<Double> or List<Density>; the data for the vector 144 * @param displayUnit DensityUnit; the display unit of the vector data, and the unit of the data points when the data is 145 * expressed as List<Double> or List<Number> in general 146 * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Vector 147 */ 148 public DensityVector(final List<? extends Number> data, final DensityUnit displayUnit, final StorageType storageType) 149 { 150 this(data.size() == 0 ? DoubleVectorData.instantiate(new double[] {}, IdentityScale.SCALE, storageType) 151 : data.get(0) instanceof Density ? DoubleVectorData.instantiate(data, IdentityScale.SCALE, storageType) 152 : DoubleVectorData.instantiate(data, displayUnit.getScale(), storageType), 153 displayUnit); 154 } 155 156 /** 157 * Construct an DensityVector from a list of Number objects or a list of Density objects. Note that the displayUnit has a 158 * different meaning depending on whether the list contains Number objects (e.g., Double objects) or Density objects. In 159 * case the list contains Number objects, the displayUnit indicates the unit in which the values in the list are expressed, 160 * as well as the unit in which they will be printed. In case the list contains Density objects, each Density has its own 161 * unit, and the displayUnit is just used for printing. The values but will always be internally stored as SI values or base 162 * values, and expressed using the display unit or base unit when printing. Assume the storage type is DENSE since we offer 163 * the data as a List. 164 * @param data List<Double> or List<Density>; the data for the vector 165 * @param displayUnit DensityUnit; the display unit of the vector data, and the unit of the data points when the data is 166 * expressed as List<Double> or List<Number> in general 167 */ 168 public DensityVector(final List<? extends Number> data, final DensityUnit displayUnit) 169 { 170 this(data, displayUnit, StorageType.DENSE); 171 } 172 173 /** 174 * Construct an DensityVector from a list of Number objects or a list of Density objects. When data contains numbers such as 175 * Double, assume that they are expressed using SI units. When the data consists of Density objects, they each have their 176 * own unit, but will be printed using SI units or base units. The values but will always be internally stored as SI values 177 * or base values, and expressed using the display unit or base unit when printing. 178 * @param data List<Double> or List<Density>; the data for the vector 179 * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Vector 180 */ 181 public DensityVector(final List<? extends Number> data, final StorageType storageType) 182 { 183 this(data, DensityUnit.SI, storageType); 184 } 185 186 /** 187 * Construct an DensityVector from a list of Number objects or a list of Density objects. When data contains numbers such as 188 * Double, assume that they are expressed using SI units. When the data consists of Density objects, they each have their 189 * own unit, but will be printed using SI units or base units. The values but will always be internally stored as SI values 190 * or base values, and expressed using the display unit or base unit when printing. Assume the storage type is DENSE since 191 * we offer the data as a List. 192 * @param data List<Double> or List<Density>; the data for the vector 193 */ 194 public DensityVector(final List<? extends Number> data) 195 { 196 this(data, StorageType.DENSE); 197 } 198 199 /* CONSTRUCTORS WITH Map<Integer, Double> or Map<Integer, Density> */ 200 201 /** 202 * Construct an DensityVector from a (sparse) map of index values to Number objects or a (sparse) map of index values to of 203 * Density objects. Using index values is particularly useful for sparse vectors. The size parameter indicates the size of 204 * the vector, since the largest index does not have to be part of the map. Note that the displayUnit has a different 205 * meaning depending on whether the map contains Number objects (e.g., Double objects) or Density objects. In case the map 206 * contains Number objects, the displayUnit indicates the unit in which the values in the map are expressed, as well as the 207 * unit in which they will be printed. In case the map contains Density objects, each Density has its own unit, and the 208 * displayUnit is just used for printing. The values but will always be internally stored as SI values or base values, and 209 * expressed using the display unit or base unit when printing. 210 * @param data Map<Integer, Double> or Map<Integer, Density>; the data for the vector 211 * @param size int; the size off the vector, i.e., the highest index 212 * @param displayUnit DensityUnit; the display unit of the vector data, and the unit of the data points when the data is 213 * expressed as List<Double> or List<Number> in general 214 * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Vector 215 */ 216 public DensityVector(final Map<Integer, ? extends Number> data, final int size, final DensityUnit displayUnit, 217 final StorageType storageType) 218 { 219 this(data.size() == 0 ? DoubleVectorData.instantiate(data, size, IdentityScale.SCALE, storageType) 220 : data.values().iterator().next() instanceof Density 221 ? DoubleVectorData.instantiate(data, size, IdentityScale.SCALE, storageType) 222 : DoubleVectorData.instantiate(data, size, displayUnit.getScale(), storageType), 223 displayUnit); 224 } 225 226 /** 227 * Construct an DensityVector from a (sparse) map of index values to Number objects or a (sparse) map of index values to of 228 * Density objects. Using index values is particularly useful for sparse vectors. The size parameter indicates the size of 229 * the vector, since the largest index does not have to be part of the map. Note that the displayUnit has a different 230 * meaning depending on whether the map contains Number objects (e.g., Double objects) or Density objects. In case the map 231 * contains Number objects, the displayUnit indicates the unit in which the values in the map are expressed, as well as the 232 * unit in which they will be printed. In case the map contains Density objects, each Density has its own unit, and the 233 * displayUnit is just used for printing. The values but will always be internally stored as SI values or base values, and 234 * expressed using the display unit or base unit when printing. Assume the storage type is SPARSE since we offer the data as 235 * a Map. 236 * @param data Map<Integer, Double> or Map<Integer, Density>; the data for the vector 237 * @param size int; the size off the vector, i.e., the highest index 238 * @param displayUnit DensityUnit; the display unit of the vector data, and the unit of the data points when the data is 239 * expressed as List<Double> or List<Number> in general 240 */ 241 public DensityVector(final Map<Integer, ? extends Number> data, final int size, final DensityUnit displayUnit) 242 { 243 this(data, size, displayUnit, StorageType.SPARSE); 244 } 245 246 /** 247 * Construct an DensityVector from a (sparse) map of index values to Number objects or a (sparse) map of index values to of 248 * Density objects. Using index values is particularly useful for sparse vectors. The size parameter indicates the size of 249 * the vector, since the largest index does not have to be part of the map. When data contains numbers such as Double, 250 * assume that they are expressed using SI units. When the data consists of Density objects, they each have their own unit, 251 * but will be printed using SI units or base units. The values but will always be internally stored as SI values or base 252 * values, and expressed using the display unit or base unit when printing. 253 * @param data Map<Integer, Double> or Map<Integer, Density>; the data for the vector 254 * @param size int; the size off the vector, i.e., the highest index 255 * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Vector 256 */ 257 public DensityVector(final Map<Integer, ? extends Number> data, final int size, final StorageType storageType) 258 { 259 this(data, size, DensityUnit.SI, storageType); 260 } 261 262 /** 263 * Construct an DensityVector from a (sparse) map of index values to Number objects or a (sparse) map of index values to of 264 * Density objects. Using index values is particularly useful for sparse vectors. The size parameter indicates the size of 265 * the vector, since the largest index does not have to be part of the map. When data contains numbers such as Double, 266 * assume that they are expressed using SI units. When the data consists of Density objects, they each have their own unit, 267 * but will be printed using SI units or base units. The values but will always be internally stored as SI values or base 268 * values, and expressed using the display unit or base unit when printing. Assume the storage type is SPARSE since we offer 269 * the data as a Map. 270 * @param data Map<Integer, Double> or Map<Integer, Density>; the data for the vector 271 * @param size int; the size off the vector, i.e., the highest index 272 */ 273 public DensityVector(final Map<Integer, ? extends Number> data, final int size) 274 { 275 this(data, size, StorageType.SPARSE); 276 } 277 278 /* ****************************** Other methods ****************************** */ 279 280 @Override 281 public Class<Density> getScalarClass() 282 { 283 return Density.class; 284 } 285 286 @Override 287 public DensityVector instantiateVector(final DoubleVectorData dvd, final DensityUnit displayUnit) 288 { 289 return new DensityVector(dvd, displayUnit); 290 } 291 292 @Override 293 public Density instantiateScalarSI(final double valueSI, final DensityUnit displayUnit) 294 { 295 Density result = Density.instantiateSI(valueSI); 296 result.setDisplayUnit(displayUnit); 297 return result; 298 } 299 300 }