1 package org.djunits.value.vdouble.vector; 2 3 import java.util.List; 4 import java.util.Map; 5 6 import org.djunits.unit.DurationUnit; 7 import org.djunits.unit.TimeUnit; 8 import org.djunits.unit.scale.IdentityScale; 9 import org.djunits.value.storage.StorageType; 10 import org.djunits.value.vdouble.scalar.Duration; 11 import org.djunits.value.vdouble.scalar.Time; 12 import org.djunits.value.vdouble.vector.base.DoubleVectorRelWithAbs; 13 import org.djunits.value.vdouble.vector.data.DoubleVectorData; 14 15 import jakarta.annotation.Generated; 16 17 /** 18 * Double DurationVector, a vector of values with a DurationUnit. 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 DurationVector extends DoubleVectorRelWithAbs<TimeUnit, Time, TimeVector, DurationUnit, Duration, DurationVector> 28 { 29 /** */ 30 private static final long serialVersionUID = 20190905L; 31 32 /** 33 * Construct an DurationVector from an internal data object. 34 * @param data DoubleVectorData; the internal data object for the vector 35 * @param displayUnit DurationUnit; the display unit of the vector data 36 */ 37 public DurationVector(final DoubleVectorData data, final DurationUnit displayUnit) 38 { 39 super(data, displayUnit); 40 } 41 42 /* CONSTRUCTORS WITH double[] */ 43 44 /** 45 * Construct an DurationVector 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 DurationUnit; 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 DurationVector(final double[] data, final DurationUnit displayUnit, final StorageType storageType) 52 { 53 this(DoubleVectorData.instantiate(data, displayUnit.getScale(), storageType), displayUnit); 54 } 55 56 /** 57 * Construct an DurationVector 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 DurationUnit; the unit of the values in the data array, and display unit when printing 61 */ 62 public DurationVector(final double[] data, final DurationUnit displayUnit) 63 { 64 this(data, displayUnit, StorageType.DENSE); 65 } 66 67 /** 68 * Construct an DurationVector 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 DurationVector(final double[] data, final StorageType storageType) 73 { 74 this(data, DurationUnit.SI, storageType); 75 } 76 77 /** 78 * Construct an DurationVector 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 DurationVector(final double[] data) 83 { 84 this(data, StorageType.DENSE); 85 } 86 87 /* CONSTRUCTORS WITH Duration[] */ 88 89 /** 90 * Construct an DurationVector from an array of Duration objects. The Duration 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 Duration[]; the data for the vector 93 * @param displayUnit DurationUnit; 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 DurationVector(final Duration[] data, final DurationUnit displayUnit, final StorageType storageType) 97 { 98 this(DoubleVectorData.instantiate(data, storageType), displayUnit); 99 } 100 101 /** 102 * Construct an DurationVector from an array of Duration objects. The Duration 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 Duration[]; the data for the vector 106 * @param displayUnit DurationUnit; the display unit of the values when printing 107 */ 108 public DurationVector(final Duration[] data, final DurationUnit displayUnit) 109 { 110 this(data, displayUnit, StorageType.DENSE); 111 } 112 113 /** 114 * Construct an DurationVector from an array of Duration objects. The Duration 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 Duration[]; the data for the vector 118 * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Vector 119 */ 120 public DurationVector(final Duration[] data, final StorageType storageType) 121 { 122 this(data, DurationUnit.SI, storageType); 123 } 124 125 /** 126 * Construct an DurationVector from an array of Duration objects. The Duration 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 Duration[]; the data for the vector 130 */ 131 public DurationVector(final Duration[] data) 132 { 133 this(data, StorageType.DENSE); 134 } 135 136 /* CONSTRUCTORS WITH List<Double> or List<Duration> */ 137 138 /** 139 * Construct an DurationVector from a list of Number objects or a list of Duration objects. Note that the displayUnit has a 140 * different meaning depending on whether the list contains Number objects (e.g., Double objects) or Duration 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 Duration objects, each Duration 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<Duration>; the data for the vector 146 * @param displayUnit DurationUnit; 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 DurationVector(final List<? extends Number> data, final DurationUnit displayUnit, final StorageType storageType) 151 { 152 this(data.size() == 0 ? DoubleVectorData.instantiate(new double[] {}, IdentityScale.SCALE, storageType) 153 : data.get(0) instanceof Duration ? DoubleVectorData.instantiate(data, IdentityScale.SCALE, storageType) 154 : DoubleVectorData.instantiate(data, displayUnit.getScale(), storageType), 155 displayUnit); 156 } 157 158 /** 159 * Construct an DurationVector from a list of Number objects or a list of Duration objects. Note that the displayUnit has a 160 * different meaning depending on whether the list contains Number objects (e.g., Double objects) or Duration 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 Duration objects, each Duration 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<Duration>; the data for the vector 167 * @param displayUnit DurationUnit; 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 DurationVector(final List<? extends Number> data, final DurationUnit displayUnit) 171 { 172 this(data, displayUnit, StorageType.DENSE); 173 } 174 175 /** 176 * Construct an DurationVector from a list of Number objects or a list of Duration objects. When data contains numbers such 177 * as Double, assume that they are expressed using SI units. When the data consists of Duration 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<Duration>; the data for the vector 181 * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Vector 182 */ 183 public DurationVector(final List<? extends Number> data, final StorageType storageType) 184 { 185 this(data, DurationUnit.SI, storageType); 186 } 187 188 /** 189 * Construct an DurationVector from a list of Number objects or a list of Duration objects. When data contains numbers such 190 * as Double, assume that they are expressed using SI units. When the data consists of Duration 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<Duration>; the data for the vector 195 */ 196 public DurationVector(final List<? extends Number> data) 197 { 198 this(data, StorageType.DENSE); 199 } 200 201 /* CONSTRUCTORS WITH Map<Integer, Double> or Map<Integer, Duration> */ 202 203 /** 204 * Construct an DurationVector from a (sparse) map of index values to Number objects or a (sparse) map of index values to of 205 * Duration 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 Duration 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 Duration objects, each Duration 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, Duration>; the data for the vector 213 * @param size int; the size off the vector, i.e., the highest index 214 * @param displayUnit DurationUnit; 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 DurationVector(final Map<Integer, ? extends Number> data, final int size, final DurationUnit displayUnit, 219 final StorageType storageType) 220 { 221 this(data.size() == 0 ? DoubleVectorData.instantiate(data, size, IdentityScale.SCALE, storageType) 222 : data.values().iterator().next() instanceof Duration 223 ? DoubleVectorData.instantiate(data, size, IdentityScale.SCALE, storageType) 224 : DoubleVectorData.instantiate(data, size, displayUnit.getScale(), storageType), 225 displayUnit); 226 } 227 228 /** 229 * Construct an DurationVector from a (sparse) map of index values to Number objects or a (sparse) map of index values to of 230 * Duration 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 Duration 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 Duration objects, each Duration 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, Duration>; the data for the vector 239 * @param size int; the size off the vector, i.e., the highest index 240 * @param displayUnit DurationUnit; 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 DurationVector(final Map<Integer, ? extends Number> data, final int size, final DurationUnit displayUnit) 244 { 245 this(data, size, displayUnit, StorageType.SPARSE); 246 } 247 248 /** 249 * Construct an DurationVector from a (sparse) map of index values to Number objects or a (sparse) map of index values to of 250 * Duration 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 Duration 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, Duration>; 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 DurationVector(final Map<Integer, ? extends Number> data, final int size, final StorageType storageType) 260 { 261 this(data, size, DurationUnit.SI, storageType); 262 } 263 264 /** 265 * Construct an DurationVector from a (sparse) map of index values to Number objects or a (sparse) map of index values to of 266 * Duration 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 Duration 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, Duration>; the data for the vector 273 * @param size int; the size off the vector, i.e., the highest index 274 */ 275 public DurationVector(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<Duration> getScalarClass() 284 { 285 return Duration.class; 286 } 287 288 @Override 289 public DurationVector instantiateVector(final DoubleVectorData dvd, final DurationUnit displayUnit) 290 { 291 return new DurationVector(dvd, displayUnit); 292 } 293 294 @Override 295 public Duration instantiateScalarSI(final double valueSI, final DurationUnit displayUnit) 296 { 297 Duration result = Duration.instantiateSI(valueSI); 298 result.setDisplayUnit(displayUnit); 299 return result; 300 } 301 302 @Override 303 public TimeVector instantiateVectorAbs(final DoubleVectorData dvd, final TimeUnit displayUnit) 304 { 305 return new TimeVector(dvd, displayUnit); 306 } 307 308 @Override 309 public Time instantiateScalarAbsSI(final double valueSI, final TimeUnit displayUnit) 310 { 311 Time result = Time.instantiateSI(valueSI); 312 result.setDisplayUnit(displayUnit); 313 return result; 314 } 315 316 }