1 package org.djunits.value.vdouble.matrix; 2 3 import org.djunits.unit.DurationUnit; 4 import org.djunits.unit.TimeUnit; 5 import org.djunits.value.StorageType; 6 import org.djunits.value.ValueException; 7 import org.djunits.value.vdouble.scalar.Time; 8 9 /** 10 * Immutable Time Matrix. 11 * <p> 12 * Note that when the offset of a stored absolute Time becomes large, precision of a double might not be enough for the required 13 * resolution of a Time. A double has around 16 significant digits (52 bit mantissa). This means that when we need to have a 14 * double Time with TimeUnit.BASE as its unit, the largest value where the ms precision is reached is 2^51 = 2.3E15, which is 15 * around 71000 years. This is sufficient to store a date in the 21st Century with a BASE or an Epoch offset precise to a 16 * microsecond. 17 * <p> 18 * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br> 19 * BSD-style license. See <a href="http://djunits.org/docs/license.html">DJUNITS License</a>. 20 * <p> 21 * $LastChangedDate: 2015-09-29 14:14:28 +0200 (Tue, 29 Sep 2015) $, @version $Revision: 73 $, by $Author: pknoppers $, initial 22 * version Sep 5, 2015 <br> 23 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a> 24 * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a> 25 */ 26 public class TimeMatrix 27 extends AbstractDoubleMatrixAbs<TimeUnit, DurationUnit, TimeMatrix, DurationMatrix, MutableTimeMatrix, Time> 28 { 29 /** */ 30 private static final long serialVersionUID = 20151003L; 31 32 /** 33 * Construct a new Absolute Immutable Double DurationMatrix. 34 * @param values double[][]; the values of the entries in the new Absolute Immutable Double DurationMatrix 35 * @param unit TimeUnit; the unit of the new Absolute Immutable Double DurationMatrix 36 * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE) 37 * @throws ValueException when values is null 38 */ 39 public TimeMatrix(final double[][] values, final TimeUnit unit, final StorageType storageType) throws ValueException 40 { 41 super(values, unit, storageType); 42 } 43 44 /** 45 * Construct a new Absolute Immutable Double DurationMatrix. 46 * @param values Time[][]; the values of the entries in the new Absolute Immutable Double DurationMatrix 47 * @param storageType StorageType; the data type to use (e.g., DENSE or SPARSE) 48 * @throws ValueException when values has zero entries 49 */ 50 public TimeMatrix(final Time[][] values, final StorageType storageType) throws ValueException 51 { 52 super(values, storageType); 53 } 54 55 /** 56 * Construct a new Absolute Immutable Double DurationMatrix. 57 * @param data DoubleMatrixData; an internal data object 58 * @param unit TimeUnit; the unit 59 */ 60 TimeMatrix(final DoubleMatrixData data, final TimeUnit unit) 61 { 62 super(data, unit); 63 } 64 65 /** {@inheritDoc} */ 66 @Override 67 public final TimeMatrix toDense() 68 { 69 return this.data.isDense() ? this : instantiateTypeAbs(this.data.toDense(), getUnit()); 70 } 71 72 /** {@inheritDoc} */ 73 @Override 74 public final TimeMatrix toSparse() 75 { 76 return this.data.isSparse() ? this : instantiateTypeAbs(this.data.toSparse(), getUnit()); 77 } 78 79 /** {@inheritDoc} */ 80 @Override 81 protected final TimeMatrix instantiateTypeAbs(final DoubleMatrixData dmd, final TimeUnit unit) 82 { 83 return new TimeMatrix(dmd, unit); 84 } 85 86 /** {@inheritDoc} */ 87 @Override 88 protected final DurationMatrix instantiateTypeRel(final DoubleMatrixData dmd, final DurationUnit unit) 89 { 90 return new DurationMatrix(dmd, unit); 91 } 92 93 /** {@inheritDoc} */ 94 @Override 95 protected final MutableTimeMatrix instantiateMutableType(final DoubleMatrixData dmd, final TimeUnit unit) 96 { 97 return new MutableTimeMatrix(dmd, unit); 98 } 99 100 /** {@inheritDoc} */ 101 @Override 102 protected final Time instantiateScalar(final double value, final TimeUnit unit) 103 { 104 return new Time(value, unit); 105 } 106 107 }