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