View Javadoc
1   package org.opentrafficsim.core.unit;
2   
3   import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.CGS;
4   import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.IMPERIAL;
5   import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.MTS;
6   import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.OTHER;
7   import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.SI_DERIVED;
8   
9   import org.opentrafficsim.core.unit.unitsystem.UnitSystem;
10  
11  /**
12   * The units of force.
13   * <p>
14   * Copyright (c) 2014 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
16   * <p>
17   * @version May 15, 2014 <br>
18   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
19   */
20  public class ForceUnit extends Unit<ForceUnit>
21  {
22      /** */
23      private static final long serialVersionUID = 20140607L;
24  
25      /** the unit of mass for the force unit, e.g., kilogram. */
26      private final MassUnit massUnit;
27  
28      /** the unit of length for the force unit, e.g., length. */
29      private final LengthUnit lengthUnit;
30  
31      /** the unit of time for the force unit, e.g., second. */
32      private final TimeUnit timeUnit;
33  
34      /** The SI unit for force is Newton. */
35      public static final ForceUnit SI;
36  
37      /** Newton. */
38      public static final ForceUnit NEWTON;
39  
40      /** Dyne. */
41      public static final ForceUnit DYNE;
42  
43      /** kilogram-force. */
44      public static final ForceUnit KILOGRAM_FORCE;
45  
46      /** ounce-force. */
47      public static final ForceUnit OUNCE_FORCE;
48  
49      /** pound-force. */
50      public static final ForceUnit POUND_FORCE;
51  
52      /** ton-force. */
53      public static final ForceUnit TON_FORCE;
54  
55      /** sthene. */
56      public static final ForceUnit STHENE;
57  
58      static
59      {
60          SI =
61                  new ForceUnit(MassUnit.KILOGRAM, LengthUnit.METER, TimeUnit.SECOND, "ForceUnit.newton", "ForceUnit.N",
62                          SI_DERIVED);
63          NEWTON = SI;
64          DYNE =
65                  new ForceUnit(MassUnit.GRAM, LengthUnit.CENTIMETER, TimeUnit.SECOND, "ForceUnit.dyne", "ForceUnit.dyn",
66                          CGS);
67          KILOGRAM_FORCE =
68                  new ForceUnit(MassUnit.KILOGRAM, AccelerationUnit.STANDARD_GRAVITY, "ForceUnit.kilogram-force",
69                          "ForceUnit.kgf", OTHER);
70          OUNCE_FORCE =
71                  new ForceUnit(MassUnit.OUNCE, AccelerationUnit.STANDARD_GRAVITY, "ForceUnit.ounce-force",
72                          "ForceUnit.ozf", IMPERIAL);
73          POUND_FORCE =
74                  new ForceUnit(MassUnit.POUND, AccelerationUnit.STANDARD_GRAVITY, "ForceUnit.pound-force",
75                          "ForceUnit.lbf", IMPERIAL);
76          TON_FORCE =
77                  new ForceUnit(MassUnit.TON_SHORT, AccelerationUnit.STANDARD_GRAVITY, "ForceUnit.ton-force",
78                          "ForceUnit.tnf", IMPERIAL);
79          STHENE =
80                  new ForceUnit(MassUnit.TON_METRIC, AccelerationUnit.METER_PER_SECOND_2, "ForceUnit.sthene",
81                          "ForceUnit.sn", MTS);
82      }
83  
84      /**
85       * Build a standard unit.
86       * @param massUnit the unit of mass for the force unit, e.g., kilogram
87       * @param lengthUnit the unit of length for the force unit, e.g., meter
88       * @param timeUnit the unit of time for the force unit, e.g., second
89       * @param nameKey the key to the locale file for the long name of the unit
90       * @param abbreviationKey the key to the locale file for the abbreviation of the unit
91       * @param unitSystem the unit system, e.g. SI or Imperial
92       */
93      public ForceUnit(final MassUnit massUnit, final LengthUnit lengthUnit, final TimeUnit timeUnit,
94              final String nameKey, final String abbreviationKey, final UnitSystem unitSystem)
95      {
96          super(nameKey, abbreviationKey, unitSystem, NEWTON, massUnit.getConversionFactorToStandardUnit()
97                  * lengthUnit.getConversionFactorToStandardUnit()
98                  / (timeUnit.getConversionFactorToStandardUnit() * timeUnit.getConversionFactorToStandardUnit()), true);
99          this.massUnit = massUnit;
100         this.lengthUnit = lengthUnit;
101         this.timeUnit = timeUnit;
102     }
103 
104     /**
105      * Build a unit with a conversion factor to another unit.
106      * @param massUnit the unit of mass for the force unit, e.g., kilogram
107      * @param accelerationUnit the unit of acceleration for the force unit, e.g., m/s^2
108      * @param nameKey the key to the locale file for the long name of the unit
109      * @param abbreviationKey the key to the locale file for the abbreviation of the unit
110      * @param unitSystem the unit system, e.g. SI or Imperial
111      */
112     public ForceUnit(final MassUnit massUnit, final AccelerationUnit accelerationUnit, final String nameKey,
113             final String abbreviationKey, final UnitSystem unitSystem)
114     {
115         super(nameKey, abbreviationKey, unitSystem, NEWTON, massUnit.getConversionFactorToStandardUnit()
116                 * accelerationUnit.getConversionFactorToStandardUnit(), true);
117         this.massUnit = massUnit;
118         this.lengthUnit = accelerationUnit.getLengthUnit();
119         this.timeUnit = accelerationUnit.getTimeUnit();
120     }
121 
122     /**
123      * @param nameKey the key to the locale file for the long name of the unit
124      * @param abbreviationKey the key to the locale file for the abbreviation of the unit
125      * @param unitSystem the unit system, e.g. SI or Imperial
126      * @param referenceUnit the unit to convert to
127      * @param conversionFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given
128      *            reference unit
129      */
130     public ForceUnit(final String nameKey, final String abbreviationKey, final UnitSystem unitSystem,
131             final ForceUnit referenceUnit, final double conversionFactorToReferenceUnit)
132     {
133         super(nameKey, abbreviationKey, unitSystem, referenceUnit, conversionFactorToReferenceUnit, true);
134         this.massUnit = referenceUnit.getMassUnit();
135         this.lengthUnit = referenceUnit.getLengthUnit();
136         this.timeUnit = referenceUnit.getTimeUnit();
137     }
138 
139     /**
140      * @return massUnit
141      */
142     public final MassUnit getMassUnit()
143     {
144         return this.massUnit;
145     }
146 
147     /**
148      * @return lengthUnit
149      */
150     public final LengthUnit getLengthUnit()
151     {
152         return this.lengthUnit;
153     }
154 
155     /**
156      * @return timeUnit
157      */
158     public final TimeUnit getTimeUnit()
159     {
160         return this.timeUnit;
161     }
162 
163     /** {@inheritDoc} */
164     @Override
165     public final ForceUnit getStandardUnit()
166     {
167         return NEWTON;
168     }
169 
170     /** {@inheritDoc} */
171     @Override
172     public final String getSICoefficientsString()
173     {
174         return "kgm/s2";
175     }
176 
177 }