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