View Javadoc
1   package org.djunits.unit;
2   
3   import static org.djunits.unit.unitsystem.UnitSystem.IMPERIAL;
4   import static org.djunits.unit.unitsystem.UnitSystem.SI_DERIVED;
5   
6   import org.djunits.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) 2015-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
12   * BSD-style license. See <a href="http://djunits.org/docs/license.html">DJUNITS License</a>.
13   * <p>
14   * $LastChangedDate: 2018-01-28 03:17:44 +0100 (Sun, 28 Jan 2018) $, @version $Revision: 256 $, by $Author: averbraeck $,
15   * initial version May 15, 2014 <br>
16   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
17   */
18  public class FlowMassUnit extends LinearUnit<FlowMassUnit>
19  {
20      /** */
21      private static final long serialVersionUID = 20140607L;
22  
23      /** the unit of mass for the flow unit, e.g., kilogram. */
24      private final MassUnit massUnit;
25  
26      /** the unit of time for the flow unit, e.g., second. */
27      private final DurationUnit durationUnit;
28  
29      /** The SI unit for mass flow rate is kg/s. */
30      public static final FlowMassUnit SI;
31  
32      /** kg/s. */
33      public static final FlowMassUnit KILOGRAM_PER_SECOND;
34  
35      /** lb/s. */
36      public static final FlowMassUnit POUND_PER_SECOND;
37  
38      static
39      {
40          SI = new FlowMassUnit(MassUnit.KILOGRAM, DurationUnit.SECOND, "FlowMassUnit.kilogram_per_second", "FlowMassUnit.kg/s",
41                  SI_DERIVED, true);
42          KILOGRAM_PER_SECOND = SI;
43          POUND_PER_SECOND = new FlowMassUnit(MassUnit.POUND, DurationUnit.SECOND, "FlowMassUnit.pound_per_second",
44                  "FlowMassUnit.lb/s", IMPERIAL, true);
45      }
46  
47      /**
48       * Create a flow-massunit based on mass and time.
49       * @param massUnit the unit of mass for the flow unit, e.g., kilogram
50       * @param durationUnit the unit of time for the flow unit, e.g., second
51       * @param nameOrNameKey if standardUnit: the key to the locale file for the long name of the unit, otherwise the name itself
52       * @param abbreviationOrAbbreviationKey if standardUnit: the key to the locale file for the abbreviation of the unit,
53       *            otherwise the abbreviation itself
54       * @param unitSystem the unit system, e.g. SI or Imperial
55       * @param standardUnit indicates whether it is a standard unit with a definition in the locale, or a user-defined unit
56       */
57      private FlowMassUnit(final MassUnit massUnit, final DurationUnit durationUnit, final String nameOrNameKey,
58              final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem, final boolean standardUnit)
59      {
60          super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, KILOGRAM_PER_SECOND,
61                  massUnit.getScaleFactor() / durationUnit.getScaleFactor(), standardUnit);
62          this.massUnit = massUnit;
63          this.durationUnit = durationUnit;
64      }
65  
66      /**
67       * Create a user-defined flow-massunit based on mass and time.
68       * @param massUnit the unit of mass for the flow unit, e.g., kilogram
69       * @param durationUnit the unit of time for the flow unit, e.g., second
70       * @param name the long name of the unit
71       * @param abbreviation the abbreviation of the unit
72       * @param unitSystem the unit system, e.g. SI or Imperial
73       */
74      public FlowMassUnit(final MassUnit massUnit, final DurationUnit durationUnit, final String name, final String abbreviation,
75              final UnitSystem unitSystem)
76      {
77          this(massUnit, durationUnit, name, abbreviation, unitSystem, false);
78      }
79  
80      /**
81       * Create a flow-massunit based on another flow-massunit.
82       * @param nameOrNameKey if standardUnit: the key to the locale file for the long name of the unit, otherwise the name itself
83       * @param abbreviationOrAbbreviationKey if standardUnit: the key to the locale file for the abbreviation of the unit,
84       *            otherwise the abbreviation itself
85       * @param unitSystem the unit system, e.g. SI or Imperial
86       * @param referenceUnit the unit to convert to
87       * @param scaleFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given reference unit
88       * @param standardUnit indicates whether it is a standard unit with a definition in the locale, or a user-defined unit
89       */
90      private FlowMassUnit(final String nameOrNameKey, final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem,
91              final FlowMassUnit referenceUnit, final double scaleFactorToReferenceUnit, final boolean standardUnit)
92      {
93          super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, referenceUnit, scaleFactorToReferenceUnit,
94                  standardUnit);
95          this.massUnit = referenceUnit.getMassUnit();
96          this.durationUnit = referenceUnit.getDurationUnit();
97      }
98  
99      /**
100      * Build a user-defined unit with a conversion factor to another unit.
101      * @param name the long name of the unit
102      * @param abbreviation the abbreviation of the unit
103      * @param unitSystem the unit system, e.g. SI or Imperial
104      * @param referenceUnit the unit to convert to
105      * @param scaleFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given reference unit
106      */
107     public FlowMassUnit(final String name, final String abbreviation, final UnitSystem unitSystem,
108             final FlowMassUnit referenceUnit, final double scaleFactorToReferenceUnit)
109     {
110         this(name, abbreviation, unitSystem, referenceUnit, scaleFactorToReferenceUnit, false);
111     }
112 
113     /**
114      * @return massUnit
115      */
116     public final MassUnit getMassUnit()
117     {
118         return this.massUnit;
119     }
120 
121     /**
122      * @return durationUnit
123      */
124     public final DurationUnit getDurationUnit()
125     {
126         return this.durationUnit;
127     }
128 
129     /** {@inheritDoc} */
130     @Override
131     public final FlowMassUnit getStandardUnit()
132     {
133         return KILOGRAM_PER_SECOND;
134     }
135 
136     /** {@inheritDoc} */
137     @Override
138     public final String getSICoefficientsString()
139     {
140         return "kg/s";
141     }
142 
143 }