View Javadoc
1   package org.opentrafficsim.core.unit;
2   
3   import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.OTHER;
4   import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.SI_ACCEPTED;
5   import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.SI_BASE;
6   
7   import org.opentrafficsim.core.unit.unitsystem.UnitSystem;
8   
9   /**
10   * Standard time units.
11   * <p>
12   * Copyright (c) 2014 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
13   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
14   * <p>
15   * @version May 15, 2014 <br>
16   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
17   */
18  public class TimeUnit extends Unit<TimeUnit>
19  {
20      /** */
21      private static final long serialVersionUID = 20140607L;
22  
23      /** The SI unit for time is second. */
24      public static final TimeUnit SI;
25  
26      /** second. */
27      public static final TimeUnit SECOND;
28  
29      /** millisecond. */
30      public static final TimeUnit MILLISECOND;
31  
32      /** minute. */
33      public static final TimeUnit MINUTE;
34  
35      /** hour. */
36      public static final TimeUnit HOUR;
37  
38      /** day. */
39      public static final TimeUnit DAY;
40  
41      /** week. */
42      public static final TimeUnit WEEK;
43  
44      static
45      {
46          SI = new TimeUnit("TimeUnit.second", "TimeUnit.s", SI_BASE);
47          SECOND = SI;
48          MILLISECOND = new TimeUnit("TimeUnit.millisecond", "TimeUnit.ms", SI_BASE, SECOND, 0.001);
49          MINUTE = new TimeUnit("TimeUnit.minute", "TimeUnit.m", SI_ACCEPTED, SECOND, 60.0);
50          HOUR = new TimeUnit("TimeUnit.hour", "TimeUnit.h", SI_ACCEPTED, MINUTE, 60.0);
51          DAY = new TimeUnit("TimeUnit.day", "TimeUnit.d", SI_ACCEPTED, HOUR, 24.0);
52          WEEK = new TimeUnit("TimeUnit.week", "TimeUnit.w", OTHER, DAY, 7.0);
53      }
54  
55      /**
56       * Build a standard unit.
57       * @param nameKey the key to the locale file for the long name of the unit
58       * @param abbreviationKey the key to the locale file for the abbreviation of the unit
59       * @param unitSystem the unit system, e.g. SI or Imperial
60       */
61      public TimeUnit(final String nameKey, final String abbreviationKey, final UnitSystem unitSystem)
62      {
63          super(nameKey, abbreviationKey, unitSystem, true);
64      }
65  
66      /**
67       * Build a unit with a conversion factor to another unit.
68       * @param nameKey the key to the locale file for the long name of the unit
69       * @param abbreviationKey the key to the locale file for the abbreviation of the unit
70       * @param unitSystem the unit system, e.g. SI or Imperial
71       * @param referenceUnit the unit to convert to
72       * @param conversionFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given
73       *            reference unit
74       */
75      public TimeUnit(final String nameKey, final String abbreviationKey, final UnitSystem unitSystem,
76              final TimeUnit referenceUnit, final double conversionFactorToReferenceUnit)
77      {
78          super(nameKey, abbreviationKey, unitSystem, referenceUnit, conversionFactorToReferenceUnit, true);
79      }
80  
81      /** {@inheritDoc} */
82      @Override
83      public final TimeUnit getStandardUnit()
84      {
85          return SECOND;
86      }
87  
88      /** {@inheritDoc} */
89      @Override
90      public final String getSICoefficientsString()
91      {
92          return "s";
93      }
94  
95  }