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_DERIVED;
6   
7   import org.opentrafficsim.core.unit.unitsystem.UnitSystem;
8   
9   /**
10   * The units of torque (moment of force).
11   * <p>
12   * Copyright (c) 2014 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
13   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
14   * <p>
15   * @version May 15, 2014 <br>
16   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
17   */
18  public class TorqueUnit extends Unit<TorqueUnit>
19  {
20      /** */
21      private static final long serialVersionUID = 20140607L;
22  
23      /** The unit of mass for the torque unit, e.g., kilogram. */
24      private final MassUnit massUnit;
25  
26      /** The unit of length for the torque unit, e.g., length. */
27      private final LengthUnit lengthUnit;
28  
29      /** The unit of time for the torque unit, e.g., second. */
30      private final TimeUnit timeUnit;
31  
32      /** The SI unit for torque is Newton meter. */
33      public static final TorqueUnit SI;
34  
35      /** Newton meter. */
36      public static final TorqueUnit NEWTON_METER;
37  
38      /** meter kilogram-force. */
39      public static final TorqueUnit METER_KILOGRAM_FORCE;
40  
41      /** foot pound-force. */
42      public static final TorqueUnit FOOT_POUND_FORCE;
43  
44      /** inch pound-force. */
45      public static final TorqueUnit INCH_POUND_FORCE;
46  
47      static
48      {
49          SI =
50                  new TorqueUnit(MassUnit.KILOGRAM, LengthUnit.METER, TimeUnit.SECOND, "TorqueUnit.Newton_meter",
51                          "TorqueUnit.N.m", SI_DERIVED);
52          NEWTON_METER = SI;
53          METER_KILOGRAM_FORCE =
54                  new TorqueUnit(ForceUnit.KILOGRAM_FORCE, LengthUnit.METER, "TorqueUnit.meter_kilogram-force",
55                          "TorqueUnit.m.kgf", OTHER);
56          FOOT_POUND_FORCE =
57                  new TorqueUnit(ForceUnit.POUND_FORCE, LengthUnit.FOOT, "TorqueUnit.foot_pound-force",
58                          "TorqueUnit.ft.lbf", IMPERIAL);
59          INCH_POUND_FORCE =
60                  new TorqueUnit(ForceUnit.POUND_FORCE, LengthUnit.INCH, "TorqueUnit.inch_pound-force",
61                          "TorqueUnit.in.lbf", IMPERIAL);
62      }
63  
64      /**
65       * Create a torque unit from mass, length and time units.
66       * @param massUnit the unit of mass for the torque unit, e.g., kilogram
67       * @param lengthUnit the unit of length for the torque unit, e.g., meter
68       * @param timeUnit the unit of time for the torque unit, e.g., second
69       * @param nameKey the key to the locale file for the long name of the unit
70       * @param abbreviationKey the key to the locale file for the abbreviation of the unit
71       * @param unitSystem the unit system, e.g. SI or Imperial
72       */
73      public TorqueUnit(final MassUnit massUnit, final LengthUnit lengthUnit, final TimeUnit timeUnit,
74              final String nameKey, final String abbreviationKey, final UnitSystem unitSystem)
75      {
76          super(nameKey, abbreviationKey, unitSystem, NEWTON_METER, massUnit.getConversionFactorToStandardUnit()
77                  * lengthUnit.getConversionFactorToStandardUnit() * lengthUnit.getConversionFactorToStandardUnit()
78                  / (timeUnit.getConversionFactorToStandardUnit() * timeUnit.getConversionFactorToStandardUnit()), true);
79          this.massUnit = massUnit;
80          this.lengthUnit = lengthUnit;
81          this.timeUnit = timeUnit;
82      }
83  
84      /**
85       * Create a torque unit from force and length units.
86       * @param forceUnit the unit of force for the torque unit, e.g., Newton
87       * @param lengthUnit the unit of length for the torque unit, e.g., m
88       * @param nameKey the key to the locale file for the long name of the unit
89       * @param abbreviationKey the key to the locale file for the abbreviation of the unit
90       * @param unitSystem the unit system, e.g. SI or Imperial
91       */
92      public TorqueUnit(final ForceUnit forceUnit, final LengthUnit lengthUnit, final String nameKey,
93              final String abbreviationKey, final UnitSystem unitSystem)
94      {
95          super(nameKey, abbreviationKey, unitSystem, NEWTON_METER, forceUnit.getConversionFactorToStandardUnit()
96                  * lengthUnit.getConversionFactorToStandardUnit(), true);
97          this.massUnit = forceUnit.getMassUnit();
98          this.lengthUnit = forceUnit.getLengthUnit();
99          this.timeUnit = forceUnit.getTimeUnit();
100     }
101 
102     /**
103      * Construct a torque unit based on another torque unit.
104      * @param nameKey the key to the locale file for the long name of the unit
105      * @param abbreviationKey the key to the locale file for the abbreviation of the unit
106      * @param unitSystem the unit system, e.g. SI or Imperial
107      * @param referenceUnit the unit to convert to
108      * @param conversionFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given
109      *            reference unit
110      */
111     public TorqueUnit(final String nameKey, final String abbreviationKey, final UnitSystem unitSystem,
112             final TorqueUnit referenceUnit, final double conversionFactorToReferenceUnit)
113     {
114         super(nameKey, abbreviationKey, unitSystem, referenceUnit, conversionFactorToReferenceUnit, true);
115         this.massUnit = referenceUnit.getMassUnit();
116         this.lengthUnit = referenceUnit.getLengthUnit();
117         this.timeUnit = referenceUnit.getTimeUnit();
118     }
119 
120     /**
121      * @return massUnit
122      */
123     public final MassUnit getMassUnit()
124     {
125         return this.massUnit;
126     }
127 
128     /**
129      * @return lengthUnit
130      */
131     public final LengthUnit getLengthUnit()
132     {
133         return this.lengthUnit;
134     }
135 
136     /**
137      * @return timeUnit
138      */
139     public final TimeUnit getTimeUnit()
140     {
141         return this.timeUnit;
142     }
143 
144     /** {@inheritDoc} */
145     @Override
146     public final TorqueUnit getStandardUnit()
147     {
148         return NEWTON_METER;
149     }
150 
151     /** {@inheritDoc} */
152     @Override
153     public final String getSICoefficientsString()
154     {
155         return "kgm2/s2";
156     }
157 
158 }