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-2019 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: 2019-03-02 19:06:46 +0100 (Sat, 02 Mar 2019) $, @version $Revision: 342 $, 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.kg/s", SI_DERIVED);
41 KILOGRAM_PER_SECOND = SI;
42 POUND_PER_SECOND = new FlowMassUnit(MassUnit.POUND, DurationUnit.SECOND, "FlowMassUnit.lb/s", IMPERIAL);
43 }
44
45 /**
46 * Create a flow-massunit based on mass and time.
47 * @param massUnit MassUnit; the unit of mass for the flow unit, e.g., kilogram
48 * @param durationUnit DurationUnit; the unit of time for the flow unit, e.g., second
49 * @param abbreviationKey String; the key to the locale file for the abbreviation of the unit
50 * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
51 */
52 private FlowMassUnit(final MassUnit massUnit, final DurationUnit durationUnit, final String abbreviationKey,
53 final UnitSystem unitSystem)
54 {
55 super(abbreviationKey, unitSystem, KILOGRAM_PER_SECOND, massUnit.getScaleFactor() / durationUnit.getScaleFactor());
56 this.massUnit = massUnit;
57 this.durationUnit = durationUnit;
58 }
59
60 /**
61 * Create a user-defined flow-massunit based on mass and time.
62 * @param massUnit MassUnit; the unit of mass for the flow unit, e.g., kilogram
63 * @param durationUnit DurationUnit; the unit of time for the flow unit, e.g., second
64 * @param name String; the long name of the unit
65 * @param abbreviation String; the abbreviation of the unit
66 * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
67 */
68 public FlowMassUnit(final MassUnit massUnit, final DurationUnit durationUnit, final String name, final String abbreviation,
69 final UnitSystem unitSystem)
70 {
71 super(name, abbreviation, unitSystem, KILOGRAM_PER_SECOND, massUnit.getScaleFactor() / durationUnit.getScaleFactor());
72 this.massUnit = massUnit;
73 this.durationUnit = durationUnit;
74 }
75
76 /**
77 * Create a flow-massunit based on another flow-massunit.
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 * @param referenceUnit FlowMassUnit; the unit to convert to
81 * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
82 * unit
83 */
84 private FlowMassUnit(final String abbreviationKey, final UnitSystem unitSystem, final FlowMassUnit referenceUnit,
85 final double scaleFactorToReferenceUnit)
86 {
87 super(abbreviationKey, unitSystem, referenceUnit, scaleFactorToReferenceUnit);
88 this.massUnit = referenceUnit.getMassUnit();
89 this.durationUnit = referenceUnit.getDurationUnit();
90 }
91
92 /**
93 * Build a user-defined unit with a conversion factor to another unit.
94 * @param name String; the long name of the unit
95 * @param abbreviation String; the abbreviation of the unit
96 * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
97 * @param referenceUnit FlowMassUnit; the unit to convert to
98 * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
99 * unit
100 */
101 public FlowMassUnit(final String name, final String abbreviation, final UnitSystem unitSystem,
102 final FlowMassUnit referenceUnit, final double scaleFactorToReferenceUnit)
103 {
104 super(name, abbreviation, unitSystem, referenceUnit, scaleFactorToReferenceUnit);
105 this.massUnit = referenceUnit.getMassUnit();
106 this.durationUnit = referenceUnit.getDurationUnit();
107 }
108
109 /**
110 * @return massUnit
111 */
112 public final MassUnit getMassUnit()
113 {
114 return this.massUnit;
115 }
116
117 /**
118 * @return durationUnit
119 */
120 public final DurationUnit getDurationUnit()
121 {
122 return this.durationUnit;
123 }
124
125 /** {@inheritDoc} */
126 @Override
127 public final FlowMassUnit getStandardUnit()
128 {
129 return KILOGRAM_PER_SECOND;
130 }
131
132 /** {@inheritDoc} */
133 @Override
134 public final String getSICoefficientsString()
135 {
136 return "kg/s";
137 }
138
139 }