View Javadoc
1   package org.opentrafficsim.core.unit;
2   
3   import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.IMPERIAL;
4   import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.OTHER;
5   import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.SI_BASE;
6   import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.SI_DERIVED;
7   
8   import org.opentrafficsim.core.unit.unitsystem.UnitSystem;
9   
10  /**
11   * Temperature units.
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 Jun 5, 2014 <br>
17   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
18   */
19  public class TemperatureUnit extends OffsetUnit<TemperatureUnit>
20  {
21      /** */
22      private static final long serialVersionUID = 20140605L;
23  
24      /** The SI unit for temperature is Kelvin. */
25      public static final TemperatureUnit SI;
26  
27      /** Kelvin. */
28      public static final TemperatureUnit KELVIN;
29  
30      /** Degree Celsius. */
31      public static final TemperatureUnit DEGREE_CELSIUS;
32  
33      /** Degree Fahrenheit. */
34      public static final TemperatureUnit DEGREE_FAHRENHEIT;
35  
36      /** Degree Rankine. */
37      public static final TemperatureUnit DEGREE_RANKINE;
38  
39      /** Degree Reaumur. */
40      public static final TemperatureUnit DEGREE_REAUMUR;
41  
42      static
43      {
44          SI = new TemperatureUnit("TemperatureUnit.kelvin", "TemperatureUnit.K", SI_BASE, 1.0, 0.0);
45          KELVIN = SI;
46          DEGREE_CELSIUS =
47                  new TemperatureUnit("TemperatureUnit.degree_Celsius", "TemperatureUnit.dgC", SI_DERIVED, 1.0, -273.15);
48          DEGREE_FAHRENHEIT =
49                  new TemperatureUnit("TemperatureUnit.degree_Fahrenheit", "TemperatureUnit.dgF", IMPERIAL, 5.0 / 9.0,
50                          -459.67);
51          DEGREE_RANKINE =
52                  new TemperatureUnit("TemperatureUnit.degree_Rankine", "TemperatureUnit.dgR", OTHER, 5.0 / 9.0, 0.0);
53          DEGREE_REAUMUR =
54                  new TemperatureUnit("TemperatureUnit.degree_Reaumur", "TemperatureUnit.dgRe", OTHER, 4.0 / 5.0, -273.15);
55      }
56  
57      /**
58       * @param nameKey the key to the locale file for the long name of the unit
59       * @param abbreviationKey the key to the locale file for the abbreviation of the unit
60       * @param unitSystem the unit system, e.g. SI or Imperial
61       * @param conversionFactorToStandardUnit multiply by this number to convert to the standard unit
62       * @param offsetToKelvin the offsetToKelvin to add to convert to the standard (e.g., SI) unit
63       */
64      public TemperatureUnit(final String nameKey, final String abbreviationKey, final UnitSystem unitSystem,
65              final double conversionFactorToStandardUnit, final double offsetToKelvin)
66      {
67          super(nameKey, abbreviationKey, unitSystem, KELVIN, conversionFactorToStandardUnit, offsetToKelvin);
68      }
69  
70      /**
71       * @param nameKey the key to the locale file for the long name of the unit
72       * @param abbreviationKey the key to the locale file for the abbreviation of the unit
73       * @param unitSystem the unit system, e.g. SI or Imperial
74       * @param referenceUnit the unit to convert to
75       * @param conversionFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given
76       *            reference unit
77       * @param offsetToKelvin the offsetToKelvin to add to convert to the standard (e.g., SI) unit
78       */
79      public TemperatureUnit(final String nameKey, final String abbreviationKey, final UnitSystem unitSystem,
80              final TemperatureUnit referenceUnit, final double conversionFactorToReferenceUnit,
81              final double offsetToKelvin)
82      {
83          super(nameKey, abbreviationKey, unitSystem, referenceUnit, conversionFactorToReferenceUnit, offsetToKelvin);
84      }
85  
86      /** {@inheritDoc} */
87      @Override
88      public final TemperatureUnit getStandardUnit()
89      {
90          return KELVIN;
91      }
92  
93      /** {@inheritDoc} */
94      @Override
95      public final String getSICoefficientsString()
96      {
97          return "K";
98      }
99  
100 }