View Javadoc
1   package org.djunits.value;
2   
3   import java.io.Serializable;
4   
5   import org.djunits.unit.Unit;
6   
7   /**
8    * Basics of the Scalar type
9    * <p>
10   * This file was generated by the djunits value classes generator, 26 jun, 2015
11   * <p>
12   * Copyright (c) 2015-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
13   * BSD-style license. See <a href="http://djunits.org/docs/license.html">DJUNITS License</a>.
14   * <p>
15   * $LastChangedDate: 2018-08-11 03:31:46 +0200 (Sat, 11 Aug 2018) $, @version $Revision: 306 $, by $Author: averbraeck $,
16   * initial version 26 jun, 2015 <br>
17   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
18   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
19   * @param <U> the unit of the values in the constructor and for display
20   */
21  public abstract class Scalar<U extends Unit<U>> extends Number implements Value<U>, Serializable
22  {
23      /**  */
24      private static final long serialVersionUID = 20150626L;
25  
26      /** The display unit of the Scalar. */
27      private U unit;
28  
29      /**
30       * Construct a new Scalar.
31       * @param unit U; the unit of the new Scalar
32       */
33      public Scalar(final U unit)
34      {
35          this.unit = unit;
36      }
37  
38      /** {@inheritDoc} */
39      @Override
40      public final U getUnit()
41      {
42          return this.unit;
43      }
44  
45      /** {@inheritDoc} */
46      @Override
47      public final double expressAsSIUnit(final double value)
48      {
49          if (this.unit.isBaseSIUnit())
50          {
51              return value;
52          }
53          return ValueUtil.expressAsSIUnit(value, this.unit);
54      }
55  
56      /**
57       * Convert a value from the standard SI unit into the unit of this Scalar.
58       * @param value double; the value to convert
59       * @return double; the value in the unit of this Scalar
60       */
61      protected final double expressAsSpecifiedUnit(final double value)
62      {
63          if (this.unit.isBaseSIUnit())
64          {
65              return value;
66          }
67          return ValueUtil.expressAsUnit(value, this.unit);
68      }
69  
70      /** {@inheritDoc} */
71      @Override
72      public void setDisplayUnit(final U newUnit)
73      {
74          this.unit = newUnit;
75      }
76  
77      /** {@inheritDoc} */
78      @Override
79      public final boolean isAbsolute()
80      {
81          return this instanceof Absolute;
82      }
83  
84      /** {@inheritDoc} */
85      @Override
86      public final boolean isRelative()
87      {
88          return this instanceof Relative;
89      }
90  
91      // No hashcode or equals -- has to be implemented on a deeper level
92  }