View Javadoc
1   package org.opentrafficsim.core.unit;
2   
3   import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.IMPERIAL;
4   import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.SI_DERIVED;
5   
6   import org.opentrafficsim.core.unit.unitsystem.UnitSystem;
7   
8   /**
9    * The mass flow rate is the mass of a substance which passes through a given surface per unit of time (wikipedia).
10   * <p>
11   * Copyright (c) 2014 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
12   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
13   * <p>
14   * @version May 15, 2014 <br>
15   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
16   */
17  public class FlowMassUnit extends Unit<FlowMassUnit>
18  {
19      /** */
20      private static final long serialVersionUID = 20140607L;
21  
22      /** the unit of mass for the flow unit, e.g., kilogram. */
23      private final MassUnit massUnit;
24  
25      /** the unit of time for the flow unit, e.g., second. */
26      private final TimeUnit timeUnit;
27  
28      /** The SI unit for mass flow rate is kg/s. */
29      public static final FlowMassUnit SI;
30  
31      /** kg/s. */
32      public static final FlowMassUnit KILOGRAM_PER_SECOND;
33  
34      /** lb/s. */
35      public static final FlowMassUnit POUND_PER_SECOND;
36  
37      static
38      {
39          SI =
40                  new FlowMassUnit(MassUnit.KILOGRAM, TimeUnit.SECOND, "FlowMassUnit.kilogram_per_second",
41                          "FlowMassUnit.kg/s", SI_DERIVED);
42          KILOGRAM_PER_SECOND = SI;
43          POUND_PER_SECOND =
44                  new FlowMassUnit(MassUnit.POUND, TimeUnit.SECOND, "FlowMassUnit.pound_per_second", "FlowMassUnit.lb/s",
45                          IMPERIAL);
46      }
47  
48      /**
49       * Create a flow-massunit based on mass and time.
50       * @param massUnit the unit of mass for the flow unit, e.g., kilogram
51       * @param timeUnit the unit of time for the flow unit, e.g., second
52       * @param nameKey the key to the locale file for the long name of the unit
53       * @param abbreviationKey the key to the locale file for the abbreviation of the unit
54       * @param unitSystem the unit system, e.g. SI or Imperial
55       */
56      public FlowMassUnit(final MassUnit massUnit, final TimeUnit timeUnit, final String nameKey,
57              final String abbreviationKey, final UnitSystem unitSystem)
58      {
59          super(nameKey, abbreviationKey, unitSystem, KILOGRAM_PER_SECOND, massUnit.getConversionFactorToStandardUnit()
60                  / timeUnit.getConversionFactorToStandardUnit(), true);
61          this.massUnit = massUnit;
62          this.timeUnit = timeUnit;
63      }
64  
65      /**
66       * Create a flow-massunit based on another flow-massunit.
67       * @param nameKey the key to the locale file for the long name of the unit
68       * @param abbreviationKey the key to the locale file for the abbreviation of the unit
69       * @param unitSystem the unit system, e.g. SI or Imperial
70       * @param referenceUnit the unit to convert to
71       * @param conversionFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given
72       *            reference unit
73       */
74      public FlowMassUnit(final String nameKey, final String abbreviationKey, final UnitSystem unitSystem,
75              final FlowMassUnit referenceUnit, final double conversionFactorToReferenceUnit)
76      {
77          super(nameKey, abbreviationKey, unitSystem, referenceUnit, conversionFactorToReferenceUnit, true);
78          this.massUnit = referenceUnit.getMassUnit();
79          this.timeUnit = referenceUnit.getTimeUnit();
80      }
81  
82      /**
83       * @return massUnit
84       */
85      public final MassUnit getMassUnit()
86      {
87          return this.massUnit;
88      }
89  
90      /**
91       * @return timeUnit
92       */
93      public final TimeUnit getTimeUnit()
94      {
95          return this.timeUnit;
96      }
97  
98      /** {@inheritDoc} */
99      @Override
100     public final FlowMassUnit getStandardUnit()
101     {
102         return KILOGRAM_PER_SECOND;
103     }
104 
105     /** {@inheritDoc} */
106     @Override
107     public final String getSICoefficientsString()
108     {
109         return "kg/s";
110     }
111 
112 }