View Javadoc
1   package org.djunits.unit;
2   
3   import static org.djunits.unit.unitsystem.UnitSystem.IMPERIAL;
4   import static org.djunits.unit.unitsystem.UnitSystem.OTHER;
5   import static org.djunits.unit.unitsystem.UnitSystem.SI_BASE;
6   import static org.djunits.unit.unitsystem.UnitSystem.SI_DERIVED;
7   
8   import org.djunits.unit.unitsystem.UnitSystem;
9   
10  /**
11   * Temperature units.
12   * <p>
13   * Copyright (c) 2015-2018 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: 2018-01-28 03:17:44 +0100 (Sun, 28 Jan 2018) $, @version $Revision: 256 $, by $Author: averbraeck $,
17   * initial version Jun 5, 2014 <br>
18   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
19   */
20  public class TemperatureUnit extends LinearUnit<TemperatureUnit>
21  {
22      /** */
23      private static final long serialVersionUID = 20140605L;
24  
25      /** The SI unit for temperature is Kelvin. */
26      public static final TemperatureUnit SI;
27  
28      /** Kelvin. */
29      public static final TemperatureUnit KELVIN;
30  
31      /** Degree Celsius. */
32      public static final TemperatureUnit DEGREE_CELSIUS;
33  
34      /** Degree Fahrenheit. */
35      public static final TemperatureUnit DEGREE_FAHRENHEIT;
36  
37      /** Degree Rankine. */
38      public static final TemperatureUnit DEGREE_RANKINE;
39  
40      /** Degree Reaumur. */
41      public static final TemperatureUnit DEGREE_REAUMUR;
42  
43      static
44      {
45          SI = new TemperatureUnit("TemperatureUnit.kelvin", "TemperatureUnit.K", SI_BASE);
46          KELVIN = SI;
47          DEGREE_CELSIUS =
48                  new TemperatureUnit("TemperatureUnit.degree_Celsius", "TemperatureUnit.dgC", SI_DERIVED, KELVIN, 1.0, true);
49          DEGREE_FAHRENHEIT = new TemperatureUnit("TemperatureUnit.degree_Fahrenheit", "TemperatureUnit.dgF", IMPERIAL, KELVIN,
50                  5.0 / 9.0, true);
51          DEGREE_RANKINE =
52                  new TemperatureUnit("TemperatureUnit.degree_Rankine", "TemperatureUnit.dgR", OTHER, KELVIN, 5.0 / 9.0, true);
53          DEGREE_REAUMUR =
54                  new TemperatureUnit("TemperatureUnit.degree_Reaumur", "TemperatureUnit.dgRe", OTHER, KELVIN, 4.0 / 5.0, true);
55      }
56  
57      /**
58       * Build a standard TemperatureUnit.
59       * @param nameKey the key to the locale file for the long name of the unit
60       * @param abbreviationKey the key to the locale file for the abbreviation of the unit
61       * @param unitSystem the unit system, e.g. SI or Imperial
62       */
63      private TemperatureUnit(final String nameKey, final String abbreviationKey, final UnitSystem unitSystem)
64      {
65          super(nameKey, abbreviationKey, unitSystem, true);
66      }
67  
68      /**
69       * Build a TemperatureUnit with a conversion factor and offset to Kelvin.
70       * @param nameOrNameKey if standardUnit: the key to the locale file for the long name of the unit, otherwise the name itself
71       * @param abbreviationOrAbbreviationKey if standardUnit: the key to the locale file for the abbreviation of the unit,
72       *            otherwise the abbreviation itself
73       * @param unitSystem the unit system, e.g. SI or Imperial
74       * @param referenceUnit the unit to convert to
75       * @param scaleFactorToStandardUnit multiply by this number to convert to the standard unit
76       * @param standardUnit indicates whether it is a standard unit with a definition in the locale, or a user-defined unit
77       */
78      private TemperatureUnit(final String nameOrNameKey, final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem,
79              final TemperatureUnit referenceUnit, final double scaleFactorToStandardUnit, final boolean standardUnit)
80      {
81          super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, referenceUnit, scaleFactorToStandardUnit, standardUnit);
82      }
83  
84      /**
85       * Build a user-defined TemperatureUnit with a conversion factor and offset to Kelvin.
86       * @param name the long name of the unit
87       * @param abbreviation the abbreviation of the unit
88       * @param unitSystem the unit system, e.g. SI or Imperial
89       * @param referenceUnit the unit to convert to
90       * @param scaleFactorToStandardUnit multiply by this number to convert to the standard unit
91       * @param offsetToKelvin the offsetToKelvin to add to convert to the standard (e.g., SI) unit
92       */
93      public TemperatureUnit(final String name, final String abbreviation, final UnitSystem unitSystem,
94              final TemperatureUnit referenceUnit, final double scaleFactorToStandardUnit, final double offsetToKelvin)
95      {
96          this(name, abbreviation, unitSystem, referenceUnit, scaleFactorToStandardUnit, false);
97      }
98  
99      /** {@inheritDoc} */
100     @Override
101     public final TemperatureUnit getStandardUnit()
102     {
103         return KELVIN;
104     }
105 
106     /** {@inheritDoc} */
107     @Override
108     public final String getSICoefficientsString()
109     {
110         return "K";
111     }
112 
113 }