View Javadoc
1   package org.djunits.unit;
2   
3   import static org.djunits.unit.unitsystem.UnitSystem.OTHER;
4   import static org.djunits.unit.unitsystem.UnitSystem.SI_ACCEPTED;
5   import static org.djunits.unit.unitsystem.UnitSystem.SI_BASE;
6   
7   import org.djunits.unit.unitsystem.UnitSystem;
8   
9   /**
10   * Standard duration units.
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: 2017-04-15 02:11:44 +0200 (Sat, 15 Apr 2017) $, @version $Revision: 239 $, 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 DurationUnit extends LinearUnit<DurationUnit>
20  {
21      /** */
22      private static final long serialVersionUID = 20140607L;
23  
24      /** The SI unit for duration is second. */
25      public static final DurationUnit SI;
26  
27      /** second. */
28      public static final DurationUnit SECOND;
29  
30      /** attosecond. */
31      public static final DurationUnit ATTOSECOND;
32  
33      /** femtosecond. */
34      public static final DurationUnit FEMTOSECOND;
35  
36      /** picosecond. */
37      public static final DurationUnit PICOSECOND;
38  
39      /** nanosecond. */
40      public static final DurationUnit NANOSECOND;
41  
42      /** microsecond. */
43      public static final DurationUnit MICROSECOND;
44  
45      /** millisecond. */
46      public static final DurationUnit MILLISECOND;
47  
48      /** minute. */
49      public static final DurationUnit MINUTE;
50  
51      /** hour. */
52      public static final DurationUnit HOUR;
53  
54      /** day. */
55      public static final DurationUnit DAY;
56  
57      /** week. */
58      public static final DurationUnit WEEK;
59  
60      static
61      {
62          SI = new DurationUnit("DurationUnit.s", SI_BASE);
63          SECOND = SI;
64          ATTOSECOND = new DurationUnit("DurationUnit.as", SI_BASE, SECOND, 1E-18);
65          FEMTOSECOND = new DurationUnit("DurationUnit.fs", SI_BASE, SECOND, 1E-15);
66          PICOSECOND = new DurationUnit("DurationUnit.ps", SI_BASE, SECOND, 1E-12);
67          NANOSECOND = new DurationUnit("DurationUnit.ns", SI_BASE, SECOND, 1E-9);
68          MICROSECOND = new DurationUnit("DurationUnit.mus", SI_BASE, SECOND, 1E-6);
69          MILLISECOND = new DurationUnit("DurationUnit.ms", SI_BASE, SECOND, 1E-3);
70          MINUTE = new DurationUnit("DurationUnit.m", SI_ACCEPTED, SECOND, 60.0);
71          HOUR = new DurationUnit("DurationUnit.h", SI_ACCEPTED, MINUTE, 60.0);
72          DAY = new DurationUnit("DurationUnit.d", SI_ACCEPTED, HOUR, 24.0);
73          WEEK = new DurationUnit("DurationUnit.w", OTHER, DAY, 7.0);
74      }
75  
76      /**
77       * Build a standard DurationUnit.
78       * @param abbreviationKey String; the key to the locale file for the abbreviation of the unit
79       * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
80       */
81      private DurationUnit(final String abbreviationKey, final UnitSystem unitSystem)
82      {
83          super(abbreviationKey, unitSystem);
84      }
85  
86      /**
87       * Build a DurationUnit with a conversion factor to another DurationUnit.
88       * @param abbreviationKey String; the key to the locale file for the abbreviation of the unit
89       * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
90       * @param referenceUnit DurationUnit; the unit to convert to
91       * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
92       *            unit
93       */
94      private DurationUnit(final String abbreviationKey, final UnitSystem unitSystem, final DurationUnit referenceUnit,
95              final double scaleFactorToReferenceUnit)
96      {
97          super(abbreviationKey, unitSystem, referenceUnit, scaleFactorToReferenceUnit);
98      }
99  
100     /**
101      * Build a user-defined DurationUnit with a conversion factor to another DurationUnit.
102      * @param name String; the long name of the unit
103      * @param abbreviation String; the abbreviation of the unit
104      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
105      * @param referenceUnit DurationUnit; the unit to convert to
106      * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
107      *            unit
108      */
109     public DurationUnit(final String name, final String abbreviation, final UnitSystem unitSystem,
110             final DurationUnit referenceUnit, final double scaleFactorToReferenceUnit)
111     {
112         super(name, abbreviation, unitSystem, referenceUnit, scaleFactorToReferenceUnit);
113     }
114 
115     /** {@inheritDoc} */
116     @Override
117     public final DurationUnit getStandardUnit()
118     {
119         return SECOND;
120     }
121 
122     /** {@inheritDoc} */
123     @Override
124     public final String getSICoefficientsString()
125     {
126         return "s";
127     }
128 
129 }