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-03-02 19:06:46 +0100 (Sat, 02 Mar 2019) $, @version $Revision: 342 $, 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.N", SI_DERIVED);
62          NEWTON = SI;
63          DYNE = new ForceUnit(MassUnit.GRAM, LengthUnit.CENTIMETER, DurationUnit.SECOND, "ForceUnit.dyn", CGS);
64          KILOGRAM_FORCE = new ForceUnit(MassUnit.KILOGRAM, AccelerationUnit.STANDARD_GRAVITY, "ForceUnit.kgf", OTHER);
65          OUNCE_FORCE = new ForceUnit(MassUnit.OUNCE, AccelerationUnit.STANDARD_GRAVITY, "ForceUnit.ozf", IMPERIAL);
66          POUND_FORCE = new ForceUnit(MassUnit.POUND, AccelerationUnit.STANDARD_GRAVITY, "ForceUnit.lbf", IMPERIAL);
67          TON_FORCE = new ForceUnit(MassUnit.TON_SHORT, AccelerationUnit.STANDARD_GRAVITY, "ForceUnit.tnf", IMPERIAL);
68          STHENE = new ForceUnit(MassUnit.TON_METRIC, AccelerationUnit.METER_PER_SECOND_2, "ForceUnit.sn", MTS);
69      }
70  
71      /**
72       * Build a ForceUnit based on its constituent base units, e.g. a N = km.m/s^2.
73       * @param massUnit MassUnit; the unit of mass for the force unit, e.g., kilogram
74       * @param lengthUnit LengthUnit; the unit of length for the force unit, e.g., meter
75       * @param durationUnit DurationUnit; the unit of time for the force unit, e.g., second
76       * @param abbreviationKey String; the key to the locale file for the abbreviation of the unit
77       * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
78       */
79      private ForceUnit(final MassUnit massUnit, final LengthUnit lengthUnit, final DurationUnit durationUnit,
80              final String abbreviationKey, final UnitSystem unitSystem)
81      {
82          super(abbreviationKey, unitSystem, NEWTON, massUnit.getScaleFactor() * lengthUnit.getScaleFactor()
83                  / (durationUnit.getScaleFactor() * durationUnit.getScaleFactor()));
84          this.massUnit = massUnit;
85          this.lengthUnit = lengthUnit;
86          this.durationUnit = durationUnit;
87      }
88  
89      /**
90       * Build a user-defined ForceUnit based on its constituent base units, e.g. a N = km.m/s^2.
91       * @param massUnit MassUnit; the unit of mass for the force unit, e.g., kilogram
92       * @param lengthUnit LengthUnit; the unit of length for the force unit, e.g., meter
93       * @param durationUnit DurationUnit; the unit of time for the force unit, e.g., second
94       * @param name String; the long name of the unit
95       * @param abbreviation String; the abbreviation of the unit
96       * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
97       */
98      public ForceUnit(final MassUnit massUnit, final LengthUnit lengthUnit, final DurationUnit durationUnit, final String name,
99              final String abbreviation, final UnitSystem unitSystem)
100     {
101         super(name, abbreviation, unitSystem, NEWTON, massUnit.getScaleFactor() * lengthUnit.getScaleFactor()
102                 / (durationUnit.getScaleFactor() * durationUnit.getScaleFactor()));
103         this.massUnit = massUnit;
104         this.lengthUnit = lengthUnit;
105         this.durationUnit = durationUnit;
106     }
107 
108     /**
109      * Build a ForceUnit based on a MassUnit and an AccelerationUnit, i.e. based on F=m.a.
110      * @param massUnit MassUnit; the unit of mass for the force unit, e.g., kilogram
111      * @param accelerationUnit AccelerationUnit; the unit of acceleration for the force unit, e.g., m/s^2
112      * @param abbreviationKey String; the key to the locale file for the abbreviation of the unit
113      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
114      */
115     private ForceUnit(final MassUnit massUnit, final AccelerationUnit accelerationUnit, final String abbreviationKey,
116             final UnitSystem unitSystem)
117     {
118         super(abbreviationKey, unitSystem, NEWTON, massUnit.getScaleFactor() * accelerationUnit.getScaleFactor());
119         this.massUnit = massUnit;
120         this.lengthUnit = accelerationUnit.getLengthUnit();
121         this.durationUnit = accelerationUnit.getDurationUnit();
122     }
123 
124     /**
125      * Build a user-defined ForceUnit based on a MassUnit and an AccelerationUnit, i.e. based on F=m.a.
126      * @param massUnit MassUnit; the unit of mass for the force unit, e.g., kilogram
127      * @param accelerationUnit AccelerationUnit; the unit of acceleration for the force unit, e.g., m/s^2
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 ForceUnit(final MassUnit massUnit, final AccelerationUnit accelerationUnit, final String name,
133             final String abbreviation, final UnitSystem unitSystem)
134     {
135         super(name, abbreviation, unitSystem, NEWTON, massUnit.getScaleFactor() * accelerationUnit.getScaleFactor());
136         this.massUnit = massUnit;
137         this.lengthUnit = accelerationUnit.getLengthUnit();
138         this.durationUnit = accelerationUnit.getDurationUnit();
139     }
140 
141     /**
142      * Build a ForceUnit with a conversion factor to another ForceUnit.
143      * @param abbreviationKey String; the key to the locale file for the abbreviation of the unit
144      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
145      * @param referenceUnit ForceUnit; 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      */
149     private ForceUnit(final String abbreviationKey, final UnitSystem unitSystem, final ForceUnit referenceUnit,
150             final double scaleFactorToReferenceUnit)
151     {
152         super(abbreviationKey, unitSystem, referenceUnit, scaleFactorToReferenceUnit);
153         this.massUnit = referenceUnit.getMassUnit();
154         this.lengthUnit = referenceUnit.getLengthUnit();
155         this.durationUnit = referenceUnit.getDurationUnit();
156     }
157 
158     /**
159      * Build a user-defined ForceUnit with a conversion factor to another ForceUnit.
160      * @param name String; the long name of the unit
161      * @param abbreviation String; the abbreviation of the unit
162      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
163      * @param referenceUnit ForceUnit; the unit to convert to
164      * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
165      *            unit
166      */
167     public ForceUnit(final String name, final String abbreviation, final UnitSystem unitSystem, final ForceUnit referenceUnit,
168             final double scaleFactorToReferenceUnit)
169     {
170         super(name, abbreviation, unitSystem, referenceUnit, scaleFactorToReferenceUnit);
171         this.massUnit = referenceUnit.getMassUnit();
172         this.lengthUnit = referenceUnit.getLengthUnit();
173         this.durationUnit = referenceUnit.getDurationUnit();
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 ForceUnit getStandardUnit()
203     {
204         return NEWTON;
205     }
206 
207     /** {@inheritDoc} */
208     @Override
209     public final String getSICoefficientsString()
210     {
211         return "kgm/s2";
212     }
213 
214 }