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