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-01-18 00:35:01 +0100 (Fri, 18 Jan 2019) $, @version $Revision: 324 $, 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      /** standard gravity. */
61      public static final AccelerationUnit GAL;
62  
63      static
64      {
65          SI = new AccelerationUnit(LengthUnit.METER, DurationUnit.SECOND, "AccelerationUnit.meter_per_second_squared",
66                  "AccelerationUnit.m/s^2", SI_DERIVED, true);
67          METER_PER_SECOND_2 = SI;
68          KM_PER_HOUR_2 = new AccelerationUnit(LengthUnit.KILOMETER, DurationUnit.HOUR, "AccelerationUnit.km_per_hour_squared",
69                  "AccelerationUnit.km/h^2", SI_DERIVED, true);
70          FOOT_PER_SECOND_2 = new AccelerationUnit(LengthUnit.FOOT, DurationUnit.SECOND,
71                  "AccelerationUnit.foot_per_second_squared", "AccelerationUnit.ft/s^2", IMPERIAL, true);
72          INCH_PER_SECOND_2 = new AccelerationUnit(LengthUnit.INCH, DurationUnit.SECOND,
73                  "AccelerationUnit.inch_per_second_squared", "AccelerationUnit.in/s^2", IMPERIAL, true);
74          MILE_PER_HOUR_2 = new AccelerationUnit(LengthUnit.MILE, DurationUnit.HOUR, "AccelerationUnit.mile_per_hour_squared",
75                  "AccelerationUnit.mi/h^2", IMPERIAL, true);
76          MILE_PER_SECOND_2 = new AccelerationUnit(LengthUnit.MILE, DurationUnit.SECOND,
77                  "AccelerationUnit.mile_per_second_squared", "AccelerationUnit.mi/s^2", IMPERIAL, true);
78          KNOT_PER_SECOND = new AccelerationUnit(SpeedUnit.KNOT, DurationUnit.SECOND, "AccelerationUnit.knot_per_second",
79                  "AccelerationUnit.kt/s", IMPERIAL, true);
80          MILE_PER_HOUR_PER_SECOND = new AccelerationUnit(SpeedUnit.MILE_PER_HOUR, DurationUnit.SECOND,
81                  "AccelerationUnit.mile_per_hour_per_second", "AccelerationUnit.mi/h/s", IMPERIAL, true);
82          STANDARD_GRAVITY = new AccelerationUnit("AccelerationUnit.standard_gravity", "AccelerationUnit.g", SI_DERIVED,
83                  METER_PER_SECOND_2, 9.80665, true);
84          GAL = new AccelerationUnit(LengthUnit.CENTIMETER, DurationUnit.SECOND, "AccelerationUnit.gal", "AccelerationUnit.Gal",
85                  CGS, true);
86      }
87  
88      /**
89       * Define acceleration unit based on length and time. You can define units like meter/second^2 here.
90       * @param lengthUnit LengthUnit; the unit of length for the acceleration unit, e.g., meter
91       * @param durationUnit DurationUnit; the unit of time for the acceleration unit, e.g., second
92       * @param nameOrNameKey String; if standardUnit: the key to the locale file for the long name of the unit, otherwise the
93       *            name itself
94       * @param abbreviationOrAbbreviationKey String; if standardUnit: the key to the locale file for the abbreviation of the
95       *            unit, otherwise the abbreviation itself
96       * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
97       * @param standardUnit boolean; indicates whether it is a standard unit with a definition in the locale, or a user-defined
98       *            unit
99       */
100     private AccelerationUnit(final LengthUnit lengthUnit, final DurationUnit durationUnit, final String nameOrNameKey,
101             final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem, final boolean standardUnit)
102     {
103         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, METER_PER_SECOND_2,
104                 lengthUnit.getScaleFactor() / (durationUnit.getScaleFactor() * durationUnit.getScaleFactor()), standardUnit);
105         this.lengthUnit = lengthUnit;
106         this.durationUnit = durationUnit;
107     }
108 
109     /**
110      * Define user defined acceleration unit based on length and time. You can define units like meter/second^2 here.
111      * @param lengthUnit LengthUnit; the unit of length for the acceleration unit, e.g., meter
112      * @param durationUnit DurationUnit; the unit of time for the acceleration unit, e.g., second
113      * @param name String; the long name of the unit
114      * @param abbreviation String; the abbreviation of the unit
115      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
116      */
117     public AccelerationUnit(final LengthUnit lengthUnit, final DurationUnit durationUnit, final String name,
118             final String abbreviation, final UnitSystem unitSystem)
119     {
120         this(lengthUnit, durationUnit, name, abbreviation, unitSystem, false);
121     }
122 
123     /**
124      * Define acceleration unit based on speed and time. You can define units like (mile/hour)/second here.
125      * @param speedUnit SpeedUnit; the unit of speed for the acceleration unit, e.g., knot
126      * @param durationUnit DurationUnit; the unit of time for the acceleration unit, e.g., second
127      * @param nameOrNameKey String; if standardUnit: the key to the locale file for the long name of the unit, otherwise the
128      *            name itself
129      * @param abbreviationOrAbbreviationKey String; if standardUnit: the key to the locale file for the abbreviation of the
130      *            unit, otherwise the abbreviation itself
131      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
132      * @param standardUnit boolean; indicates whether it is a standard unit with a definition in the locale, or a user-defined
133      *            unit
134      */
135     private AccelerationUnit(final SpeedUnit speedUnit, final DurationUnit durationUnit, final String nameOrNameKey,
136             final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem, final boolean standardUnit)
137     {
138         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, METER_PER_SECOND_2,
139                 speedUnit.getScaleFactor() / durationUnit.getScaleFactor(), standardUnit);
140         this.lengthUnit = speedUnit.getLengthUnit();
141         this.durationUnit = durationUnit;
142     }
143 
144     /**
145      * Define user-defined acceleration unit based on speed and time. You can define units like (mile/hour)/second here.
146      * @param speedUnit SpeedUnit; the unit of speed for the acceleration unit, e.g., knot
147      * @param durationUnit DurationUnit; the unit of time for the acceleration unit, e.g., second
148      * @param name String; the long name of the unit
149      * @param abbreviation String; the abbreviation of the unit
150      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
151      */
152     public AccelerationUnit(final SpeedUnit speedUnit, final DurationUnit durationUnit, final String name,
153             final String abbreviation, final UnitSystem unitSystem)
154     {
155         this(speedUnit, durationUnit, name, abbreviation, unitSystem, false);
156     }
157 
158     /**
159      * Build a unit with a conversion factor to another unit.
160      * @param nameOrNameKey String; if standardUnit: the key to the locale file for the long name of the unit, otherwise the
161      *            name itself
162      * @param abbreviationOrAbbreviationKey String; if standardUnit: the key to the locale file for the abbreviation of the
163      *            unit, otherwise the abbreviation itself
164      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
165      * @param referenceUnit AccelerationUnit; the unit to convert to
166      * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
167      *            unit
168      * @param standardUnit boolean; indicates whether it is a standard unit with a definition in the locale, or a user-defined
169      *            unit
170      */
171     private AccelerationUnit(final String nameOrNameKey, final String abbreviationOrAbbreviationKey,
172             final UnitSystem unitSystem, final AccelerationUnit referenceUnit, final double scaleFactorToReferenceUnit,
173             final boolean standardUnit)
174     {
175         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, referenceUnit, scaleFactorToReferenceUnit,
176                 standardUnit);
177         this.lengthUnit = referenceUnit.getLengthUnit();
178         this.durationUnit = referenceUnit.getDurationUnit();
179     }
180 
181     /**
182      * Build a user-defined unit with a conversion factor to another unit.
183      * @param name String; the long name of the unit
184      * @param abbreviation String; the abbreviation of the unit
185      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
186      * @param referenceUnit AccelerationUnit; the unit to convert to
187      * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
188      *            unit
189      */
190     public AccelerationUnit(final String name, final String abbreviation, final UnitSystem unitSystem,
191             final AccelerationUnit referenceUnit, final double scaleFactorToReferenceUnit)
192     {
193         this(name, abbreviation, unitSystem, referenceUnit, scaleFactorToReferenceUnit, false);
194     }
195 
196     /**
197      * @return lengthUnit
198      */
199     public final LengthUnit getLengthUnit()
200     {
201         return this.lengthUnit;
202     }
203 
204     /**
205      * @return durationUnit
206      */
207     public final DurationUnit getDurationUnit()
208     {
209         return this.durationUnit;
210     }
211 
212     /** {@inheritDoc} */
213     @Override
214     public final AccelerationUnit getStandardUnit()
215     {
216         return METER_PER_SECOND_2;
217     }
218 
219     /** {@inheritDoc} */
220     @Override
221     public final String getSICoefficientsString()
222     {
223         return "m/s2";
224     }
225 
226 }