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-2018 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: 2018-01-28 03:17:44 +0100 (Sun, 28 Jan 2018) $, @version $Revision: 256 $, 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 the unit of mass for the force unit, e.g., kilogram
81       * @param lengthUnit the unit of length for the force unit, e.g., meter
82       * @param durationUnit the unit of time for the force unit, e.g., second
83       * @param nameOrNameKey if standardUnit: the key to the locale file for the long name of the unit, otherwise the name itself
84       * @param abbreviationOrAbbreviationKey if standardUnit: the key to the locale file for the abbreviation of the unit,
85       *            otherwise the abbreviation itself
86       * @param unitSystem the unit system, e.g. SI or Imperial
87       * @param standardUnit indicates whether it is a standard unit with a definition in the locale, or a user-defined unit
88       */
89      private ForceUnit(final MassUnit massUnit, final LengthUnit lengthUnit, final DurationUnit durationUnit,
90              final String nameOrNameKey, final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem,
91              final boolean standardUnit)
92      {
93          super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, NEWTON, massUnit.getScaleFactor()
94                  * lengthUnit.getScaleFactor() / (durationUnit.getScaleFactor() * durationUnit.getScaleFactor()), standardUnit);
95          this.massUnit = massUnit;
96          this.lengthUnit = lengthUnit;
97          this.durationUnit = durationUnit;
98      }
99  
100     /**
101      * Build a user-defined ForceUnit based on its constituent base units, e.g. a N = km.m/s^2.
102      * @param massUnit the unit of mass for the force unit, e.g., kilogram
103      * @param lengthUnit the unit of length for the force unit, e.g., meter
104      * @param durationUnit the unit of time for the force unit, e.g., second
105      * @param name the long name of the unit
106      * @param abbreviation the abbreviation of the unit
107      * @param unitSystem the unit system, e.g. SI or Imperial
108      */
109     public ForceUnit(final MassUnit massUnit, final LengthUnit lengthUnit, final DurationUnit durationUnit, final String name,
110             final String abbreviation, final UnitSystem unitSystem)
111     {
112         this(massUnit, lengthUnit, durationUnit, name, abbreviation, unitSystem, false);
113     }
114 
115     /**
116      * Build a ForceUnit based on a MassUnit and an AccelerationUnit, i.e. based on F=m.a.
117      * @param massUnit the unit of mass for the force unit, e.g., kilogram
118      * @param accelerationUnit the unit of acceleration for the force unit, e.g., m/s^2
119      * @param nameOrNameKey if standardUnit: the key to the locale file for the long name of the unit, otherwise the name itself
120      * @param abbreviationOrAbbreviationKey if standardUnit: the key to the locale file for the abbreviation of the unit,
121      *            otherwise the abbreviation itself
122      * @param unitSystem the unit system, e.g. SI or Imperial
123      * @param standardUnit indicates whether it is a standard unit with a definition in the locale, or a user-defined unit
124      */
125     private ForceUnit(final MassUnit massUnit, final AccelerationUnit accelerationUnit, final String nameOrNameKey,
126             final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem, final boolean standardUnit)
127     {
128         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, NEWTON,
129                 massUnit.getScaleFactor() * accelerationUnit.getScaleFactor(), standardUnit);
130         this.massUnit = massUnit;
131         this.lengthUnit = accelerationUnit.getLengthUnit();
132         this.durationUnit = accelerationUnit.getDurationUnit();
133     }
134 
135     /**
136      * Build a user-defined ForceUnit based on a MassUnit and an AccelerationUnit, i.e. based on F=m.a.
137      * @param massUnit the unit of mass for the force unit, e.g., kilogram
138      * @param accelerationUnit the unit of acceleration for the force unit, e.g., m/s^2
139      * @param name the long name of the unit
140      * @param abbreviation the abbreviation of the unit
141      * @param unitSystem the unit system, e.g. SI or Imperial
142      */
143     public ForceUnit(final MassUnit massUnit, final AccelerationUnit accelerationUnit, final String name,
144             final String abbreviation, final UnitSystem unitSystem)
145     {
146         this(massUnit, accelerationUnit, name, abbreviation, unitSystem, false);
147     }
148 
149     /**
150      * Build a ForceUnit with a conversion factor to another ForceUnit.
151      * @param nameOrNameKey if standardUnit: the key to the locale file for the long name of the unit, otherwise the name itself
152      * @param abbreviationOrAbbreviationKey if standardUnit: the key to the locale file for the abbreviation of the unit,
153      *            otherwise the abbreviation itself
154      * @param unitSystem the unit system, e.g. SI or Imperial
155      * @param referenceUnit the unit to convert to
156      * @param scaleFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given reference unit
157      * @param standardUnit indicates whether it is a standard unit with a definition in the locale, or a user-defined unit
158      */
159     private ForceUnit(final String nameOrNameKey, final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem,
160             final ForceUnit referenceUnit, final double scaleFactorToReferenceUnit, final boolean standardUnit)
161     {
162         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, referenceUnit, scaleFactorToReferenceUnit,
163                 standardUnit);
164         this.massUnit = referenceUnit.getMassUnit();
165         this.lengthUnit = referenceUnit.getLengthUnit();
166         this.durationUnit = referenceUnit.getDurationUnit();
167     }
168 
169     /**
170      * Build a user-defined ForceUnit with a conversion factor to another ForceUnit.
171      * @param name the long name of the unit
172      * @param abbreviation the abbreviation of the unit
173      * @param unitSystem the unit system, e.g. SI or Imperial
174      * @param referenceUnit the unit to convert to
175      * @param scaleFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given reference unit
176      */
177     public ForceUnit(final String name, final String abbreviation, final UnitSystem unitSystem, final ForceUnit referenceUnit,
178             final double scaleFactorToReferenceUnit)
179     {
180         this(name, abbreviation, unitSystem, referenceUnit, scaleFactorToReferenceUnit, false);
181     }
182 
183     /**
184      * @return massUnit
185      */
186     public final MassUnit getMassUnit()
187     {
188         return this.massUnit;
189     }
190 
191     /**
192      * @return lengthUnit
193      */
194     public final LengthUnit getLengthUnit()
195     {
196         return this.lengthUnit;
197     }
198 
199     /**
200      * @return durationUnit
201      */
202     public final DurationUnit getDurationUnit()
203     {
204         return this.durationUnit;
205     }
206 
207     /** {@inheritDoc} */
208     @Override
209     public final ForceUnit getStandardUnit()
210     {
211         return NEWTON;
212     }
213 
214     /** {@inheritDoc} */
215     @Override
216     public final String getSICoefficientsString()
217     {
218         return "kgm/s2";
219     }
220 
221 }