View Javadoc
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-2018 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 U; the unit of the new Absolute Immutable Double DurationMatrix
36       * @param 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 DoubleScalar.Rel&lt;U&gt;[][]; the values of the entries in the new Absolute Immutable Double
47       *            DurationMatrix
48       * @param storageType the data type to use (e.g., DENSE or SPARSE)
49       * @throws ValueException when values has zero entries
50       */
51      public TimeMatrix(final Time[][] values, final StorageType storageType) throws ValueException
52      {
53          super(values, storageType);
54      }
55  
56      /**
57       * Construct a new Absolute Immutable Double DurationMatrix.
58       * @param data an internal data object
59       * @param unit the unit
60       */
61      TimeMatrix(final DoubleMatrixData data, final TimeUnit unit)
62      {
63          super(data, unit);
64      }
65  
66      /** {@inheritDoc} */
67      @Override
68      public final TimeMatrix toDense()
69      {
70          return this.data.isDense() ? this : instantiateTypeAbs(this.data.toDense(), getUnit());
71      }
72  
73      /** {@inheritDoc} */
74      @Override
75      public final TimeMatrix toSparse()
76      {
77          return this.data.isSparse() ? this : instantiateTypeAbs(this.data.toSparse(), getUnit());
78      }
79  
80      /** {@inheritDoc} */
81      @Override
82      protected final TimeMatrix instantiateTypeAbs(final DoubleMatrixData dmd, final TimeUnit unit)
83      {
84          return new TimeMatrix(dmd, unit);
85      }
86  
87      /** {@inheritDoc} */
88      @Override
89      protected final DurationMatrix instantiateTypeRel(final DoubleMatrixData dmd, final DurationUnit unit)
90      {
91          return new DurationMatrix(dmd, unit);
92      }
93  
94      /** {@inheritDoc} */
95      @Override
96      protected final MutableTimeMatrix instantiateMutableType(final DoubleMatrixData dmd, final TimeUnit unit)
97      {
98          return new MutableTimeMatrix(dmd, unit);
99      }
100 
101     /** {@inheritDoc} */
102     @Override
103     protected final Time instantiateScalar(final double value, final TimeUnit unit)
104     {
105         return new Time(value, unit);
106     }
107 
108 }