View Javadoc
1   package org.opentrafficsim.core.unit;
2   
3   import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.CGS_EMU;
4   import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.CGS_ESU;
5   import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.OTHER;
6   import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.SI_ACCEPTED;
7   import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.SI_DERIVED;
8   
9   import org.opentrafficsim.core.unit.unitsystem.UnitSystem;
10  
11  /**
12   * Units for electrical charge.
13   * <p>
14   * Copyright (c) 2014 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
16   * <p>
17   * @version May 15, 2014 <br>
18   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
19   */
20  public class ElectricalChargeUnit extends Unit<ElectricalChargeUnit>
21  {
22      /** */
23      private static final long serialVersionUID = 20140607L;
24  
25      /** the unit of electrical current, e.g., Ampere. */
26      private final ElectricalCurrentUnit electricalCurrentUnit;
27  
28      /** the unit of time, e.g., second. */
29      private final TimeUnit timeUnit;
30  
31      /** The SI unit for electrical charge is Coulomb = A.s. */
32      public static final ElectricalChargeUnit SI;
33  
34      /** Coulomb = A.s. */
35      public static final ElectricalChargeUnit COULOMB;
36  
37      /** milliampere hour. */
38      public static final ElectricalChargeUnit MILLIAMPERE_HOUR;
39  
40      /** Faraday. */
41      public static final ElectricalChargeUnit FARADAY;
42  
43      /** atomic unit of charge. */
44      public static final ElectricalChargeUnit ATOMIC_UNIT;
45  
46      /** statcoulomb (CGS ESU). */
47      public static final ElectricalChargeUnit STATCOULOMB;
48  
49      /** franklin (CGS ESU). */
50      public static final ElectricalChargeUnit FRANKLIN;
51  
52      /** esu (CGS ESU). */
53      public static final ElectricalChargeUnit ESU;
54  
55      /** abcoulomb (CGS EMU). */
56      public static final ElectricalChargeUnit ABCOULOMB;
57  
58      /** emu (CGS EMU). */
59      public static final ElectricalChargeUnit EMU;
60  
61      static
62      {
63          SI =
64                  new ElectricalChargeUnit(ElectricalCurrentUnit.AMPERE, TimeUnit.SECOND, "ElectricalChargeUnit.coulomb",
65                          "ElectricalChargeUnit.C", SI_DERIVED);
66          COULOMB = SI;
67          MILLIAMPERE_HOUR =
68                  new ElectricalChargeUnit(ElectricalCurrentUnit.MILLIAMPERE, TimeUnit.HOUR,
69                          "ElectricalChargeUnit.milliampere_hour", "ElectricalChargeUnit.mAh", SI_DERIVED);
70          FARADAY =
71                  new ElectricalChargeUnit("ElectricalChargeUnit.faraday", "ElectricalChargeUnit.F", OTHER, COULOMB,
72                          96485.3383);
73          ATOMIC_UNIT =
74                  new ElectricalChargeUnit("ElectricalChargeUnit.atomic_unit_of_charge", "ElectricalChargeUnit.e",
75                          SI_ACCEPTED, COULOMB, 1.6021765314E-19);
76          STATCOULOMB =
77                  new ElectricalChargeUnit("ElectricalChargeUnit.statcoulomb", "ElectricalChargeUnit.statC", CGS_ESU,
78                          COULOMB, 3.335641E-10);
79          FRANKLIN =
80                  new ElectricalChargeUnit("ElectricalChargeUnit.franklin", "ElectricalChargeUnit.Fr", CGS_ESU,
81                          STATCOULOMB, 1.0);
82          ESU =
83                  new ElectricalChargeUnit("ElectricalChargeUnit.electrostatic_unit", "ElectricalChargeUnit.esu",
84                          CGS_ESU, STATCOULOMB, 1.0);
85          ABCOULOMB =
86                  new ElectricalChargeUnit("ElectricalChargeUnit.abcoulomb", "ElectricalChargeUnit.abC", CGS_EMU,
87                          COULOMB, 10.0);
88          EMU =
89                  new ElectricalChargeUnit("ElectricalChargeUnit.electromagnetic_unit", "ElectricalChargeUnit.emu",
90                          CGS_EMU, ABCOULOMB, 1.0);
91      }
92  
93      /**
94       * @param electricalCurrentUnit the unit of electrical current for the electrical charge unit, e.g., meter
95       * @param timeUnit the unit of time for the electrical charge unit, e.g., second
96       * @param nameKey the key to the locale file for the long name of the unit
97       * @param abbreviationKey the key to the locale file for the abbreviation of the unit
98       * @param unitSystem the unit system, e.g. SI or Imperial
99       */
100     public ElectricalChargeUnit(final ElectricalCurrentUnit electricalCurrentUnit, final TimeUnit timeUnit,
101             final String nameKey, final String abbreviationKey, final UnitSystem unitSystem)
102     {
103         super(nameKey, abbreviationKey, unitSystem, COULOMB, electricalCurrentUnit.getConversionFactorToStandardUnit()
104                 * timeUnit.getConversionFactorToStandardUnit(), true);
105         this.electricalCurrentUnit = electricalCurrentUnit;
106         this.timeUnit = timeUnit;
107     }
108 
109     /**
110      * @param nameKey the key to the locale file for the long name of the unit
111      * @param abbreviationKey the key to the locale file for the abbreviation of the unit
112      * @param unitSystem the unit system, e.g. SI or Imperial
113      * @param referenceUnit the unit to convert to
114      * @param conversionFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given
115      *            reference unit
116      */
117     public ElectricalChargeUnit(final String nameKey, final String abbreviationKey, final UnitSystem unitSystem,
118             final ElectricalChargeUnit referenceUnit, final double conversionFactorToReferenceUnit)
119     {
120         super(nameKey, abbreviationKey, unitSystem, referenceUnit, conversionFactorToReferenceUnit, true);
121         this.electricalCurrentUnit = referenceUnit.getElectricalCurrentUnit();
122         this.timeUnit = referenceUnit.getTimeUnit();
123     }
124 
125     /**
126      * @return electricalCurrentUnit
127      */
128     public final ElectricalCurrentUnit getElectricalCurrentUnit()
129     {
130         return this.electricalCurrentUnit;
131     }
132 
133     /**
134      * @return timeUnit
135      */
136     public final TimeUnit getTimeUnit()
137     {
138         return this.timeUnit;
139     }
140 
141     /** {@inheritDoc} */
142     @Override
143     public final ElectricalChargeUnit getStandardUnit()
144     {
145         return COULOMB;
146     }
147 
148     /** {@inheritDoc} */
149     @Override
150     public final String getSICoefficientsString()
151     {
152         return "sA";
153     }
154 
155 }