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-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: 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.second", "DurationUnit.s", SI_BASE);
63          SECOND = SI;
64          ATTOSECOND = new DurationUnit("DurationUnit.attosecond", "DurationUnit.as", SI_BASE, SECOND, 1E-18, true);
65          FEMTOSECOND = new DurationUnit("DurationUnit.femtosecond", "DurationUnit.fs", SI_BASE, SECOND, 1E-15, true);
66          PICOSECOND = new DurationUnit("DurationUnit.picosecond", "DurationUnit.ps", SI_BASE, SECOND, 1E-12, true);
67          NANOSECOND = new DurationUnit("DurationUnit.nanosecond", "DurationUnit.ns", SI_BASE, SECOND, 1E-9, true);
68          MICROSECOND = new DurationUnit("DurationUnit.microsecond", "DurationUnit.mus", SI_BASE, SECOND, 1E-6, true);
69          MILLISECOND = new DurationUnit("DurationUnit.millisecond", "DurationUnit.ms", SI_BASE, SECOND, 1E-3, true);
70          MINUTE = new DurationUnit("DurationUnit.minute", "DurationUnit.m", SI_ACCEPTED, SECOND, 60.0, true);
71          HOUR = new DurationUnit("DurationUnit.hour", "DurationUnit.h", SI_ACCEPTED, MINUTE, 60.0, true);
72          DAY = new DurationUnit("DurationUnit.day", "DurationUnit.d", SI_ACCEPTED, HOUR, 24.0, true);
73          WEEK = new DurationUnit("DurationUnit.week", "DurationUnit.w", OTHER, DAY, 7.0, true);
74      }
75  
76      /**
77       * Build a standard DurationUnit.
78       * @param nameKey the key to the locale file for the long name of the unit
79       * @param abbreviationKey the key to the locale file for the abbreviation of the unit
80       * @param unitSystem the unit system, e.g. SI or Imperial
81       */
82      private DurationUnit(final String nameKey, final String abbreviationKey, final UnitSystem unitSystem)
83      {
84          super(nameKey, abbreviationKey, unitSystem, true);
85      }
86  
87      /**
88       * Build a DurationUnit with a conversion factor to another DurationUnit.
89       * @param nameOrNameKey if standardUnit: the key to the locale file for the long name of the unit, otherwise the name itself
90       * @param abbreviationOrAbbreviationKey if standardUnit: the key to the locale file for the abbreviation of the unit,
91       *            otherwise the abbreviation itself
92       * @param unitSystem the unit system, e.g. SI or Imperial
93       * @param referenceUnit the unit to convert to
94       * @param scaleFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given reference unit
95       * @param standardUnit indicates whether it is a standard unit with a definition in the locale, or a user-defined unit
96       */
97      private DurationUnit(final String nameOrNameKey, final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem,
98              final DurationUnit referenceUnit, final double scaleFactorToReferenceUnit, final boolean standardUnit)
99      {
100         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, referenceUnit, scaleFactorToReferenceUnit,
101                 standardUnit);
102     }
103 
104     /**
105      * Build a user-defined DurationUnit with a conversion factor to another DurationUnit.
106      * @param name the long name of the unit
107      * @param abbreviation the abbreviation of the unit
108      * @param unitSystem the unit system, e.g. SI or Imperial
109      * @param referenceUnit the unit to convert to
110      * @param scaleFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given reference unit
111      */
112     public DurationUnit(final String name, final String abbreviation, final UnitSystem unitSystem,
113             final DurationUnit referenceUnit, final double scaleFactorToReferenceUnit)
114     {
115         this(name, abbreviation, unitSystem, referenceUnit, scaleFactorToReferenceUnit, false);
116     }
117 
118     /** {@inheritDoc} */
119     @Override
120     public final DurationUnit getStandardUnit()
121     {
122         return SECOND;
123     }
124 
125     /** {@inheritDoc} */
126     @Override
127     public final String getSICoefficientsString()
128     {
129         return "s";
130     }
131 
132 }