1 package org.opentrafficsim.core.value;
2
3 import java.io.Serializable;
4
5 import org.opentrafficsim.core.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 OpenTrafficSim value classes generator, 09 mrt, 2015
12 * <p>
13 * Copyright (c) 2014 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
14 * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
15 * <p>
16 * @version 09 mrt, 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 value(s) in this AbstractValue. Used for setting, getting and displaying the value(s)
20 */
21 public abstract class AbstractValue<U extends Unit<U>> implements Value<U>, Serializable
22 {
23 /** */
24 private static final long serialVersionUID = 20150309L;
25
26 /** The unit of this AbstractValue. */
27 private final U unit;
28
29 /**
30 * Construct a new AbstractValue.
31 * @param unit U; the unit of the new AbstractValue
32 */
33 protected AbstractValue(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 return ValueUtil.expressAsSIUnit(value, this.unit);
50 }
51
52 /**
53 * Convert a value in SI standard unit into the unit of this AbstractValue.
54 * @param value double; the value in the standard SI unit
55 * @return double; the value in the unit as specified for this AbstractValue
56 */
57 protected final double expressAsSpecifiedUnit(final double value)
58 {
59 return ValueUtil.expressAsUnit(value, this.unit);
60 }
61
62 /** {@inheritDoc} */
63 @Override
64 public final boolean isAbsolute()
65 {
66 return this instanceof Absolute;
67 }
68
69 /** {@inheritDoc} */
70 @Override
71 public final boolean isRelative()
72 {
73 return this instanceof Relative;
74 }
75
76 }