View Javadoc
1   package org.djunits.unit;
2   
3   import static org.djunits.unit.unitsystem.UnitSystem.CGS;
4   import static org.djunits.unit.unitsystem.UnitSystem.IMPERIAL;
5   import static org.djunits.unit.unitsystem.UnitSystem.MTS;
6   import static org.djunits.unit.unitsystem.UnitSystem.OTHER;
7   import static org.djunits.unit.unitsystem.UnitSystem.SI_DERIVED;
8   
9   import org.djunits.unit.unitsystem.UnitSystem;
10  
11  /**
12   * The units of force.
13   * <p>
14   * Copyright (c) 2015-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15   * BSD-style license. See <a href="http://djunits.org/docs/license.html">DJUNITS License</a>.
16   * <p>
17   * $LastChangedDate: 2019-01-18 00:35:01 +0100 (Fri, 18 Jan 2019) $, @version $Revision: 324 $, by $Author: averbraeck $,
18   * initial version May 15, 2014 <br>
19   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
20   */
21  public class ForceUnit extends LinearUnit<ForceUnit>
22  {
23      /** */
24      private static final long serialVersionUID = 20140607L;
25  
26      /** the unit of mass for the force unit, e.g., kilogram. */
27      private final MassUnit massUnit;
28  
29      /** the unit of length for the force unit, e.g., length. */
30      private final LengthUnit lengthUnit;
31  
32      /** the unit of time for the force unit, e.g., second. */
33      private final DurationUnit durationUnit;
34  
35      /** The SI unit for force is Newton. */
36      public static final ForceUnit SI;
37  
38      /** Newton. */
39      public static final ForceUnit NEWTON;
40  
41      /** Dyne. */
42      public static final ForceUnit DYNE;
43  
44      /** kilogram-force. */
45      public static final ForceUnit KILOGRAM_FORCE;
46  
47      /** ounce-force. */
48      public static final ForceUnit OUNCE_FORCE;
49  
50      /** pound-force. */
51      public static final ForceUnit POUND_FORCE;
52  
53      /** ton-force. */
54      public static final ForceUnit TON_FORCE;
55  
56      /** sthene. */
57      public static final ForceUnit STHENE;
58  
59      static
60      {
61          SI = new ForceUnit(MassUnit.KILOGRAM, LengthUnit.METER, DurationUnit.SECOND, "ForceUnit.newton", "ForceUnit.N",
62                  SI_DERIVED, true);
63          NEWTON = SI;
64          DYNE = new ForceUnit(MassUnit.GRAM, LengthUnit.CENTIMETER, DurationUnit.SECOND, "ForceUnit.dyne", "ForceUnit.dyn", CGS,
65                  true);
66          KILOGRAM_FORCE = new ForceUnit(MassUnit.KILOGRAM, AccelerationUnit.STANDARD_GRAVITY, "ForceUnit.kilogram-force",
67                  "ForceUnit.kgf", OTHER, true);
68          OUNCE_FORCE = new ForceUnit(MassUnit.OUNCE, AccelerationUnit.STANDARD_GRAVITY, "ForceUnit.ounce-force", "ForceUnit.ozf",
69                  IMPERIAL, true);
70          POUND_FORCE = new ForceUnit(MassUnit.POUND, AccelerationUnit.STANDARD_GRAVITY, "ForceUnit.pound-force", "ForceUnit.lbf",
71                  IMPERIAL, true);
72          TON_FORCE = new ForceUnit(MassUnit.TON_SHORT, AccelerationUnit.STANDARD_GRAVITY, "ForceUnit.ton-force", "ForceUnit.tnf",
73                  IMPERIAL, true);
74          STHENE = new ForceUnit(MassUnit.TON_METRIC, AccelerationUnit.METER_PER_SECOND_2, "ForceUnit.sthene", "ForceUnit.sn",
75                  MTS, true);
76      }
77  
78      /**
79       * Build a ForceUnit based on its constituent base units, e.g. a N = km.m/s^2.
80       * @param massUnit MassUnit; the unit of mass for the force unit, e.g., kilogram
81       * @param lengthUnit LengthUnit; the unit of length for the force unit, e.g., meter
82       * @param durationUnit DurationUnit; the unit of time for the force unit, e.g., second
83       * @param nameOrNameKey String; if standardUnit: the key to the locale file for the long name of the unit, otherwise the
84       *            name itself
85       * @param abbreviationOrAbbreviationKey String; if standardUnit: the key to the locale file for the abbreviation of the
86       *            unit, otherwise the abbreviation itself
87       * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
88       * @param standardUnit boolean; indicates whether it is a standard unit with a definition in the locale, or a user-defined
89       *            unit
90       */
91      private ForceUnit(final MassUnit massUnit, final LengthUnit lengthUnit, final DurationUnit durationUnit,
92              final String nameOrNameKey, final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem,
93              final boolean standardUnit)
94      {
95          super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, NEWTON, massUnit.getScaleFactor()
96                  * lengthUnit.getScaleFactor() / (durationUnit.getScaleFactor() * durationUnit.getScaleFactor()), standardUnit);
97          this.massUnit = massUnit;
98          this.lengthUnit = lengthUnit;
99          this.durationUnit = durationUnit;
100     }
101 
102     /**
103      * Build a user-defined ForceUnit based on its constituent base units, e.g. a N = km.m/s^2.
104      * @param massUnit MassUnit; the unit of mass for the force unit, e.g., kilogram
105      * @param lengthUnit LengthUnit; the unit of length for the force unit, e.g., meter
106      * @param durationUnit DurationUnit; the unit of time for the force unit, e.g., second
107      * @param name String; the long name of the unit
108      * @param abbreviation String; the abbreviation of the unit
109      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
110      */
111     public ForceUnit(final MassUnit massUnit, final LengthUnit lengthUnit, final DurationUnit durationUnit, final String name,
112             final String abbreviation, final UnitSystem unitSystem)
113     {
114         this(massUnit, lengthUnit, durationUnit, name, abbreviation, unitSystem, false);
115     }
116 
117     /**
118      * Build a ForceUnit based on a MassUnit and an AccelerationUnit, i.e. based on F=m.a.
119      * @param massUnit MassUnit; the unit of mass for the force unit, e.g., kilogram
120      * @param accelerationUnit AccelerationUnit; the unit of acceleration for the force unit, e.g., m/s^2
121      * @param nameOrNameKey String; if standardUnit: the key to the locale file for the long name of the unit, otherwise the
122      *            name itself
123      * @param abbreviationOrAbbreviationKey String; if standardUnit: the key to the locale file for the abbreviation of the
124      *            unit, otherwise the abbreviation itself
125      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
126      * @param standardUnit boolean; indicates whether it is a standard unit with a definition in the locale, or a user-defined
127      *            unit
128      */
129     private ForceUnit(final MassUnit massUnit, final AccelerationUnit accelerationUnit, final String nameOrNameKey,
130             final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem, final boolean standardUnit)
131     {
132         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, NEWTON,
133                 massUnit.getScaleFactor() * accelerationUnit.getScaleFactor(), standardUnit);
134         this.massUnit = massUnit;
135         this.lengthUnit = accelerationUnit.getLengthUnit();
136         this.durationUnit = accelerationUnit.getDurationUnit();
137     }
138 
139     /**
140      * Build a user-defined ForceUnit based on a MassUnit and an AccelerationUnit, i.e. based on F=m.a.
141      * @param massUnit MassUnit; the unit of mass for the force unit, e.g., kilogram
142      * @param accelerationUnit AccelerationUnit; the unit of acceleration for the force unit, e.g., m/s^2
143      * @param name String; the long name of the unit
144      * @param abbreviation String; the abbreviation of the unit
145      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
146      */
147     public ForceUnit(final MassUnit massUnit, final AccelerationUnit accelerationUnit, final String name,
148             final String abbreviation, final UnitSystem unitSystem)
149     {
150         this(massUnit, accelerationUnit, name, abbreviation, unitSystem, false);
151     }
152 
153     /**
154      * Build a ForceUnit with a conversion factor to another ForceUnit.
155      * @param nameOrNameKey String; if standardUnit: the key to the locale file for the long name of the unit, otherwise the
156      *            name itself
157      * @param abbreviationOrAbbreviationKey String; if standardUnit: the key to the locale file for the abbreviation of the
158      *            unit, otherwise the abbreviation itself
159      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
160      * @param referenceUnit ForceUnit; the unit to convert to
161      * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
162      *            unit
163      * @param standardUnit boolean; indicates whether it is a standard unit with a definition in the locale, or a user-defined
164      *            unit
165      */
166     private ForceUnit(final String nameOrNameKey, final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem,
167             final ForceUnit referenceUnit, final double scaleFactorToReferenceUnit, final boolean standardUnit)
168     {
169         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, referenceUnit, scaleFactorToReferenceUnit,
170                 standardUnit);
171         this.massUnit = referenceUnit.getMassUnit();
172         this.lengthUnit = referenceUnit.getLengthUnit();
173         this.durationUnit = referenceUnit.getDurationUnit();
174     }
175 
176     /**
177      * Build a user-defined ForceUnit with a conversion factor to another ForceUnit.
178      * @param name String; the long name of the unit
179      * @param abbreviation String; the abbreviation of the unit
180      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
181      * @param referenceUnit ForceUnit; the unit to convert to
182      * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
183      *            unit
184      */
185     public ForceUnit(final String name, final String abbreviation, final UnitSystem unitSystem, final ForceUnit referenceUnit,
186             final double scaleFactorToReferenceUnit)
187     {
188         this(name, abbreviation, unitSystem, referenceUnit, scaleFactorToReferenceUnit, false);
189     }
190 
191     /**
192      * @return massUnit
193      */
194     public final MassUnit getMassUnit()
195     {
196         return this.massUnit;
197     }
198 
199     /**
200      * @return lengthUnit
201      */
202     public final LengthUnit getLengthUnit()
203     {
204         return this.lengthUnit;
205     }
206 
207     /**
208      * @return durationUnit
209      */
210     public final DurationUnit getDurationUnit()
211     {
212         return this.durationUnit;
213     }
214 
215     /** {@inheritDoc} */
216     @Override
217     public final ForceUnit getStandardUnit()
218     {
219         return NEWTON;
220     }
221 
222     /** {@inheritDoc} */
223     @Override
224     public final String getSICoefficientsString()
225     {
226         return "kgm/s2";
227     }
228 
229 }