View Javadoc
1   package org.opentrafficsim.core.value;
2   
3   import java.io.Serializable;
4   
5   import org.opentrafficsim.core.unit.Unit;
6   
7   /**
8    * Basics of the Scalar type
9    * <p>
10   * This file was generated by the OpenTrafficSim value classes generator, 09 mrt, 2015
11   * <p>
12   * Copyright (c) 2014 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
13   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
14   * <p>
15   * @version 09 mrt, 2015 <br>
16   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
17   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
18   * @param <U> the unit of the values in the constructor and for display
19   */
20  public abstract class Scalar<U extends Unit<U>> extends Number implements Value<U>, Serializable
21  {
22      /**  */
23      private static final long serialVersionUID = 20150309L;
24  
25      /** The unit of the Scalar. */
26      private final U unit;
27  
28      /**
29       * Construct a new Scalar.
30       * @param unit U; the unit of the new Scalar
31       */
32      public Scalar(final U unit)
33      {
34          this.unit = unit;
35      }
36  
37      /** {@inheritDoc} */
38      @Override
39      public final U getUnit()
40      {
41          return this.unit;
42      }
43  
44      /** {@inheritDoc} */
45      @Override
46      public final double expressAsSIUnit(final double value)
47      {
48          return ValueUtil.expressAsSIUnit(value, this.unit);
49      }
50  
51      /**
52       * Convert a value from the standard SI unit into the unit of this Scalar.
53       * @param value double; the value to convert
54       * @return double; the value in the unit of this Scalar
55       */
56      protected final double expressAsSpecifiedUnit(final double value)
57      {
58          return ValueUtil.expressAsUnit(value, this.unit);
59      }
60  
61      /** {@inheritDoc} */
62      @Override
63      public final boolean isAbsolute()
64      {
65          return this instanceof Absolute;
66      }
67  
68      /** {@inheritDoc} */
69      @Override
70      public final boolean isRelative()
71      {
72          return this instanceof Relative;
73      }
74  
75  }