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_DERIVED;
6   
7   import org.djunits.unit.unitsystem.UnitSystem;
8   
9   /**
10   * The units of torque (moment of force).
11   * <p>
12   * Copyright (c) 2015-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
13   * BSD-style license. See <a href="http://djunits.org/docs/license.html">DJUNITS License</a>.
14   * <p>
15   * $LastChangedDate: 2019-03-02 19:06:46 +0100 (Sat, 02 Mar 2019) $, @version $Revision: 342 $, by $Author: averbraeck $,
16   * initial version May 15, 2014 <br>
17   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
18   */
19  public class TorqueUnit extends LinearUnit<TorqueUnit>
20  {
21      /** */
22      private static final long serialVersionUID = 20140607L;
23  
24      /** The unit of mass for the torque unit, e.g., kilogram. */
25      private final MassUnit massUnit;
26  
27      /** The unit of length for the torque unit, e.g., length. */
28      private final LengthUnit lengthUnit;
29  
30      /** The unit of time for the torque unit, e.g., second. */
31      private final DurationUnit durationUnit;
32  
33      /** The SI unit for torque is Newton meter. */
34      public static final TorqueUnit SI;
35  
36      /** Newton meter. */
37      public static final TorqueUnit NEWTON_METER;
38  
39      /** meter kilogram-force. */
40      public static final TorqueUnit METER_KILOGRAM_FORCE;
41  
42      /** Pound foot. */
43      public static final TorqueUnit POUND_FOOT;
44  
45      /** Pound inch. */
46      public static final TorqueUnit POUND_INCH;
47  
48      static
49      {
50          SI = new TorqueUnit(MassUnit.KILOGRAM, LengthUnit.METER, DurationUnit.SECOND, "TorqueUnit.N.m", SI_DERIVED);
51          NEWTON_METER = SI;
52          METER_KILOGRAM_FORCE = new TorqueUnit(ForceUnit.KILOGRAM_FORCE, LengthUnit.METER, "TorqueUnit.m.kgf", OTHER);
53          POUND_FOOT = new TorqueUnit(ForceUnit.POUND_FORCE, LengthUnit.FOOT, "TorqueUnit.lbf.ft", IMPERIAL);
54          POUND_INCH = new TorqueUnit(ForceUnit.POUND_FORCE, LengthUnit.INCH, "TorqueUnit.lbf.in", IMPERIAL);
55      }
56  
57      /**
58       * Create a torque unit from mass, length and time units.
59       * @param massUnit MassUnit; the unit of mass for the torque unit, e.g., kilogram
60       * @param lengthUnit LengthUnit; the unit of length for the torque unit, e.g., meter
61       * @param durationUnit DurationUnit; the unit of time for the torque unit, e.g., second
62       * @param abbreviationKey String; the key to the locale file for the abbreviation of the unit
63       * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
64       */
65      private TorqueUnit(final MassUnit massUnit, final LengthUnit lengthUnit, final DurationUnit durationUnit,
66              final String abbreviationKey, final UnitSystem unitSystem)
67      {
68          super(abbreviationKey, unitSystem, NEWTON_METER, massUnit.getScaleFactor() * lengthUnit.getScaleFactor()
69                  * lengthUnit.getScaleFactor() / (durationUnit.getScaleFactor() * durationUnit.getScaleFactor()));
70          this.massUnit = massUnit;
71          this.lengthUnit = lengthUnit;
72          this.durationUnit = durationUnit;
73      }
74  
75      /**
76       * Create a user-defined torque unit from mass, length and time units.
77       * @param massUnit MassUnit; the unit of mass for the torque unit, e.g., kilogram
78       * @param lengthUnit LengthUnit; the unit of length for the torque unit, e.g., meter
79       * @param durationUnit DurationUnit; the unit of time for the torque unit, e.g., second
80       * @param name String; the long name of the unit
81       * @param abbreviation String; the abbreviation of the unit
82       * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
83       */
84      public TorqueUnit(final MassUnit massUnit, final LengthUnit lengthUnit, final DurationUnit durationUnit, final String name,
85              final String abbreviation, final UnitSystem unitSystem)
86      {
87          super(name, abbreviation, unitSystem, NEWTON_METER, massUnit.getScaleFactor() * lengthUnit.getScaleFactor()
88                  * lengthUnit.getScaleFactor() / (durationUnit.getScaleFactor() * durationUnit.getScaleFactor()));
89          this.massUnit = massUnit;
90          this.lengthUnit = lengthUnit;
91          this.durationUnit = durationUnit;
92      }
93  
94      /**
95       * Create a torque unit from force and length units.
96       * @param forceUnit ForceUnit; the unit of force for the torque unit, e.g., Newton
97       * @param lengthUnit LengthUnit; the unit of length for the torque unit, e.g., meter
98       * @param abbreviationKey String; the key to the locale file for the abbreviation of the unit
99       * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
100      */
101     private TorqueUnit(final ForceUnit forceUnit, final LengthUnit lengthUnit, final String abbreviationKey,
102             final UnitSystem unitSystem)
103     {
104         super(abbreviationKey, unitSystem, NEWTON_METER, forceUnit.getScaleFactor() * lengthUnit.getScaleFactor());
105         this.massUnit = forceUnit.getMassUnit();
106         this.lengthUnit = forceUnit.getLengthUnit();
107         this.durationUnit = forceUnit.getDurationUnit();
108     }
109 
110     /**
111      * Create a user-defined torque unit from force and length units.
112      * @param forceUnit ForceUnit; the unit of force for the torque unit, e.g., Newton
113      * @param lengthUnit LengthUnit; the unit of length for the torque unit, e.g., meter
114      * @param name String; the long name of the unit
115      * @param abbreviation String; the abbreviation of the unit
116      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
117      */
118     public TorqueUnit(final ForceUnit forceUnit, final LengthUnit lengthUnit, final String name, final String abbreviation,
119             final UnitSystem unitSystem)
120     {
121         super(name, abbreviation, unitSystem, NEWTON_METER, forceUnit.getScaleFactor() * lengthUnit.getScaleFactor());
122         this.massUnit = forceUnit.getMassUnit();
123         this.lengthUnit = forceUnit.getLengthUnit();
124         this.durationUnit = forceUnit.getDurationUnit();
125     }
126 
127     /**
128      * Construct a torque unit based on another torque unit.
129      * @param abbreviationKey String; the key to the locale file for the abbreviation of the unit
130      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
131      * @param referenceUnit TorqueUnit; the unit to convert to
132      * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
133      *            unit
134      */
135     private TorqueUnit(final String abbreviationKey, final UnitSystem unitSystem, final TorqueUnit referenceUnit,
136             final double scaleFactorToReferenceUnit)
137     {
138         super(abbreviationKey, unitSystem, referenceUnit, scaleFactorToReferenceUnit);
139         this.massUnit = referenceUnit.getMassUnit();
140         this.lengthUnit = referenceUnit.getLengthUnit();
141         this.durationUnit = referenceUnit.getDurationUnit();
142     }
143 
144     /**
145      * Build a user-defined unit with a conversion factor to another unit.
146      * @param name String; the long name of the unit
147      * @param abbreviation String; the abbreviation of the unit
148      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
149      * @param referenceUnit TorqueUnit; the unit to convert to
150      * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
151      *            unit
152      */
153     public TorqueUnit(final String name, final String abbreviation, final UnitSystem unitSystem, final TorqueUnit referenceUnit,
154             final double scaleFactorToReferenceUnit)
155     {
156         super(name, abbreviation, unitSystem, referenceUnit, scaleFactorToReferenceUnit);
157         this.massUnit = referenceUnit.getMassUnit();
158         this.lengthUnit = referenceUnit.getLengthUnit();
159         this.durationUnit = referenceUnit.getDurationUnit();
160     }
161 
162     /**
163      * @return massUnit
164      */
165     public final MassUnit getMassUnit()
166     {
167         return this.massUnit;
168     }
169 
170     /**
171      * @return lengthUnit
172      */
173     public final LengthUnit getLengthUnit()
174     {
175         return this.lengthUnit;
176     }
177 
178     /**
179      * @return durationUnit
180      */
181     public final DurationUnit getDurationUnit()
182     {
183         return this.durationUnit;
184     }
185 
186     /** {@inheritDoc} */
187     @Override
188     public final TorqueUnit getStandardUnit()
189     {
190         return NEWTON_METER;
191     }
192 
193     /** {@inheritDoc} */
194     @Override
195     public final String getSICoefficientsString()
196     {
197         return "kgm2/s2";
198     }
199 
200 }