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-2018 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: 2018-01-28 03:17:44 +0100 (Sun, 28 Jan 2018) $, @version $Revision: 256 $, 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.Newton_meter",
51                  "TorqueUnit.N.m", SI_DERIVED, true);
52          NEWTON_METER = SI;
53          METER_KILOGRAM_FORCE = new TorqueUnit(ForceUnit.KILOGRAM_FORCE, LengthUnit.METER, "TorqueUnit.meter_kilogram-force",
54                  "TorqueUnit.m.kgf", OTHER, true);
55          POUND_FOOT = new TorqueUnit(ForceUnit.POUND_FORCE, LengthUnit.FOOT, "TorqueUnit.pound-foot", "TorqueUnit.lbf.ft",
56                  IMPERIAL, true);
57          POUND_INCH = new TorqueUnit(ForceUnit.POUND_FORCE, LengthUnit.INCH, "TorqueUnit.pound-inch", "TorqueUnit.lbf.in",
58                  IMPERIAL, true);
59      }
60  
61      /**
62       * Create a torque unit from mass, length and time units.
63       * @param massUnit the unit of mass for the torque unit, e.g., kilogram
64       * @param lengthUnit the unit of length for the torque unit, e.g., meter
65       * @param durationUnit the unit of time for the torque unit, e.g., second
66       * @param nameOrNameKey if standardUnit: the key to the locale file for the long name of the unit, otherwise the name itself
67       * @param abbreviationOrAbbreviationKey if standardUnit: the key to the locale file for the abbreviation of the unit,
68       *            otherwise the abbreviation itself
69       * @param unitSystem the unit system, e.g. SI or Imperial
70       * @param standardUnit indicates whether it is a standard unit with a definition in the locale, or a user-defined unit
71       */
72      private TorqueUnit(final MassUnit massUnit, final LengthUnit lengthUnit, final DurationUnit durationUnit,
73              final String nameOrNameKey, final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem,
74              final boolean standardUnit)
75      {
76          super(nameOrNameKey,
77                  abbreviationOrAbbreviationKey, unitSystem, NEWTON_METER, massUnit.getScaleFactor() * lengthUnit.getScaleFactor()
78                          * lengthUnit.getScaleFactor() / (durationUnit.getScaleFactor() * durationUnit.getScaleFactor()),
79                  standardUnit);
80          this.massUnit = massUnit;
81          this.lengthUnit = lengthUnit;
82          this.durationUnit = durationUnit;
83      }
84  
85      /**
86       * Create a user-defined torque unit from mass, length and time units.
87       * @param massUnit the unit of mass for the torque unit, e.g., kilogram
88       * @param lengthUnit the unit of length for the torque unit, e.g., meter
89       * @param durationUnit the unit of time for the torque unit, e.g., second
90       * @param name the long name of the unit
91       * @param abbreviation the abbreviation of the unit
92       * @param unitSystem the unit system, e.g. SI or Imperial
93       */
94      public TorqueUnit(final MassUnit massUnit, final LengthUnit lengthUnit, final DurationUnit durationUnit, final String name,
95              final String abbreviation, final UnitSystem unitSystem)
96      {
97          this(massUnit, lengthUnit, durationUnit, name, abbreviation, unitSystem, false);
98      }
99  
100     /**
101      * Create a torque unit from force and length units.
102      * @param forceUnit the unit of force for the torque unit, e.g., Newton
103      * @param lengthUnit the unit of length for the torque unit, e.g., meter
104      * @param nameOrNameKey if standardUnit: the key to the locale file for the long name of the unit, otherwise the name itself
105      * @param abbreviationOrAbbreviationKey if standardUnit: the key to the locale file for the abbreviation of the unit,
106      *            otherwise the abbreviation itself
107      * @param unitSystem the unit system, e.g. SI or Imperial
108      * @param standardUnit indicates whether it is a standard unit with a definition in the locale, or a user-defined unit
109      */
110     private TorqueUnit(final ForceUnit forceUnit, final LengthUnit lengthUnit, final String nameOrNameKey,
111             final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem, final boolean standardUnit)
112     {
113         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, NEWTON_METER,
114                 forceUnit.getScaleFactor() * lengthUnit.getScaleFactor(), standardUnit);
115         this.massUnit = forceUnit.getMassUnit();
116         this.lengthUnit = forceUnit.getLengthUnit();
117         this.durationUnit = forceUnit.getDurationUnit();
118     }
119 
120     /**
121      * Create a user-defined torque unit from force and length units.
122      * @param forceUnit the unit of force for the torque unit, e.g., Newton
123      * @param lengthUnit the unit of length for the torque unit, e.g., meter
124      * @param name the long name of the unit
125      * @param abbreviation the abbreviation of the unit
126      * @param unitSystem the unit system, e.g. SI or Imperial
127      */
128     public TorqueUnit(final ForceUnit forceUnit, final LengthUnit lengthUnit, final String name, final String abbreviation,
129             final UnitSystem unitSystem)
130     {
131         this(forceUnit, lengthUnit, name, abbreviation, unitSystem, false);
132     }
133 
134     /**
135      * Construct a torque unit based on another torque unit.
136      * @param nameOrNameKey if standardUnit: the key to the locale file for the long name of the unit, otherwise the name itself
137      * @param abbreviationOrAbbreviationKey if standardUnit: the key to the locale file for the abbreviation of the unit,
138      *            otherwise the abbreviation itself
139      * @param unitSystem the unit system, e.g. SI or Imperial
140      * @param referenceUnit the unit to convert to
141      * @param scaleFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given reference unit
142      * @param standardUnit indicates whether it is a standard unit with a definition in the locale, or a user-defined unit
143      */
144     private TorqueUnit(final String nameOrNameKey, final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem,
145             final TorqueUnit referenceUnit, final double scaleFactorToReferenceUnit, final boolean standardUnit)
146     {
147         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, referenceUnit, scaleFactorToReferenceUnit,
148                 standardUnit);
149         this.massUnit = referenceUnit.getMassUnit();
150         this.lengthUnit = referenceUnit.getLengthUnit();
151         this.durationUnit = referenceUnit.getDurationUnit();
152     }
153 
154     /**
155      * Build a user-defined unit with a conversion factor to another unit.
156      * @param name the long name of the unit
157      * @param abbreviation the abbreviation of the unit
158      * @param unitSystem the unit system, e.g. SI or Imperial
159      * @param referenceUnit the unit to convert to
160      * @param scaleFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given reference unit
161      */
162     public TorqueUnit(final String name, final String abbreviation, final UnitSystem unitSystem, final TorqueUnit referenceUnit,
163             final double scaleFactorToReferenceUnit)
164     {
165         this(name, abbreviation, unitSystem, referenceUnit, scaleFactorToReferenceUnit, false);
166     }
167 
168     /**
169      * @return massUnit
170      */
171     public final MassUnit getMassUnit()
172     {
173         return this.massUnit;
174     }
175 
176     /**
177      * @return lengthUnit
178      */
179     public final LengthUnit getLengthUnit()
180     {
181         return this.lengthUnit;
182     }
183 
184     /**
185      * @return durationUnit
186      */
187     public final DurationUnit getDurationUnit()
188     {
189         return this.durationUnit;
190     }
191 
192     /** {@inheritDoc} */
193     @Override
194     public final TorqueUnit getStandardUnit()
195     {
196         return NEWTON_METER;
197     }
198 
199     /** {@inheritDoc} */
200     @Override
201     public final String getSICoefficientsString()
202     {
203         return "kgm2/s2";
204     }
205 
206 }