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.DoubleVectorAbs; 13 import org.djunits.value.vdouble.vector.data.DoubleVectorData; 14 15 import jakarta.annotation.Generated; 16 17 /** 18 * Double TimeVector, a vector of values with a TimeUnit. 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 TimeVector extends DoubleVectorAbs<TimeUnit, Time, TimeVector, DurationUnit, Duration, DurationVector> 28 { 29 /** */ 30 private static final long serialVersionUID = 20190905L; 31 32 /** 33 * Construct an TimeVector from an internal data object. 34 * @param data DoubleVectorData; the internal data object for the vector 35 * @param displayUnit TimeUnit; the display unit of the vector data 36 */ 37 public TimeVector(final DoubleVectorData data, final TimeUnit displayUnit) 38 { 39 super(data, displayUnit); 40 } 41 42 /* CONSTRUCTORS WITH double[] */ 43 44 /** 45 * Construct an TimeVector from a double[] object. The double values are expressed in the displayUnit, and will be printed 46 * using the displayUnit. 47 * @param data double[]; the data for the vector, expressed in the displayUnit 48 * @param displayUnit TimeUnit; 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 TimeVector(final double[] data, final TimeUnit displayUnit, final StorageType storageType) 52 { 53 this(DoubleVectorData.instantiate(data, displayUnit.getScale(), storageType), displayUnit); 54 } 55 56 /** 57 * Construct an TimeVector 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 TimeUnit; the unit of the values in the data array, and display unit when printing 61 */ 62 public TimeVector(final double[] data, final TimeUnit displayUnit) 63 { 64 this(data, displayUnit, StorageType.DENSE); 65 } 66 67 /** 68 * Construct an TimeVector 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 TimeVector(final double[] data, final StorageType storageType) 73 { 74 this(data, TimeUnit.DEFAULT, storageType); 75 } 76 77 /** 78 * Construct an TimeVector from a double[] object with SI-unit values. Assume that the StorageType is DENSE since we offer 79 * the data as an array. 80 * @param data double[]; the data for the vector, in SI units 81 */ 82 public TimeVector(final double[] data) 83 { 84 this(data, StorageType.DENSE); 85 } 86 87 /* CONSTRUCTORS WITH Time[] */ 88 89 /** 90 * Construct an TimeVector from an array of Time objects. The Time values are each expressed in their own unit, but will be 91 * internally stored as SI values, all expressed in the displayUnit when printing. 92 * @param data Time[]; the data for the vector 93 * @param displayUnit TimeUnit; 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 TimeVector(final Time[] data, final TimeUnit displayUnit, final StorageType storageType) 97 { 98 this(DoubleVectorData.instantiate(data, storageType), displayUnit); 99 } 100 101 /** 102 * Construct an TimeVector from an array of Time objects. The Time values are each expressed in their own unit, but will be 103 * internally stored as SI values, all expressed in the displayUnit when printing. Assume that the StorageType is DENSE 104 * since we offer the data as an array. 105 * @param data Time[]; the data for the vector 106 * @param displayUnit TimeUnit; the display unit of the values when printing 107 */ 108 public TimeVector(final Time[] data, final TimeUnit displayUnit) 109 { 110 this(data, displayUnit, StorageType.DENSE); 111 } 112 113 /** 114 * Construct an TimeVector from an array of Time objects. The Time values are each expressed in their own unit, but will be 115 * internally stored as SI values, and expressed using SI units when printing. since we offer the data as an array. 116 * @param data Time[]; the data for the vector 117 * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Vector 118 */ 119 public TimeVector(final Time[] data, final StorageType storageType) 120 { 121 this(data, TimeUnit.DEFAULT, storageType); 122 } 123 124 /** 125 * Construct an TimeVector from an array of Time objects. The Time values are each expressed in their own unit, but will be 126 * internally stored as SI values, and expressed using SI units when printing. Assume that the StorageType is DENSE since we 127 * offer the data as an array. 128 * @param data Time[]; the data for the vector 129 */ 130 public TimeVector(final Time[] data) 131 { 132 this(data, StorageType.DENSE); 133 } 134 135 /* CONSTRUCTORS WITH List<Double> or List<Time> */ 136 137 /** 138 * Construct an TimeVector from a list of Number objects or a list of Time objects. Note that the displayUnit has a 139 * different meaning depending on whether the list contains Number objects (e.g., Double objects) or Time objects. In case 140 * the list contains Number objects, the displayUnit indicates the unit in which the values in the list are expressed, as 141 * well as the unit in which they will be printed. In case the list contains Time objects, each Time has its own unit, and 142 * the displayUnit is just used for printing. The values but will always be internally stored as SI values or base values, 143 * and expressed using the display unit or base unit when printing. 144 * @param data List<Double> or List<Time>; the data for the vector 145 * @param displayUnit TimeUnit; the display unit of the vector data, and the unit of the data points when the data is 146 * expressed as List<Double> or List<Number> in general 147 * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Vector 148 */ 149 public TimeVector(final List<? extends Number> data, final TimeUnit displayUnit, final StorageType storageType) 150 { 151 this(data.size() == 0 ? DoubleVectorData.instantiate(new double[] {}, IdentityScale.SCALE, storageType) 152 : data.get(0) instanceof Time ? DoubleVectorData.instantiate(data, IdentityScale.SCALE, storageType) 153 : DoubleVectorData.instantiate(data, displayUnit.getScale(), storageType), 154 displayUnit); 155 } 156 157 /** 158 * Construct an TimeVector from a list of Number objects or a list of Time objects. Note that the displayUnit has a 159 * different meaning depending on whether the list contains Number objects (e.g., Double objects) or Time objects. In case 160 * the list contains Number objects, the displayUnit indicates the unit in which the values in the list are expressed, as 161 * well as the unit in which they will be printed. In case the list contains Time objects, each Time has its own unit, and 162 * the displayUnit is just used for printing. The values but will always be internally stored as SI values or base values, 163 * and expressed using the display unit or base unit when printing. Assume the storage type is DENSE since we offer the data 164 * as a List. 165 * @param data List<Double> or List<Time>; the data for the vector 166 * @param displayUnit TimeUnit; the display unit of the vector data, and the unit of the data points when the data is 167 * expressed as List<Double> or List<Number> in general 168 */ 169 public TimeVector(final List<? extends Number> data, final TimeUnit displayUnit) 170 { 171 this(data, displayUnit, StorageType.DENSE); 172 } 173 174 /** 175 * Construct an TimeVector from a list of Number objects or a list of Time objects. When data contains numbers such as 176 * Double, assume that they are expressed using SI units. When the data consists of Time objects, they each have their own 177 * unit, but will be printed using SI units or base units. The values but will always be internally stored as SI values or 178 * base values, and expressed using the display unit or base unit when printing. 179 * @param data List<Double> or List<Time>; the data for the vector 180 * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Vector 181 */ 182 public TimeVector(final List<? extends Number> data, final StorageType storageType) 183 { 184 this(data, TimeUnit.DEFAULT, storageType); 185 } 186 187 /** 188 * Construct an TimeVector from a list of Number objects or a list of Time objects. When data contains numbers such as 189 * Double, assume that they are expressed using SI units. When the data consists of Time objects, they each have their own 190 * unit, but will be printed using SI units or base units. The values but will always be internally stored as SI values or 191 * base values, and expressed using the display unit or base unit when printing. Assume the storage type is DENSE since we 192 * offer the data as a List. 193 * @param data List<Double> or List<Time>; the data for the vector 194 */ 195 public TimeVector(final List<? extends Number> data) 196 { 197 this(data, StorageType.DENSE); 198 } 199 200 /* CONSTRUCTORS WITH Map<Integer, Double> or Map<Integer, Time> */ 201 202 /** 203 * Construct an TimeVector from a (sparse) map of index values to Number objects or a (sparse) map of index values to of 204 * Time objects. Using index values is particularly useful for sparse vectors. The size parameter indicates the size of the 205 * vector, since the largest index does not have to be part of the map. Note that the displayUnit has a different meaning 206 * depending on whether the map contains Number objects (e.g., Double objects) or Time objects. In case the map contains 207 * Number objects, the displayUnit indicates the unit in which the values in the map are expressed, as well as the unit in 208 * which they will be printed. In case the map contains Time objects, each Time has its own unit, and the displayUnit is 209 * just used for printing. The values but will always be internally stored as SI values or base values, and expressed using 210 * the display unit or base unit when printing. 211 * @param data Map<Integer, Double> or Map<Integer, Time>; the data for the vector 212 * @param size int; the size off the vector, i.e., the highest index 213 * @param displayUnit TimeUnit; the display unit of the vector data, and the unit of the data points when the data is 214 * expressed as List<Double> or List<Number> in general 215 * @param storageType StorageType; the StorageType (SPARSE or DENSE) to use for constructing the Vector 216 */ 217 public TimeVector(final Map<Integer, ? extends Number> data, final int size, final TimeUnit displayUnit, 218 final StorageType storageType) 219 { 220 this(data.size() == 0 ? DoubleVectorData.instantiate(data, size, IdentityScale.SCALE, storageType) 221 : data.values().iterator().next() instanceof Time 222 ? DoubleVectorData.instantiate(data, size, IdentityScale.SCALE, storageType) 223 : DoubleVectorData.instantiate(data, size, displayUnit.getScale(), storageType), 224 displayUnit); 225 } 226 227 /** 228 * Construct an TimeVector from a (sparse) map of index values to Number objects or a (sparse) map of index values to of 229 * Time objects. Using index values is particularly useful for sparse vectors. The size parameter indicates the size of the 230 * vector, since the largest index does not have to be part of the map. Note that the displayUnit has a different meaning 231 * depending on whether the map contains Number objects (e.g., Double objects) or Time objects. In case the map contains 232 * Number objects, the displayUnit indicates the unit in which the values in the map are expressed, as well as the unit in 233 * which they will be printed. In case the map contains Time objects, each Time has its own unit, and the displayUnit is 234 * just used for printing. The values but will always be internally stored as SI values or base values, and expressed using 235 * the display unit or base unit when printing. Assume the storage type is SPARSE since we offer the data as a Map. 236 * @param data Map<Integer, Double> or Map<Integer, Time>; the data for the vector 237 * @param size int; the size off the vector, i.e., the highest index 238 * @param displayUnit TimeUnit; 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 TimeVector(final Map<Integer, ? extends Number> data, final int size, final TimeUnit displayUnit) 242 { 243 this(data, size, displayUnit, StorageType.SPARSE); 244 } 245 246 /** 247 * Construct an TimeVector from a (sparse) map of index values to Number objects or a (sparse) map of index values to of 248 * Time objects. Using index values is particularly useful for sparse vectors. The size parameter indicates the size of the 249 * vector, since the largest index does not have to be part of the map. When data contains numbers such as Double, assume 250 * that they are expressed using SI units. When the data consists of Time objects, they each have their own unit, but will 251 * be printed using SI units or base units. The values but will always be internally stored as SI values or base values, and 252 * expressed using the display unit or base unit when printing. 253 * @param data Map<Integer, Double> or Map<Integer, Time>; 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 TimeVector(final Map<Integer, ? extends Number> data, final int size, final StorageType storageType) 258 { 259 this(data, size, TimeUnit.DEFAULT, storageType); 260 } 261 262 /** 263 * Construct an TimeVector from a (sparse) map of index values to Number objects or a (sparse) map of index values to of 264 * Time objects. Using index values is particularly useful for sparse vectors. The size parameter indicates the size of the 265 * vector, since the largest index does not have to be part of the map. When data contains numbers such as Double, assume 266 * that they are expressed using SI units. When the data consists of Time objects, they each have their own unit, but will 267 * be printed using SI units or base units. The values but will always be internally stored as SI values or base values, and 268 * expressed using the display unit or base unit when printing. Assume the storage type is SPARSE since we offer the data as 269 * a Map. 270 * @param data Map<Integer, Double> or Map<Integer, Time>; the data for the vector 271 * @param size int; the size off the vector, i.e., the highest index 272 */ 273 public TimeVector(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<Time> getScalarClass() 282 { 283 return Time.class; 284 } 285 286 @Override 287 public TimeVector instantiateVector(final DoubleVectorData dvd, final TimeUnit displayUnit) 288 { 289 return new TimeVector(dvd, displayUnit); 290 } 291 292 @Override 293 public Time instantiateScalarSI(final double valueSI, final TimeUnit displayUnit) 294 { 295 Time result = Time.instantiateSI(valueSI); 296 result.setDisplayUnit(displayUnit); 297 return result; 298 } 299 300 @Override 301 public DurationVector instantiateVectorRel(final DoubleVectorData dvd, final DurationUnit displayUnit) 302 { 303 return new DurationVector(dvd, displayUnit); 304 } 305 306 @Override 307 public Duration instantiateScalarRelSI(final double valueSI, final DurationUnit displayUnit) 308 { 309 Duration result = Duration.instantiateSI(valueSI); 310 result.setDisplayUnit(displayUnit); 311 return result; 312 } 313 314 }