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 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: 2015-10-04 20:48:33 +0200 (Sun, 04 Oct 2015) $, @version $Revision: 87 $, by $Author: averbraeck $, initial
18   * version May 15, 2014 <br>
19   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
20   */
21  public class ForceUnit extends Unit<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 TimeUnit timeUnit;
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 =
62              new ForceUnit(MassUnit.KILOGRAM, LengthUnit.METER, TimeUnit.SECOND, "ForceUnit.newton", "ForceUnit.N",
63                  SI_DERIVED, true);
64          NEWTON = SI;
65          DYNE =
66              new ForceUnit(MassUnit.GRAM, LengthUnit.CENTIMETER, TimeUnit.SECOND, "ForceUnit.dyne", "ForceUnit.dyn",
67                  CGS, true);
68          KILOGRAM_FORCE =
69              new ForceUnit(MassUnit.KILOGRAM, AccelerationUnit.STANDARD_GRAVITY, "ForceUnit.kilogram-force",
70                  "ForceUnit.kgf", OTHER, true);
71          OUNCE_FORCE =
72              new ForceUnit(MassUnit.OUNCE, AccelerationUnit.STANDARD_GRAVITY, "ForceUnit.ounce-force", "ForceUnit.ozf",
73                  IMPERIAL, true);
74          POUND_FORCE =
75              new ForceUnit(MassUnit.POUND, AccelerationUnit.STANDARD_GRAVITY, "ForceUnit.pound-force", "ForceUnit.lbf",
76                  IMPERIAL, true);
77          TON_FORCE =
78              new ForceUnit(MassUnit.TON_SHORT, AccelerationUnit.STANDARD_GRAVITY, "ForceUnit.ton-force",
79                  "ForceUnit.tnf", IMPERIAL, true);
80          STHENE =
81              new ForceUnit(MassUnit.TON_METRIC, AccelerationUnit.METER_PER_SECOND_2, "ForceUnit.sthene", "ForceUnit.sn",
82                  MTS, true);
83      }
84  
85      /**
86       * Build a ForceUnit based on its constituent base units, e.g. a N = km.m/s^2.
87       * @param massUnit the unit of mass for the force unit, e.g., kilogram
88       * @param lengthUnit the unit of length for the force unit, e.g., meter
89       * @param timeUnit the unit of time for the force unit, e.g., second
90       * @param nameOrNameKey if standardUnit: the key to the locale file for the long name of the unit, otherwise the name itself
91       * @param abbreviationOrAbbreviationKey if standardUnit: the key to the locale file for the abbreviation of the unit,
92       *            otherwise the abbreviation itself
93       * @param unitSystem the unit system, e.g. SI or Imperial
94       * @param standardUnit indicates whether it is a standard unit with a definition in the locale, or a user-defined unit
95       */
96      private ForceUnit(final MassUnit massUnit, final LengthUnit lengthUnit, final TimeUnit timeUnit,
97          final String nameOrNameKey, final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem,
98          final boolean standardUnit)
99      {
100         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, NEWTON, massUnit
101             .getConversionFactorToStandardUnit()
102             * lengthUnit.getConversionFactorToStandardUnit()
103             / (timeUnit.getConversionFactorToStandardUnit() * timeUnit.getConversionFactorToStandardUnit()),
104             standardUnit);
105         this.massUnit = massUnit;
106         this.lengthUnit = lengthUnit;
107         this.timeUnit = timeUnit;
108     }
109 
110     /**
111      * Build a user-defined ForceUnit based on its constituent base units, e.g. a N = km.m/s^2.
112      * @param massUnit the unit of mass for the force unit, e.g., kilogram
113      * @param lengthUnit the unit of length for the force unit, e.g., meter
114      * @param timeUnit the unit of time for the force unit, e.g., second
115      * @param name the long name of the unit
116      * @param abbreviation the abbreviation of the unit
117      * @param unitSystem the unit system, e.g. SI or Imperial
118      */
119     public ForceUnit(final MassUnit massUnit, final LengthUnit lengthUnit, final TimeUnit timeUnit, final String name,
120         final String abbreviation, final UnitSystem unitSystem)
121     {
122         this(massUnit, lengthUnit, timeUnit, name, abbreviation, unitSystem, false);
123     }
124 
125     /**
126      * Build a ForceUnit based on a MassUnit and an AccelerationUnit, i.e. based on F=m.a.
127      * @param massUnit the unit of mass for the force unit, e.g., kilogram
128      * @param accelerationUnit the unit of acceleration for the force unit, e.g., m/s^2
129      * @param nameOrNameKey if standardUnit: the key to the locale file for the long name of the unit, otherwise the name itself
130      * @param abbreviationOrAbbreviationKey if standardUnit: the key to the locale file for the abbreviation of the unit,
131      *            otherwise the abbreviation itself
132      * @param unitSystem the unit system, e.g. SI or Imperial
133      * @param standardUnit indicates whether it is a standard unit with a definition in the locale, or a user-defined unit
134      */
135     private ForceUnit(final MassUnit massUnit, final AccelerationUnit accelerationUnit, final String nameOrNameKey,
136         final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem, final boolean standardUnit)
137     {
138         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, NEWTON, massUnit
139             .getConversionFactorToStandardUnit()
140             * accelerationUnit.getConversionFactorToStandardUnit(), standardUnit);
141         this.massUnit = massUnit;
142         this.lengthUnit = accelerationUnit.getLengthUnit();
143         this.timeUnit = accelerationUnit.getTimeUnit();
144     }
145 
146     /**
147      * Build a user-defined ForceUnit based on a MassUnit and an AccelerationUnit, i.e. based on F=m.a.
148      * @param massUnit the unit of mass for the force unit, e.g., kilogram
149      * @param accelerationUnit the unit of acceleration for the force unit, e.g., m/s^2
150      * @param name the long name of the unit
151      * @param abbreviation the abbreviation of the unit
152      * @param unitSystem the unit system, e.g. SI or Imperial
153      */
154     public ForceUnit(final MassUnit massUnit, final AccelerationUnit accelerationUnit, final String name,
155         final String abbreviation, final UnitSystem unitSystem)
156     {
157         this(massUnit, accelerationUnit, name, abbreviation, unitSystem, false);
158     }
159 
160     /**
161      * Build a ForceUnit with a conversion factor to another ForceUnit.
162      * @param nameOrNameKey if standardUnit: the key to the locale file for the long name of the unit, otherwise the name itself
163      * @param abbreviationOrAbbreviationKey if standardUnit: the key to the locale file for the abbreviation of the unit,
164      *            otherwise the abbreviation itself
165      * @param unitSystem the unit system, e.g. SI or Imperial
166      * @param referenceUnit the unit to convert to
167      * @param conversionFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given reference unit
168      * @param standardUnit indicates whether it is a standard unit with a definition in the locale, or a user-defined unit
169      */
170     private ForceUnit(final String nameOrNameKey, final String abbreviationOrAbbreviationKey,
171         final UnitSystem unitSystem, final ForceUnit referenceUnit, final double conversionFactorToReferenceUnit,
172         final boolean standardUnit)
173     {
174         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, referenceUnit, conversionFactorToReferenceUnit,
175             standardUnit);
176         this.massUnit = referenceUnit.getMassUnit();
177         this.lengthUnit = referenceUnit.getLengthUnit();
178         this.timeUnit = referenceUnit.getTimeUnit();
179     }
180 
181     /**
182      * Build a user-defined ForceUnit with a conversion factor to another ForceUnit.
183      * @param name the long name of the unit
184      * @param abbreviation the abbreviation of the unit
185      * @param unitSystem the unit system, e.g. SI or Imperial
186      * @param referenceUnit the unit to convert to
187      * @param conversionFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given reference unit
188      */
189     public ForceUnit(final String name, final String abbreviation, final UnitSystem unitSystem,
190         final ForceUnit referenceUnit, final double conversionFactorToReferenceUnit)
191     {
192         this(name, abbreviation, unitSystem, referenceUnit, conversionFactorToReferenceUnit, false);
193     }
194 
195     /**
196      * @return massUnit
197      */
198     public final MassUnit getMassUnit()
199     {
200         return this.massUnit;
201     }
202 
203     /**
204      * @return lengthUnit
205      */
206     public final LengthUnit getLengthUnit()
207     {
208         return this.lengthUnit;
209     }
210 
211     /**
212      * @return timeUnit
213      */
214     public final TimeUnit getTimeUnit()
215     {
216         return this.timeUnit;
217     }
218 
219     /** {@inheritDoc} */
220     @Override
221     public final ForceUnit getStandardUnit()
222     {
223         return NEWTON;
224     }
225 
226     /** {@inheritDoc} */
227     @Override
228     public final String getSICoefficientsString()
229     {
230         return "kgm/s2";
231     }
232 
233 }