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