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.SI_DERIVED;
6   
7   import org.djunits.unit.unitsystem.UnitSystem;
8   
9   /**
10   * Standard acceleration unit based on distance and time.
11   * <p>
12   * Copyright (c) 2015-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
13   * BSD-style license. See <a href="http://djunits.org/docs/license.html">DJUNITS License</a>.
14   * <p>
15   * $LastChangedDate: 2019-04-01 02:14:38 +0200 (Mon, 01 Apr 2019) $, @version $Revision: 370 $, by $Author: averbraeck $,
16   * initial version May 15, 2014 <br>
17   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
18   */
19  public class AccelerationUnit extends LinearUnit<AccelerationUnit>
20  {
21      /** */
22      private static final long serialVersionUID = 20140607L;
23  
24      /** the actual length unit, e.g. KILOMETER. */
25      private final LengthUnit lengthUnit;
26  
27      /** the actual time unit, e.g. HOUR. */
28      private final DurationUnit durationUnit;
29  
30      /** The SI unit for acceleration is m/s^2. */
31      public static final AccelerationUnit SI;
32  
33      /** m/s^2. */
34      public static final AccelerationUnit METER_PER_SECOND_2;
35  
36      /** km/h^2. */
37      public static final AccelerationUnit KM_PER_HOUR_2;
38  
39      /** ft/s^2. */
40      public static final AccelerationUnit FOOT_PER_SECOND_2;
41  
42      /** in/s^2. */
43      public static final AccelerationUnit INCH_PER_SECOND_2;
44  
45      /** mi/h^2. */
46      public static final AccelerationUnit MILE_PER_HOUR_2;
47  
48      /** mi/s^2. */
49      public static final AccelerationUnit MILE_PER_SECOND_2;
50  
51      /** kt/s. */
52      public static final AccelerationUnit KNOT_PER_SECOND;
53  
54      /** mi/h/s. */
55      public static final AccelerationUnit MILE_PER_HOUR_PER_SECOND;
56  
57      /** standard gravity. */
58      public static final AccelerationUnit STANDARD_GRAVITY;
59  
60      /** cm/s. */
61      public static final AccelerationUnit GAL;
62  
63      static
64      {
65          SI = new AccelerationUnit(LengthUnit.METER, DurationUnit.SECOND, "AccelerationUnit.m/s^2", SI_DERIVED);
66          METER_PER_SECOND_2 = SI;
67          KM_PER_HOUR_2 = new AccelerationUnit(LengthUnit.KILOMETER, DurationUnit.HOUR, "AccelerationUnit.km/h^2", SI_DERIVED);
68          FOOT_PER_SECOND_2 = new AccelerationUnit(LengthUnit.FOOT, DurationUnit.SECOND, "AccelerationUnit.ft/s^2", IMPERIAL);
69          INCH_PER_SECOND_2 = new AccelerationUnit(LengthUnit.INCH, DurationUnit.SECOND, "AccelerationUnit.in/s^2", IMPERIAL);
70          MILE_PER_HOUR_2 = new AccelerationUnit(LengthUnit.MILE, DurationUnit.HOUR, "AccelerationUnit.mi/h^2", IMPERIAL);
71          MILE_PER_SECOND_2 = new AccelerationUnit(LengthUnit.MILE, DurationUnit.SECOND, "AccelerationUnit.mi/s^2", IMPERIAL);
72          KNOT_PER_SECOND = new AccelerationUnit(SpeedUnit.KNOT, DurationUnit.SECOND, "AccelerationUnit.kt/s", IMPERIAL);
73          MILE_PER_HOUR_PER_SECOND =
74                  new AccelerationUnit(SpeedUnit.MILE_PER_HOUR, DurationUnit.SECOND, "AccelerationUnit.mi/h/s", IMPERIAL);
75          STANDARD_GRAVITY = new AccelerationUnit("AccelerationUnit.g", SI_DERIVED, METER_PER_SECOND_2, 9.80665);
76          GAL = new AccelerationUnit(LengthUnit.CENTIMETER, DurationUnit.SECOND, "AccelerationUnit.Gal", CGS);
77      }
78  
79      /**
80       * Define standard acceleration unit based on length and time. You can define units like meter/second^2 here.
81       * @param lengthUnit LengthUnit; the unit of length for the acceleration unit, e.g., meter
82       * @param durationUnit DurationUnit; the unit of time for the acceleration unit, e.g., second
83       * @param abbreviationKey String; the key to the locale file for the abbreviation of the unit
84       * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
85       */
86      private AccelerationUnit(final LengthUnit lengthUnit, final DurationUnit durationUnit, final String abbreviationKey,
87              final UnitSystem unitSystem)
88      {
89          super(abbreviationKey, unitSystem, METER_PER_SECOND_2,
90                  lengthUnit.getScaleFactor() / (durationUnit.getScaleFactor() * durationUnit.getScaleFactor()));
91          this.lengthUnit = lengthUnit;
92          this.durationUnit = durationUnit;
93      }
94  
95      /**
96       * Define user defined acceleration unit based on length and time. You can define units like meter/second^2 here.
97       * @param lengthUnit LengthUnit; the unit of length for the acceleration unit, e.g., meter
98       * @param durationUnit DurationUnit; the unit of time for the acceleration unit, e.g., second
99       * @param name String; the long name of the unit
100      * @param abbreviation String; the abbreviation of the unit
101      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
102      */
103     public AccelerationUnit(final LengthUnit lengthUnit, final DurationUnit durationUnit, final String name,
104             final String abbreviation, final UnitSystem unitSystem)
105     {
106         super(name, abbreviation, unitSystem, METER_PER_SECOND_2,
107                 lengthUnit.getScaleFactor() / (durationUnit.getScaleFactor() * durationUnit.getScaleFactor()));
108         this.lengthUnit = lengthUnit;
109         this.durationUnit = durationUnit;
110     }
111 
112     /**
113      * Define acceleration unit based on speed and time. You can define units like (mile/hour)/second here.
114      * @param speedUnit SpeedUnit; the unit of speed for the acceleration unit, e.g., knot
115      * @param durationUnit DurationUnit; the unit of time for the acceleration unit, e.g., second
116      * @param abbreviationKey String; the key to the locale file for the abbreviation of the unit
117      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
118      */
119     private AccelerationUnit(final SpeedUnit speedUnit, final DurationUnit durationUnit, final String abbreviationKey,
120             final UnitSystem unitSystem)
121     {
122         super(abbreviationKey, unitSystem, METER_PER_SECOND_2, speedUnit.getScaleFactor() / durationUnit.getScaleFactor());
123         this.lengthUnit = speedUnit.getLengthUnit();
124         this.durationUnit = durationUnit;
125     }
126 
127     /**
128      * Define user-defined acceleration unit based on speed and time. You can define units like (mile/hour)/second here.
129      * @param speedUnit SpeedUnit; the unit of speed for the acceleration unit, e.g., knot
130      * @param durationUnit DurationUnit; the unit of time for the acceleration unit, e.g., second
131      * @param name String; the long name of the unit
132      * @param abbreviation String; the abbreviation of the unit
133      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
134      */
135     public AccelerationUnit(final SpeedUnit speedUnit, final DurationUnit durationUnit, final String name,
136             final String abbreviation, final UnitSystem unitSystem)
137     {
138         super(name, abbreviation, unitSystem, METER_PER_SECOND_2, speedUnit.getScaleFactor() / durationUnit.getScaleFactor());
139         this.lengthUnit = speedUnit.getLengthUnit();
140         this.durationUnit = durationUnit;
141     }
142 
143     /**
144      * Build a unit with a conversion factor to another unit.
145      * @param abbreviationKey String; the key to the locale file for the abbreviation of the unit
146      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
147      * @param referenceUnit AccelerationUnit; the unit to convert to
148      * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
149      *            unit
150      */
151     private AccelerationUnit(final String abbreviationKey, final UnitSystem unitSystem, final AccelerationUnit referenceUnit,
152             final double scaleFactorToReferenceUnit)
153     {
154         super(abbreviationKey, unitSystem, referenceUnit, scaleFactorToReferenceUnit);
155         this.lengthUnit = referenceUnit.getLengthUnit();
156         this.durationUnit = referenceUnit.getDurationUnit();
157     }
158 
159     /**
160      * Build a user-defined unit with a conversion factor to another unit.
161      * @param name String; the long name of the unit
162      * @param abbreviation String; the abbreviation of the unit
163      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
164      * @param referenceUnit AccelerationUnit; the unit to convert to
165      * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
166      *            unit
167      */
168     public AccelerationUnit(final String name, final String abbreviation, final UnitSystem unitSystem,
169             final AccelerationUnit referenceUnit, final double scaleFactorToReferenceUnit)
170     {
171         super(name, abbreviation, unitSystem, referenceUnit, scaleFactorToReferenceUnit);
172         this.lengthUnit = referenceUnit.getLengthUnit();
173         this.durationUnit = referenceUnit.getDurationUnit();
174     }
175 
176     /**
177      * @return lengthUnit
178      */
179     public final LengthUnit getLengthUnit()
180     {
181         return this.lengthUnit;
182     }
183 
184     /**
185      * @return durationUnit
186      */
187     public final DurationUnit getDurationUnit()
188     {
189         return this.durationUnit;
190     }
191 
192     /** {@inheritDoc} */
193     @Override
194     public final AccelerationUnit getStandardUnit()
195     {
196         return METER_PER_SECOND_2;
197     }
198 
199     /** {@inheritDoc} */
200     @Override
201     public final String getSICoefficientsString()
202     {
203         return "m/s2";
204     }
205 
206 }