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